@payloadcms/db-postgres 3.0.0-beta.9 → 3.0.0-canary.f6e77b8
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/count.d.ts +3 -0
- package/dist/count.d.ts.map +1 -0
- package/dist/count.js +50 -0
- package/dist/count.js.map +1 -0
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +3 -5
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +3 -5
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +2 -6
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +9 -13
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +2 -5
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +2 -5
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +2 -6
- package/dist/deleteVersions.js.map +1 -1
- package/dist/destroy.d.ts.map +1 -1
- package/dist/destroy.js +7 -7
- package/dist/destroy.js.map +1 -1
- package/dist/find/buildFindManyArgs.js +2 -2
- package/dist/find/buildFindManyArgs.js.map +1 -1
- package/dist/find/findMany.d.ts.map +1 -1
- package/dist/find/findMany.js.map +1 -1
- package/dist/find/traverseFields.d.ts.map +1 -1
- package/dist/find/traverseFields.js +4 -20
- package/dist/find/traverseFields.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +2 -5
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +2 -5
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +2 -6
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +2 -5
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +2 -6
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +9 -7
- package/dist/init.js.map +1 -1
- package/dist/migrate.js.map +1 -1
- package/dist/migrateDown.js.map +1 -1
- package/dist/migrateFresh.js.map +1 -1
- package/dist/migrateRefresh.js.map +1 -1
- package/dist/migrateReset.js.map +1 -1
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.js +95 -62
- package/dist/queries/getTableColumnFromPath.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +2 -6
- package/dist/queryDrafts.js.map +1 -1
- package/dist/schema/build.d.ts +3 -2
- package/dist/schema/build.d.ts.map +1 -1
- package/dist/schema/build.js +77 -42
- package/dist/schema/build.js.map +1 -1
- package/dist/schema/{getTableName.d.ts → createTableName.d.ts} +5 -7
- package/dist/schema/createTableName.d.ts.map +1 -0
- package/dist/schema/createTableName.js +31 -0
- package/dist/schema/createTableName.js.map +1 -0
- package/dist/schema/traverseFields.d.ts.map +1 -1
- package/dist/schema/traverseFields.js +45 -24
- package/dist/schema/traverseFields.js.map +1 -1
- package/dist/schema/validateExistingBlockIsIdentical.d.ts +2 -1
- package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +1 -1
- package/dist/schema/validateExistingBlockIsIdentical.js +13 -7
- package/dist/schema/validateExistingBlockIsIdentical.js.map +1 -1
- package/dist/transform/write/array.d.ts.map +1 -1
- package/dist/transform/write/array.js.map +1 -1
- package/dist/transform/write/blocks.js +1 -1
- package/dist/transform/write/blocks.js.map +1 -1
- package/dist/transform/write/traverseFields.js +2 -2
- package/dist/transform/write/traverseFields.js.map +1 -1
- package/dist/types.d.ts +4 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/update.d.ts.map +1 -1
- package/dist/update.js +2 -5
- package/dist/update.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +2 -5
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +2 -6
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +2 -6
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsertRow/index.d.ts.map +1 -1
- package/dist/upsertRow/index.js +6 -5
- package/dist/upsertRow/index.js.map +1 -1
- package/dist/upsertRow/insertArrays.d.ts.map +1 -1
- package/dist/upsertRow/insertArrays.js +3 -3
- package/dist/upsertRow/insertArrays.js.map +1 -1
- package/dist/upsertRow/types.d.ts +2 -2
- package/dist/upsertRow/types.d.ts.map +1 -1
- package/dist/upsertRow/types.js.map +1 -1
- package/package.json +21 -25
- package/dist/schema/getTableName.d.ts.map +0 -1
- package/dist/schema/getTableName.js +0 -31
- package/dist/schema/getTableName.js.map +0 -1
- package/src/index.ts +0 -156
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/schema/traverseFields.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Relation } from 'drizzle-orm'\nimport type { IndexBuilder, PgColumnBuilder, UniqueConstraintBuilder } from 'drizzle-orm/pg-core'\nimport type { Field, TabAsField } from 'payload/types'\n\nimport { relations } from 'drizzle-orm'\nimport {\n PgNumericBuilder,\n PgUUIDBuilder,\n PgVarcharBuilder,\n boolean,\n index,\n integer,\n jsonb,\n numeric,\n pgEnum,\n text,\n timestamp,\n varchar,\n} from 'drizzle-orm/pg-core'\nimport { InvalidConfiguration } from 'payload/errors'\nimport { fieldAffectsData, optionIsObject } from 'payload/types'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { GenericColumns, IDType, PostgresAdapter } from '../types.js'\n\nimport { hasLocalesTable } from '../utilities/hasLocalesTable.js'\nimport { buildTable } from './build.js'\nimport { createIndex } from './createIndex.js'\nimport { getTableName } from './getTableName.js'\nimport { idToUUID } from './idToUUID.js'\nimport { parentIDColumnMap } from './parentIDColumnMap.js'\nimport { validateExistingBlockIsIdentical } from './validateExistingBlockIsIdentical.js'\n\ntype Args = {\n adapter: PostgresAdapter\n buildNumbers: boolean\n buildRelationships: boolean\n buildTexts: boolean\n columnPrefix?: string\n columns: Record<string, PgColumnBuilder>\n disableNotNull: boolean\n disableUnique?: boolean\n fieldPrefix?: string\n fields: (Field | TabAsField)[]\n forceLocalized?: boolean\n indexes: Record<string, (cols: GenericColumns) => IndexBuilder>\n localesColumns: Record<string, PgColumnBuilder>\n localesIndexes: Record<string, (cols: GenericColumns) => IndexBuilder>\n newTableName: string\n parentTableName: string\n relationsToBuild: Map<string, string>\n relationships: Set<string>\n rootRelationsToBuild?: Map<string, string>\n rootTableIDColType: string\n rootTableName: string\n versions: 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 buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix,\n columns,\n disableNotNull,\n disableUnique = false,\n fieldPrefix,\n fields,\n forceLocalized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\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 if (columns.id instanceof PgUUIDBuilder) parentIDColType = 'uuid'\n if (columns.id instanceof PgNumericBuilder) parentIDColType = 'numeric'\n if (columns.id instanceof PgVarcharBuilder) parentIDColType = 'varchar'\n\n fields.forEach((field) => {\n if ('name' in field && field.name === 'id') return\n let columnName: string\n let fieldName: string\n\n let targetTable = columns\n let targetIndexes = indexes\n\n if (fieldAffectsData(field)) {\n columnName = `${columnPrefix || ''}${field.name[0] === '_' ? '_' : ''}${toSnakeCase(\n field.name,\n )}`\n 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 (adapter.payload.config.localization && (field.localized || forceLocalized)) {\n hasLocalizedField = true\n targetTable = localesColumns\n targetIndexes = localesIndexes\n }\n\n if (\n (field.unique || field.index) &&\n !['array', 'blocks', 'group', 'point', 'relationship', 'upload'].includes(field.type) &&\n !('hasMany' in field && field.hasMany === true)\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 targetIndexes[`${newTableName}_${field.name}Idx`] = createIndex({\n name: fieldName,\n columnName,\n tableName: newTableName,\n unique,\n })\n }\n }\n\n switch (field.type) {\n case 'text': {\n if (field.hasMany) {\n if (field.localized) {\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] = varchar(columnName)\n }\n break\n }\n case 'email':\n case 'code':\n case 'textarea': {\n targetTable[fieldName] = varchar(columnName)\n break\n }\n\n case 'number': {\n if (field.hasMany) {\n if (field.localized) {\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] = numeric(columnName)\n }\n break\n }\n\n case 'richText':\n case 'json': {\n targetTable[fieldName] = jsonb(columnName)\n break\n }\n\n case 'date': {\n targetTable[fieldName] = timestamp(columnName, {\n mode: 'string',\n precision: 3,\n withTimezone: true,\n })\n break\n }\n\n case 'point': {\n break\n }\n\n case 'radio':\n case 'select': {\n const enumName = getTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `enum_${newTableName}_`,\n target: 'enumName',\n throwValidationError,\n versions,\n })\n\n adapter.enums[enumName] = pgEnum(\n enumName,\n field.options.map((option) => {\n if (optionIsObject(option)) {\n return option.value\n }\n\n return option\n }) as [string, ...string[]],\n )\n\n if (field.type === 'select' && field.hasMany) {\n const selectTableName = getTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `${newTableName}_`,\n throwValidationError,\n versions,\n })\n const baseColumns: Record<string, PgColumnBuilder> = {\n order: integer('order').notNull(),\n parent: parentIDColumnMap[parentIDColType]('parent_id')\n .references(() => adapter.tables[parentTableName].id, { onDelete: 'cascade' })\n .notNull(),\n value: adapter.enums[enumName]('value'),\n }\n\n const baseExtraConfig: Record<\n string,\n (cols: GenericColumns) => IndexBuilder | UniqueConstraintBuilder\n > = {\n orderIdx: (cols) => index(`${selectTableName}_order_idx`).on(cols.order),\n parentIdx: (cols) => index(`${selectTableName}_parent_idx`).on(cols.parent),\n }\n\n if (field.localized) {\n baseColumns.locale = adapter.enums.enum__locales('locale').notNull()\n baseExtraConfig.localeIdx = (cols) =>\n index(`${selectTableName}_locale_idx`).on(cols.locale)\n }\n\n if (field.index) {\n baseExtraConfig.value = (cols) => index(`${selectTableName}_value_idx`).on(cols.value)\n }\n\n buildTable({\n adapter,\n baseColumns,\n baseExtraConfig,\n disableNotNull,\n disableUnique,\n fields: [],\n tableName: selectTableName,\n versions,\n })\n\n relationsToBuild.set(fieldName, selectTableName)\n\n const selectTableRelations = relations(adapter.tables[selectTableName], ({ one }) => {\n const result: Record<string, Relation<string>> = {\n parent: one(adapter.tables[parentTableName], {\n fields: [adapter.tables[selectTableName].parent],\n references: [adapter.tables[parentTableName].id],\n }),\n }\n\n return result\n })\n\n adapter.relations[`relation_${selectTableName}`] = selectTableRelations\n } else {\n targetTable[fieldName] = adapter.enums[enumName](fieldName)\n }\n break\n }\n\n case 'checkbox': {\n targetTable[fieldName] = boolean(columnName)\n break\n }\n\n case 'array': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n const arrayTableName = getTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `${newTableName}_`,\n throwValidationError,\n })\n const baseColumns: Record<string, PgColumnBuilder> = {\n _order: integer('_order').notNull(),\n _parentID: parentIDColumnMap[parentIDColType]('_parent_id')\n .references(() => adapter.tables[parentTableName].id, { onDelete: 'cascade' })\n .notNull(),\n }\n\n const baseExtraConfig: Record<\n string,\n (cols: GenericColumns) => IndexBuilder | UniqueConstraintBuilder\n > = {\n _orderIdx: (cols) => index(`${arrayTableName}_order_idx`).on(cols._order),\n _parentIDIdx: (cols) => index(`${arrayTableName}_parent_id_idx`).on(cols._parentID),\n }\n\n if (field.localized && adapter.payload.config.localization) {\n baseColumns._locale = adapter.enums.enum__locales('_locale').notNull()\n baseExtraConfig._localeIdx = (cols) =>\n index(`${arrayTableName}_locale_idx`).on(cols._locale)\n }\n\n const {\n hasManyNumberField: subHasManyNumberField,\n hasManyTextField: subHasManyTextField,\n relationsToBuild: subRelationsToBuild,\n } = buildTable({\n adapter,\n baseColumns,\n baseExtraConfig,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fields: disableUnique ? idToUUID(field.fields) : field.fields,\n rootRelationsToBuild,\n rootRelationships: relationships,\n rootTableIDColType,\n rootTableName,\n tableName: arrayTableName,\n versions,\n })\n\n if (subHasManyTextField) {\n if (!hasManyTextField || subHasManyTextField === 'index')\n hasManyTextField = subHasManyTextField\n }\n if (subHasManyNumberField) {\n if (!hasManyNumberField || subHasManyNumberField === 'index')\n hasManyNumberField = subHasManyNumberField\n }\n\n relationsToBuild.set(fieldName, arrayTableName)\n\n const arrayTableRelations = relations(adapter.tables[arrayTableName], ({ many, one }) => {\n const result: Record<string, Relation<string>> = {\n _parentID: one(adapter.tables[parentTableName], {\n fields: [adapter.tables[arrayTableName]._parentID],\n references: [adapter.tables[parentTableName].id],\n }),\n }\n\n if (hasLocalesTable(field.fields)) {\n result._locales = many(adapter.tables[`${arrayTableName}${adapter.localesSuffix}`])\n }\n\n subRelationsToBuild.forEach((val, key) => {\n result[key] = many(adapter.tables[val])\n })\n\n return result\n })\n\n adapter.relations[`relations_${arrayTableName}`] = arrayTableRelations\n\n break\n }\n\n case 'blocks': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n field.blocks.forEach((block) => {\n const blockTableName = getTableName({\n adapter,\n config: block,\n parentTableName: rootTableName,\n prefix: `${rootTableName}_blocks_`,\n throwValidationError,\n })\n if (!adapter.tables[blockTableName]) {\n const baseColumns: Record<string, PgColumnBuilder> = {\n _order: integer('_order').notNull(),\n _parentID: parentIDColumnMap[rootTableIDColType]('_parent_id')\n .references(() => adapter.tables[rootTableName].id, { onDelete: 'cascade' })\n .notNull(),\n _path: text('_path').notNull(),\n }\n\n const baseExtraConfig: Record<\n string,\n (cols: GenericColumns) => IndexBuilder | UniqueConstraintBuilder\n > = {\n _orderIdx: (cols) => index(`${blockTableName}_order_idx`).on(cols._order),\n _parentIDIdx: (cols) => index(`${blockTableName}_parent_id_idx`).on(cols._parentID),\n _pathIdx: (cols) => index(`${blockTableName}_path_idx`).on(cols._path),\n }\n\n if (field.localized && adapter.payload.config.localization) {\n baseColumns._locale = adapter.enums.enum__locales('_locale').notNull()\n baseExtraConfig._localeIdx = (cols) =>\n index(`${blockTableName}_locale_idx`).on(cols._locale)\n }\n\n const {\n hasManyNumberField: subHasManyNumberField,\n hasManyTextField: subHasManyTextField,\n relationsToBuild: subRelationsToBuild,\n } = buildTable({\n adapter,\n baseColumns,\n baseExtraConfig,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fields: disableUnique ? idToUUID(block.fields) : block.fields,\n rootRelationsToBuild,\n rootRelationships: relationships,\n rootTableIDColType,\n rootTableName,\n tableName: blockTableName,\n versions,\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 const blockTableRelations = relations(\n adapter.tables[blockTableName],\n ({ many, one }) => {\n const result: Record<string, Relation<string>> = {\n _parentID: one(adapter.tables[rootTableName], {\n fields: [adapter.tables[blockTableName]._parentID],\n references: [adapter.tables[rootTableName].id],\n }),\n }\n\n if (hasLocalesTable(block.fields)) {\n result._locales = many(\n adapter.tables[`${blockTableName}${adapter.localesSuffix}`],\n )\n }\n\n subRelationsToBuild.forEach((val, key) => {\n result[key] = many(adapter.tables[val])\n })\n\n return result\n },\n )\n\n adapter.relations[`relations_${blockTableName}`] = blockTableRelations\n } else if (process.env.NODE_ENV !== 'production' && !versions) {\n validateExistingBlockIsIdentical({\n block,\n localized: field.localized,\n rootTableName,\n table: adapter.tables[blockTableName],\n })\n }\n adapter.blockTableNames[`${rootTableName}.${toSnakeCase(block.slug)}`] = blockTableName\n rootRelationsToBuild.set(`_blocks_${block.slug}`, blockTableName)\n })\n\n break\n }\n\n case 'tab':\n case 'group': {\n if (!('name' in field)) {\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 buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix,\n columns,\n disableNotNull,\n disableUnique,\n fieldPrefix,\n fields: field.fields,\n forceLocalized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\n })\n\n if (groupHasLocalizedField) hasLocalizedField = true\n if (groupHasLocalizedRelationshipField) hasLocalizedRelationshipField = true\n if (groupHasManyTextField) hasManyTextField = true\n if (groupHasLocalizedManyTextField) hasLocalizedManyTextField = true\n if (groupHasManyNumberField) hasManyNumberField = true\n if (groupHasLocalizedManyNumberField) hasLocalizedManyNumberField = true\n break\n }\n\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 buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix: `${columnName}_`,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix: `${fieldName}.`,\n fields: field.fields,\n forceLocalized: field.localized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName: `${parentTableName}_${columnName}`,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\n })\n\n if (groupHasLocalizedField) hasLocalizedField = true\n if (groupHasLocalizedRelationshipField) hasLocalizedRelationshipField = true\n if (groupHasManyTextField) hasManyTextField = true\n if (groupHasLocalizedManyTextField) hasLocalizedManyTextField = true\n if (groupHasManyNumberField) hasManyNumberField = true\n if (groupHasLocalizedManyNumberField) hasLocalizedManyNumberField = true\n break\n }\n\n case 'tabs': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n const {\n hasLocalizedField: tabHasLocalizedField,\n hasLocalizedManyNumberField: tabHasLocalizedManyNumberField,\n hasLocalizedManyTextField: tabHasLocalizedManyTextField,\n hasLocalizedRelationshipField: tabHasLocalizedRelationshipField,\n hasManyNumberField: tabHasManyNumberField,\n hasManyTextField: tabHasManyTextField,\n } = traverseFields({\n adapter,\n buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n forceLocalized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\n })\n\n if (tabHasLocalizedField) hasLocalizedField = true\n if (tabHasLocalizedRelationshipField) hasLocalizedRelationshipField = true\n if (tabHasManyTextField) hasManyTextField = true\n if (tabHasLocalizedManyTextField) hasLocalizedManyTextField = true\n if (tabHasManyNumberField) hasManyNumberField = true\n if (tabHasLocalizedManyNumberField) hasLocalizedManyNumberField = true\n break\n }\n\n case 'row':\n case 'collapsible': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n const {\n hasLocalizedField: rowHasLocalizedField,\n hasLocalizedManyNumberField: rowHasLocalizedManyNumberField,\n hasLocalizedManyTextField: rowHasLocalizedManyTextField,\n hasLocalizedRelationshipField: rowHasLocalizedRelationshipField,\n hasManyNumberField: rowHasManyNumberField,\n hasManyTextField: rowHasManyTextField,\n } = traverseFields({\n adapter,\n buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix,\n fields: field.fields,\n forceLocalized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName: parentTableName,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\n })\n\n if (rowHasLocalizedField) hasLocalizedField = true\n if (rowHasLocalizedRelationshipField) hasLocalizedRelationshipField = true\n if (rowHasManyTextField) hasManyTextField = true\n if (rowHasLocalizedManyTextField) hasLocalizedManyTextField = true\n if (rowHasManyNumberField) hasManyNumberField = true\n if (rowHasLocalizedManyNumberField) hasLocalizedManyNumberField = true\n break\n }\n\n case 'relationship':\n case 'upload':\n if (Array.isArray(field.relationTo)) {\n field.relationTo.forEach((relation) => relationships.add(relation))\n } else {\n relationships.add(field.relationTo)\n }\n\n if (field.localized && adapter.payload.config.localization) {\n hasLocalizedRelationshipField = true\n }\n break\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()\n }\n })\n\n return {\n hasLocalizedField,\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n }\n}\n"],"names":["relations","PgNumericBuilder","PgUUIDBuilder","PgVarcharBuilder","boolean","index","integer","jsonb","numeric","pgEnum","text","timestamp","varchar","InvalidConfiguration","fieldAffectsData","optionIsObject","toSnakeCase","hasLocalesTable","buildTable","createIndex","getTableName","idToUUID","parentIDColumnMap","validateExistingBlockIsIdentical","traverseFields","adapter","buildNumbers","buildRelationships","buildTexts","columnPrefix","columns","disableNotNull","disableUnique","fieldPrefix","fields","forceLocalized","indexes","localesColumns","localesIndexes","newTableName","parentTableName","relationsToBuild","relationships","rootRelationsToBuild","rootTableIDColType","rootTableName","versions","throwValidationError","hasLocalizedField","hasLocalizedRelationshipField","hasManyTextField","hasLocalizedManyTextField","hasManyNumberField","hasLocalizedManyNumberField","parentIDColType","id","forEach","field","name","columnName","fieldName","targetTable","targetIndexes","replace","payload","config","localization","localized","unique","includes","type","hasMany","constraintValue","fieldConstraints","tableName","mode","precision","withTimezone","enumName","prefix","target","enums","options","map","option","value","selectTableName","baseColumns","order","notNull","parent","references","tables","onDelete","baseExtraConfig","orderIdx","cols","on","parentIdx","locale","enum__locales","localeIdx","set","selectTableRelations","one","result","disableNotNullFromHere","Boolean","admin","condition","arrayTableName","_order","_parentID","_orderIdx","_parentIDIdx","_locale","_localeIdx","subHasManyNumberField","subHasManyTextField","subRelationsToBuild","rootRelationships","arrayTableRelations","many","_locales","localesSuffix","val","key","blocks","block","blockTableName","_path","_pathIdx","blockTableRelations","process","env","NODE_ENV","table","blockTableNames","slug","groupHasLocalizedField","groupHasLocalizedManyNumberField","groupHasLocalizedManyTextField","groupHasLocalizedRelationshipField","groupHasManyNumberField","groupHasManyTextField","tabHasLocalizedField","tabHasLocalizedManyNumberField","tabHasLocalizedManyTextField","tabHasLocalizedRelationshipField","tabHasManyNumberField","tabHasManyTextField","tabs","tab","rowHasLocalizedField","rowHasLocalizedManyNumberField","rowHasLocalizedManyTextField","rowHasLocalizedRelationshipField","rowHasManyNumberField","rowHasManyTextField","Array","isArray","relationTo","relation","add","required"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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B,WAAW,CAACD,UAAU,IACtB,cAAcH,SACdA,MAAM2G,QAAQ,IACd,CAACvD,WACD;YACAhD,WAAW,CAACD,UAAU,CAAC6B,OAAO;QAChC;IACF;IAEA,OAAO;QACLzC;QACAK;QACAF;QACAF;QACAG;QACAF;IACF;AACF,EAAC"}
|
1
|
+
{"version":3,"sources":["../../src/schema/traverseFields.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Relation } from 'drizzle-orm'\nimport type { IndexBuilder, PgColumnBuilder } from 'drizzle-orm/pg-core'\nimport type { Field, TabAsField } from 'payload/types'\n\nimport { relations } from 'drizzle-orm'\nimport {\n PgNumericBuilder,\n PgUUIDBuilder,\n PgVarcharBuilder,\n boolean,\n foreignKey,\n index,\n integer,\n jsonb,\n numeric,\n pgEnum,\n text,\n timestamp,\n varchar,\n} from 'drizzle-orm/pg-core'\nimport { InvalidConfiguration } from 'payload/errors'\nimport { fieldAffectsData, optionIsObject } from 'payload/types'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { GenericColumns, IDType, PostgresAdapter } from '../types.js'\nimport type { BaseExtraConfig } from './build.js'\n\nimport { hasLocalesTable } from '../utilities/hasLocalesTable.js'\nimport { buildTable } from './build.js'\nimport { createIndex } from './createIndex.js'\nimport { createTableName } from './createTableName.js'\nimport { idToUUID } from './idToUUID.js'\nimport { parentIDColumnMap } from './parentIDColumnMap.js'\nimport { validateExistingBlockIsIdentical } from './validateExistingBlockIsIdentical.js'\n\ntype Args = {\n adapter: PostgresAdapter\n buildNumbers: boolean\n buildRelationships: boolean\n buildTexts: boolean\n columnPrefix?: string\n columns: Record<string, PgColumnBuilder>\n disableNotNull: boolean\n disableUnique?: boolean\n fieldPrefix?: string\n fields: (Field | TabAsField)[]\n forceLocalized?: boolean\n indexes: Record<string, (cols: GenericColumns) => IndexBuilder>\n localesColumns: Record<string, PgColumnBuilder>\n localesIndexes: Record<string, (cols: GenericColumns) => IndexBuilder>\n newTableName: string\n parentTableName: string\n relationsToBuild: Map<string, string>\n relationships: Set<string>\n rootRelationsToBuild?: Map<string, string>\n rootTableIDColType: string\n rootTableName: string\n versions: 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 buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix,\n columns,\n disableNotNull,\n disableUnique = false,\n fieldPrefix,\n fields,\n forceLocalized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\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 if (columns.id instanceof PgUUIDBuilder) parentIDColType = 'uuid'\n if (columns.id instanceof PgNumericBuilder) parentIDColType = 'numeric'\n if (columns.id instanceof PgVarcharBuilder) parentIDColType = 'varchar'\n\n fields.forEach((field) => {\n if ('name' in field && field.name === 'id') return\n let columnName: string\n let fieldName: string\n\n let targetTable = columns\n let targetIndexes = indexes\n\n if (fieldAffectsData(field)) {\n columnName = `${columnPrefix || ''}${field.name[0] === '_' ? '_' : ''}${toSnakeCase(\n field.name,\n )}`\n 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 (adapter.payload.config.localization && (field.localized || forceLocalized)) {\n hasLocalizedField = true\n targetTable = localesColumns\n targetIndexes = localesIndexes\n }\n\n if (\n (field.unique || field.index) &&\n !['array', 'blocks', 'group', 'point', 'relationship', 'upload'].includes(field.type) &&\n !('hasMany' in field && field.hasMany === true)\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 targetIndexes[`${newTableName}_${field.name}Idx`] = createIndex({\n name: fieldName,\n columnName,\n tableName: newTableName,\n unique,\n })\n }\n }\n\n switch (field.type) {\n case 'text': {\n if (field.hasMany) {\n if (field.localized) {\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] = varchar(columnName)\n }\n break\n }\n case 'email':\n case 'code':\n case 'textarea': {\n targetTable[fieldName] = varchar(columnName)\n break\n }\n\n case 'number': {\n if (field.hasMany) {\n if (field.localized) {\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] = numeric(columnName)\n }\n break\n }\n\n case 'richText':\n case 'json': {\n targetTable[fieldName] = jsonb(columnName)\n break\n }\n\n case 'date': {\n targetTable[fieldName] = timestamp(columnName, {\n mode: 'string',\n precision: 3,\n withTimezone: true,\n })\n break\n }\n\n case 'point': {\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 adapter.enums[enumName] = pgEnum(\n enumName,\n field.options.map((option) => {\n if (optionIsObject(option)) {\n return option.value\n }\n\n return option\n }) as [string, ...string[]],\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 })\n const baseColumns: Record<string, PgColumnBuilder> = {\n order: integer('order').notNull(),\n parent: parentIDColumnMap[parentIDColType]('parent_id').notNull(),\n value: adapter.enums[enumName]('value'),\n }\n\n const baseExtraConfig: BaseExtraConfig = {\n orderIdx: (cols) => index(`${selectTableName}_order_idx`).on(cols.order),\n parentFk: (cols) =>\n foreignKey({\n name: `${selectTableName}_parent_fk`,\n columns: [cols.parent],\n foreignColumns: [adapter.tables[parentTableName].id],\n }),\n parentIdx: (cols) => index(`${selectTableName}_parent_idx`).on(cols.parent),\n }\n\n if (field.localized) {\n baseColumns.locale = adapter.enums.enum__locales('locale').notNull()\n baseExtraConfig.localeIdx = (cols) =>\n index(`${selectTableName}_locale_idx`).on(cols.locale)\n }\n\n if (field.index) {\n baseExtraConfig.value = (cols) => index(`${selectTableName}_value_idx`).on(cols.value)\n }\n\n buildTable({\n adapter,\n baseColumns,\n baseExtraConfig,\n disableNotNull,\n disableUnique,\n fields: [],\n tableName: selectTableName,\n versions,\n })\n\n relationsToBuild.set(fieldName, selectTableName)\n\n const selectTableRelations = relations(adapter.tables[selectTableName], ({ one }) => {\n const result: Record<string, Relation<string>> = {\n parent: one(adapter.tables[parentTableName], {\n fields: [adapter.tables[selectTableName].parent],\n references: [adapter.tables[parentTableName].id],\n }),\n }\n\n return result\n })\n\n adapter.relations[`relation_${selectTableName}`] = selectTableRelations\n } else {\n targetTable[fieldName] = adapter.enums[enumName](fieldName)\n }\n break\n }\n\n case 'checkbox': {\n targetTable[fieldName] = boolean(columnName)\n break\n }\n\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, PgColumnBuilder> = {\n _order: integer('_order').notNull(),\n _parentID: parentIDColumnMap[parentIDColType]('_parent_id').notNull(),\n }\n\n const baseExtraConfig: BaseExtraConfig = {\n _orderIdx: (cols) => index(`${arrayTableName}_order_idx`).on(cols._order),\n _parentIDFk: (cols) =>\n foreignKey({\n name: `${arrayTableName}_parent_id_fk`,\n columns: [cols['_parentID']],\n foreignColumns: [adapter.tables[parentTableName].id],\n }).onDelete('cascade'),\n _parentIDIdx: (cols) => index(`${arrayTableName}_parent_id_idx`).on(cols._parentID),\n }\n\n if (field.localized && adapter.payload.config.localization) {\n baseColumns._locale = adapter.enums.enum__locales('_locale').notNull()\n baseExtraConfig._localeIdx = (cols) =>\n index(`${arrayTableName}_locale_idx`).on(cols._locale)\n }\n\n const {\n hasManyNumberField: subHasManyNumberField,\n hasManyTextField: subHasManyTextField,\n relationsToBuild: subRelationsToBuild,\n } = buildTable({\n adapter,\n baseColumns,\n baseExtraConfig,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fields: disableUnique ? idToUUID(field.fields) : field.fields,\n rootRelationsToBuild,\n rootRelationships: relationships,\n rootTableIDColType,\n rootTableName,\n tableName: arrayTableName,\n versions,\n })\n\n if (subHasManyTextField) {\n if (!hasManyTextField || subHasManyTextField === 'index')\n hasManyTextField = subHasManyTextField\n }\n if (subHasManyNumberField) {\n if (!hasManyNumberField || subHasManyNumberField === 'index')\n hasManyNumberField = subHasManyNumberField\n }\n\n relationsToBuild.set(fieldName, arrayTableName)\n\n const arrayTableRelations = relations(adapter.tables[arrayTableName], ({ many, one }) => {\n const result: Record<string, Relation<string>> = {\n _parentID: one(adapter.tables[parentTableName], {\n fields: [adapter.tables[arrayTableName]._parentID],\n references: [adapter.tables[parentTableName].id],\n }),\n }\n\n if (hasLocalesTable(field.fields)) {\n result._locales = many(adapter.tables[`${arrayTableName}${adapter.localesSuffix}`])\n }\n\n subRelationsToBuild.forEach((val, key) => {\n result[key] = many(adapter.tables[val])\n })\n\n return result\n })\n\n adapter.relations[`relations_${arrayTableName}`] = arrayTableRelations\n\n break\n }\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.tables[blockTableName]) {\n const baseColumns: Record<string, PgColumnBuilder> = {\n _order: integer('_order').notNull(),\n _parentID: parentIDColumnMap[rootTableIDColType]('_parent_id').notNull(),\n _path: text('_path').notNull(),\n }\n\n const baseExtraConfig: BaseExtraConfig = {\n _orderIdx: (cols) => index(`${blockTableName}_order_idx`).on(cols._order),\n _parentIDIdx: (cols) => index(`${blockTableName}_parent_id_idx`).on(cols._parentID),\n _parentIdFk: (cols) =>\n foreignKey({\n name: `${blockTableName}_parent_id_fk`,\n columns: [cols._parentID],\n foreignColumns: [adapter.tables[rootTableName].id],\n }).onDelete('cascade'),\n _pathIdx: (cols) => index(`${blockTableName}_path_idx`).on(cols._path),\n }\n\n if (field.localized && adapter.payload.config.localization) {\n baseColumns._locale = adapter.enums.enum__locales('_locale').notNull()\n baseExtraConfig._localeIdx = (cols) =>\n index(`${blockTableName}_locale_idx`).on(cols._locale)\n }\n\n const {\n hasManyNumberField: subHasManyNumberField,\n hasManyTextField: subHasManyTextField,\n relationsToBuild: subRelationsToBuild,\n } = buildTable({\n adapter,\n baseColumns,\n baseExtraConfig,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fields: disableUnique ? idToUUID(block.fields) : block.fields,\n rootRelationsToBuild,\n rootRelationships: relationships,\n rootTableIDColType,\n rootTableName,\n tableName: blockTableName,\n versions,\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 const blockTableRelations = relations(\n adapter.tables[blockTableName],\n ({ many, one }) => {\n const result: Record<string, Relation<string>> = {\n _parentID: one(adapter.tables[rootTableName], {\n fields: [adapter.tables[blockTableName]._parentID],\n references: [adapter.tables[rootTableName].id],\n }),\n }\n\n if (hasLocalesTable(block.fields)) {\n result._locales = many(\n adapter.tables[`${blockTableName}${adapter.localesSuffix}`],\n )\n }\n\n subRelationsToBuild.forEach((val, key) => {\n result[key] = many(adapter.tables[val])\n })\n\n return result\n },\n )\n\n adapter.relations[`relations_${blockTableName}`] = blockTableRelations\n } else if (process.env.NODE_ENV !== 'production' && !versions) {\n validateExistingBlockIsIdentical({\n block,\n localized: field.localized,\n rootTableName,\n table: adapter.tables[blockTableName],\n tableLocales: adapter.tables[`${blockTableName}${adapter.localesSuffix}`],\n })\n }\n rootRelationsToBuild.set(`_blocks_${block.slug}`, blockTableName)\n })\n\n break\n }\n\n case 'tab':\n case 'group': {\n if (!('name' in field)) {\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 buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix,\n columns,\n disableNotNull,\n disableUnique,\n fieldPrefix,\n fields: field.fields,\n forceLocalized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\n })\n\n if (groupHasLocalizedField) hasLocalizedField = true\n if (groupHasLocalizedRelationshipField) hasLocalizedRelationshipField = true\n if (groupHasManyTextField) hasManyTextField = true\n if (groupHasLocalizedManyTextField) hasLocalizedManyTextField = true\n if (groupHasManyNumberField) hasManyNumberField = true\n if (groupHasLocalizedManyNumberField) hasLocalizedManyNumberField = true\n break\n }\n\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 buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix: `${columnName}_`,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix: `${fieldName}.`,\n fields: field.fields,\n forceLocalized: field.localized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName: `${parentTableName}_${columnName}`,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\n })\n\n if (groupHasLocalizedField) hasLocalizedField = true\n if (groupHasLocalizedRelationshipField) hasLocalizedRelationshipField = true\n if (groupHasManyTextField) hasManyTextField = true\n if (groupHasLocalizedManyTextField) hasLocalizedManyTextField = true\n if (groupHasManyNumberField) hasManyNumberField = true\n if (groupHasLocalizedManyNumberField) hasLocalizedManyNumberField = true\n break\n }\n\n case 'tabs': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n const {\n hasLocalizedField: tabHasLocalizedField,\n hasLocalizedManyNumberField: tabHasLocalizedManyNumberField,\n hasLocalizedManyTextField: tabHasLocalizedManyTextField,\n hasLocalizedRelationshipField: tabHasLocalizedRelationshipField,\n hasManyNumberField: tabHasManyNumberField,\n hasManyTextField: tabHasManyTextField,\n } = traverseFields({\n adapter,\n buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n forceLocalized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\n })\n\n if (tabHasLocalizedField) hasLocalizedField = true\n if (tabHasLocalizedRelationshipField) hasLocalizedRelationshipField = true\n if (tabHasManyTextField) hasManyTextField = true\n if (tabHasLocalizedManyTextField) hasLocalizedManyTextField = true\n if (tabHasManyNumberField) hasManyNumberField = true\n if (tabHasLocalizedManyNumberField) hasLocalizedManyNumberField = true\n break\n }\n\n case 'row':\n case 'collapsible': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n const {\n hasLocalizedField: rowHasLocalizedField,\n hasLocalizedManyNumberField: rowHasLocalizedManyNumberField,\n hasLocalizedManyTextField: rowHasLocalizedManyTextField,\n hasLocalizedRelationshipField: rowHasLocalizedRelationshipField,\n hasManyNumberField: rowHasManyNumberField,\n hasManyTextField: rowHasManyTextField,\n } = traverseFields({\n adapter,\n buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix,\n fields: field.fields,\n forceLocalized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\n })\n\n if (rowHasLocalizedField) hasLocalizedField = true\n if (rowHasLocalizedRelationshipField) hasLocalizedRelationshipField = true\n if (rowHasManyTextField) hasManyTextField = true\n if (rowHasLocalizedManyTextField) hasLocalizedManyTextField = true\n if (rowHasManyNumberField) hasManyNumberField = true\n if (rowHasLocalizedManyNumberField) hasLocalizedManyNumberField = true\n break\n }\n\n case 'relationship':\n case 'upload':\n if (Array.isArray(field.relationTo)) {\n field.relationTo.forEach((relation) => relationships.add(relation))\n } else {\n relationships.add(field.relationTo)\n }\n\n if (field.localized && adapter.payload.config.localization) {\n hasLocalizedRelationshipField = true\n }\n break\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()\n }\n })\n\n return {\n hasLocalizedField,\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n }\n}\n"],"names":["relations","PgNumericBuilder","PgUUIDBuilder","PgVarcharBuilder","boolean","foreignKey","index","integer","jsonb","numeric","pgEnum","text","timestamp","varchar","InvalidConfiguration","fieldAffectsData","optionIsObject","toSnakeCase","hasLocalesTable","buildTable","createIndex","createTableName","idToUUID","parentIDColumnMap","validateExistingBlockIsIdentical","traverseFields","adapter","buildNumbers","buildRelationships","buildTexts","columnPrefix","columns","disableNotNull","disableUnique","fieldPrefix","fields","forceLocalized","indexes","localesColumns","localesIndexes","newTableName","parentTableName","relationsToBuild","relationships","rootRelationsToBuild","rootTableIDColType","rootTableName","versions","throwValidationError","hasLocalizedField","hasLocalizedRelationshipField","hasManyTextField","hasLocalizedManyTextField","hasManyNumberField","hasLocalizedManyNumberField","parentIDColType","id","forEach","field","name","columnName","fieldName","targetTable","targetIndexes","replace","payload","config","localization","localized","unique","includes","type","hasMany","constraintValue","fieldConstraints","tableName","mode","precision","withTimezone","enumName","prefix","target","enums","options","map","option","value","selectTableName","baseColumns","order","notNull","parent","baseExtraConfig","orderIdx","cols","on","parentFk","foreignColumns","tables","parentIdx","locale","enum__locales","localeIdx","set","selectTableRelations","one","result","references","disableNotNullFromHere","Boolean","admin","condition","arrayTableName","versionsCustomName","_order","_parentID","_orderIdx","_parentIDFk","onDelete","_parentIDIdx","_locale","_localeIdx","subHasManyNumberField","subHasManyTextField","subRelationsToBuild","rootRelationships","arrayTableRelations","many","_locales","localesSuffix","val","key","blocks","block","blockTableName","_path","_parentIdFk","_pathIdx","blockTableRelations","process","env","NODE_ENV","table","tableLocales","slug","groupHasLocalizedField","groupHasLocalizedManyNumberField","groupHasLocalizedManyTextField","groupHasLocalizedRelationshipField","groupHasManyNumberField","groupHasManyTextField","tabHasLocalizedField","tabHasLocalizedManyNumberField","tabHasLocalizedManyTextField","tabHasLocalizedRelationshipField","tabHasManyNumberField","tabHasManyTextField","tabs","tab","rowHasLocalizedField","rowHasLocalizedManyNumberField","rowHasLocalizedManyTextField","rowHasLocalizedRelationshipField","rowHasManyNumberField","rowHasManyTextField","Array","isArray","relationTo","relation","add","required"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAKpC,SAASA,SAAS,QAAQ,cAAa;AACvC,SACEC,gBAAgB,EAChBC,aAAa,EACbC,gBAAgB,EAChBC,OAAO,EACPC,UAAU,EACVC,KAAK,EACLC,OAAO,EACPC,KAAK,EACLC,OAAO,EACPC,MAAM,EACNC,IAAI,EACJC,SAAS,EACTC,OAAO,QACF,sBAAqB;AAC5B,SAASC,oBAAoB,QAAQ,iBAAgB;AACrD,SAASC,gBAAgB,EAAEC,cAAc,QAAQ,gBAAe;AAChE,OAAOC,iBAAi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CAAC/E,kBACD8B,WAAW,CAACD,UAAU,IACtB,cAAcH,SACdA,MAAMgH,QAAQ,IACd,CAAC3D,WACD;YACAjD,WAAW,CAACD,UAAU,CAAC6B,OAAO;QAChC;IACF;IAEA,OAAO;QACLzC;QACAK;QACAF;QACAF;QACAG;QACAF;IACF;AACF,EAAC"}
|
@@ -5,7 +5,8 @@ type Args = {
|
|
5
5
|
localized: boolean;
|
6
6
|
rootTableName: string;
|
7
7
|
table: GenericTable;
|
8
|
+
tableLocales?: GenericTable;
|
8
9
|
};
|
9
|
-
export declare const validateExistingBlockIsIdentical: ({ block, localized, rootTableName, table, }: Args) => void;
|
10
|
+
export declare const validateExistingBlockIsIdentical: ({ block, localized, rootTableName, table, tableLocales, }: Args) => void;
|
10
11
|
export {};
|
11
12
|
//# sourceMappingURL=validateExistingBlockIsIdentical.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"validateExistingBlockIsIdentical.d.ts","sourceRoot":"","sources":["../../src/schema/validateExistingBlockIsIdentical.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAS,MAAM,eAAe,CAAA;AAKjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,KAAK,IAAI,GAAG;IACV,KAAK,EAAE,KAAK,CAAA;IACZ,SAAS,EAAE,OAAO,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;IACrB,KAAK,EAAE,YAAY,CAAA;
|
1
|
+
{"version":3,"file":"validateExistingBlockIsIdentical.d.ts","sourceRoot":"","sources":["../../src/schema/validateExistingBlockIsIdentical.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAS,MAAM,eAAe,CAAA;AAKjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,KAAK,IAAI,GAAG;IACV,KAAK,EAAE,KAAK,CAAA;IACZ,SAAS,EAAE,OAAO,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;IACrB,KAAK,EAAE,YAAY,CAAA;IACnB,YAAY,CAAC,EAAE,YAAY,CAAA;CAC5B,CAAA;AAkDD,eAAO,MAAM,gCAAgC,8DAM1C,IAAI,KAAG,IA+BT,CAAA"}
|
@@ -12,7 +12,7 @@ const getFlattenedFieldNames = (fields, prefix = '')=>{
|
|
12
12
|
return fieldsToUse;
|
13
13
|
}
|
14
14
|
if (fieldHasSubFields(field)) {
|
15
|
-
fieldPrefix = 'name' in field ? `${prefix}${field.name}
|
15
|
+
fieldPrefix = 'name' in field ? `${prefix}${field.name}_` : prefix;
|
16
16
|
return [
|
17
17
|
...fieldsToUse,
|
18
18
|
...getFlattenedFieldNames(field.fields, fieldPrefix)
|
@@ -22,7 +22,7 @@ const getFlattenedFieldNames = (fields, prefix = '')=>{
|
|
22
22
|
return [
|
23
23
|
...fieldsToUse,
|
24
24
|
...field.tabs.reduce((tabFields, tab)=>{
|
25
|
-
fieldPrefix = 'name' in tab ? `${prefix}
|
25
|
+
fieldPrefix = 'name' in tab ? `${prefix}_${tab.name}` : prefix;
|
26
26
|
return [
|
27
27
|
...tabFields,
|
28
28
|
...tabHasName(tab) ? [
|
@@ -38,16 +38,22 @@ const getFlattenedFieldNames = (fields, prefix = '')=>{
|
|
38
38
|
if (fieldAffectsData(field)) {
|
39
39
|
return [
|
40
40
|
...fieldsToUse,
|
41
|
-
|
41
|
+
{
|
42
|
+
name: `${fieldPrefix}${field.name}`,
|
43
|
+
localized: field.localized
|
44
|
+
}
|
42
45
|
];
|
43
46
|
}
|
44
47
|
return fieldsToUse;
|
45
48
|
}, []);
|
46
49
|
};
|
47
|
-
export const validateExistingBlockIsIdentical = ({ block, localized, rootTableName, table })=>{
|
50
|
+
export const validateExistingBlockIsIdentical = ({ block, localized, rootTableName, table, tableLocales })=>{
|
48
51
|
const fieldNames = getFlattenedFieldNames(block.fields);
|
49
52
|
const missingField = // ensure every field from the config is in the matching table
|
50
|
-
fieldNames.find((name
|
53
|
+
fieldNames.find(({ name, localized })=>{
|
54
|
+
const fieldTable = localized && tableLocales ? tableLocales : table;
|
55
|
+
return Object.keys(fieldTable).indexOf(name) === -1;
|
56
|
+
}) || // ensure every table column is matched for every field from the config
|
51
57
|
Object.keys(table).find((fieldName)=>{
|
52
58
|
if (![
|
53
59
|
'_locale',
|
@@ -56,11 +62,11 @@ export const validateExistingBlockIsIdentical = ({ block, localized, rootTableNa
|
|
56
62
|
'_path',
|
57
63
|
'_uuid'
|
58
64
|
].includes(fieldName)) {
|
59
|
-
return fieldNames.
|
65
|
+
return fieldNames.findIndex((field)=>field.name) === -1;
|
60
66
|
}
|
61
67
|
});
|
62
68
|
if (missingField) {
|
63
|
-
throw new InvalidConfiguration(`The table ${rootTableName} has multiple blocks with slug ${block.slug}, but the schemas do not match. One block includes the field ${missingField}, while the other block does not.`);
|
69
|
+
throw new InvalidConfiguration(`The table ${rootTableName} has multiple blocks with slug ${block.slug}, but the schemas do not match. One block includes the field ${typeof missingField === 'string' ? missingField : missingField.name}, while the other block does not.`);
|
64
70
|
}
|
65
71
|
if (Boolean(localized) !== Boolean(table._locale)) {
|
66
72
|
throw new InvalidConfiguration(`The table ${rootTableName} has multiple blocks with slug ${block.slug}, but the schemas do not match. One is localized, but another is not. Block schemas of the same name must match exactly.`);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/schema/validateExistingBlockIsIdentical.ts"],"sourcesContent":["import type { Block, Field } from 'payload/types'\n\nimport { InvalidConfiguration } from 'payload/errors'\nimport { fieldAffectsData, fieldHasSubFields, tabHasName } from 'payload/types'\n\nimport type { GenericTable } from '../types.js'\n\ntype Args = {\n block: Block\n localized: boolean\n rootTableName: string\n table: GenericTable\n}\n\nconst getFlattenedFieldNames = (fields: Field[]
|
1
|
+
{"version":3,"sources":["../../src/schema/validateExistingBlockIsIdentical.ts"],"sourcesContent":["import type { Block, Field } from 'payload/types'\n\nimport { InvalidConfiguration } from 'payload/errors'\nimport { fieldAffectsData, fieldHasSubFields, tabHasName } from 'payload/types'\n\nimport type { GenericTable } from '../types.js'\n\ntype Args = {\n block: Block\n localized: boolean\n rootTableName: string\n table: GenericTable\n tableLocales?: GenericTable\n}\n\nconst getFlattenedFieldNames = (\n fields: Field[],\n prefix: string = '',\n): { localized?: boolean; name: string }[] => {\n return fields.reduce((fieldsToUse, field) => {\n let fieldPrefix = prefix\n\n if (\n ['array', 'blocks', 'relationship', 'upload'].includes(field.type) ||\n ('hasMany' in field && field.hasMany === true)\n ) {\n return fieldsToUse\n }\n\n if (fieldHasSubFields(field)) {\n fieldPrefix = 'name' in field ? `${prefix}${field.name}_` : prefix\n return [...fieldsToUse, ...getFlattenedFieldNames(field.fields, fieldPrefix)]\n }\n\n if (field.type === 'tabs') {\n return [\n ...fieldsToUse,\n ...field.tabs.reduce((tabFields, tab) => {\n fieldPrefix = 'name' in tab ? `${prefix}_${tab.name}` : prefix\n return [\n ...tabFields,\n ...(tabHasName(tab)\n ? [{ ...tab, type: 'tab' }]\n : getFlattenedFieldNames(tab.fields, fieldPrefix)),\n ]\n }, []),\n ]\n }\n\n if (fieldAffectsData(field)) {\n return [\n ...fieldsToUse,\n {\n name: `${fieldPrefix}${field.name}`,\n localized: field.localized,\n },\n ]\n }\n\n return fieldsToUse\n }, [])\n}\n\nexport const validateExistingBlockIsIdentical = ({\n block,\n localized,\n rootTableName,\n table,\n tableLocales,\n}: Args): void => {\n const fieldNames = getFlattenedFieldNames(block.fields)\n\n const missingField =\n // ensure every field from the config is in the matching table\n fieldNames.find(({ name, localized }) => {\n const fieldTable = localized && tableLocales ? tableLocales : table\n return Object.keys(fieldTable).indexOf(name) === -1\n }) ||\n // ensure every table column is matched for every field from the config\n Object.keys(table).find((fieldName) => {\n if (!['_locale', '_order', '_parentID', '_path', '_uuid'].includes(fieldName)) {\n return fieldNames.findIndex((field) => field.name) === -1\n }\n })\n\n if (missingField) {\n throw new InvalidConfiguration(\n `The table ${rootTableName} has multiple blocks with slug ${\n block.slug\n }, but the schemas do not match. One block includes the field ${\n typeof missingField === 'string' ? missingField : missingField.name\n }, while the other block does not.`,\n )\n }\n\n if (Boolean(localized) !== Boolean(table._locale)) {\n throw new InvalidConfiguration(\n `The table ${rootTableName} has multiple blocks with slug ${block.slug}, but the schemas do not match. One is localized, but another is not. Block schemas of the same name must match exactly.`,\n )\n }\n}\n"],"names":["InvalidConfiguration","fieldAffectsData","fieldHasSubFields","tabHasName","getFlattenedFieldNames","fields","prefix","reduce","fieldsToUse","field","fieldPrefix","includes","type","hasMany","name","tabs","tabFields","tab","localized","validateExistingBlockIsIdentical","block","rootTableName","table","tableLocales","fieldNames","missingField","find","fieldTable","Object","keys","indexOf","fieldName","findIndex","slug","Boolean","_locale"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,oBAAoB,QAAQ,iBAAgB;AACrD,SAASC,gBAAgB,EAAEC,iBAAiB,EAAEC,UAAU,QAAQ,gBAAe;AAY/E,MAAMC,yBAAyB,CAC7BC,QACAC,SAAiB,EAAE;IAEnB,OAAOD,OAAOE,MAAM,CAAC,CAACC,aAAaC;QACjC,IAAIC,cAAcJ;QAElB,IACE;YAAC;YAAS;YAAU;YAAgB;SAAS,CAACK,QAAQ,CAACF,MAAMG,IAAI,KAChE,aAAaH,SAASA,MAAMI,OAAO,KAAK,MACzC;YACA,OAAOL;QACT;QAEA,IAAIN,kBAAkBO,QAAQ;YAC5BC,cAAc,UAAUD,QAAQ,CAAC,EAAEH,OAAO,EAAEG,MAAMK,IAAI,CAAC,CAAC,CAAC,GAAGR;YAC5D,OAAO;mBAAIE;mBAAgBJ,uBAAuBK,MAAMJ,MAAM,EAAEK;aAAa;QAC/E;QAEA,IAAID,MAAMG,IAAI,KAAK,QAAQ;YACzB,OAAO;mBACFJ;mBACAC,MAAMM,IAAI,CAACR,MAAM,CAAC,CAACS,WAAWC;oBAC/BP,cAAc,UAAUO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AexB,IAAI,
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../../src/transform/write/array.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAK1F,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,EAAE,MAAM,CAAA;IACtB,aAAa,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE;QACN,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAAA;KACxC,CAAA;IACD,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC3B,IAAI,EAAE,OAAO,CAAA;IACb,KAAK,EAAE,UAAU,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IACxC,qBAAqB,EAAE,oBAAoB,EAAE,CAAA;IAC7C,OAAO,EAAE;QACP,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;KAC/C,CAAA;IACD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;CACjC,CAAA;AAED,eAAO,MAAM,cAAc,kKAexB,IAAI,uBA6DN,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/transform/write/array.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { ArrayField } from 'payload/types'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { ArrayRowToInsert, BlockRowToInsert, RelationshipToDelete } from './types.js'\n\nimport { isArrayOfRows } from '../../utilities/isArrayOfRows.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: PostgresAdapter\n arrayTableName: string\n baseTableName: string\n blocks: {\n [blockType: string]: BlockRowToInsert[]\n }\n blocksToDelete: Set<string>\n data: unknown\n field: ArrayField\n locale?: string\n numbers: Record<string, unknown>[]\n path: string\n relationships: Record<string, unknown>[]\n relationshipsToDelete: RelationshipToDelete[]\n selects: {\n [tableName: string]: Record<string, unknown>[]\n }\n texts: Record<string, unknown>[]\n}\n\nexport const transformArray = ({\n adapter,\n arrayTableName,\n baseTableName,\n blocks,\n blocksToDelete,\n data,\n field,\n locale,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n}: Args) => {\n const newRows: ArrayRowToInsert[] = []\n const hasUUID = adapter.tables[arrayTableName]._uuid\n\n if (isArrayOfRows(data)) {\n data.forEach((arrayRow, i) => {\n const newRow: ArrayRowToInsert = {\n arrays: {},\n locales: {},\n row: {\n _order: i + 1,\n },\n }\n\n // If we have declared a _uuid field on arrays,\n // that means the ID has to be unique,\n // and our ids within arrays are not unique.\n // So move the ID to a uuid field for storage\n // and allow the database to generate a serial id automatically\n if (hasUUID) {\n newRow.row._uuid = arrayRow.id\n delete arrayRow.id\n }\n\n if (locale) {\n newRow.locales[locale] = {\n _locale: locale,\n }\n }\n\n if (field.localized) {\n newRow.row._locale = locale\n }\n\n traverseFields({\n adapter,\n arrays: newRow.arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: '',\n data: arrayRow,\n fieldPrefix: '',\n fields: field.fields,\n locales: newRow.locales,\n numbers,\n parentTableName: arrayTableName,\n path: `${path || ''}${field.name}.${i}.`,\n relationships,\n relationshipsToDelete,\n row: newRow.row,\n selects,\n texts,\n })\n\n newRows.push(newRow)\n })\n }\n\n return newRows\n}\n"],"names":["isArrayOfRows","traverseFields","transformArray","adapter","arrayTableName","baseTableName","blocks","blocksToDelete","data","field","locale","numbers","path","relationships","relationshipsToDelete","selects","texts","newRows","hasUUID","tables","_uuid","forEach","arrayRow","i","newRow","arrays","locales","row","_order","id","_locale","localized","columnPrefix","fieldPrefix","fields","parentTableName","name","push"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAMpC,SAASA,aAAa,QAAQ,mCAAkC;AAChE,SAASC,cAAc,QAAQ,sBAAqB;AAuBpD,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,OAAO,EACPC,cAAc,EACdC,aAAa,EACbC,MAAM,EACNC,cAAc,EACdC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,OAAO,EACPC,IAAI,EACJC,aAAa,EACbC,qBAAqB,EACrBC,OAAO,EACPC,KAAK,EACA;IACL,MAAMC,UAA8B,EAAE;
|
1
|
+
{"version":3,"sources":["../../../src/transform/write/array.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { ArrayField } from 'payload/types'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { ArrayRowToInsert, BlockRowToInsert, RelationshipToDelete } from './types.js'\n\nimport { isArrayOfRows } from '../../utilities/isArrayOfRows.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: PostgresAdapter\n arrayTableName: string\n baseTableName: string\n blocks: {\n [blockType: string]: BlockRowToInsert[]\n }\n blocksToDelete: Set<string>\n data: unknown\n field: ArrayField\n locale?: string\n numbers: Record<string, unknown>[]\n path: string\n relationships: Record<string, unknown>[]\n relationshipsToDelete: RelationshipToDelete[]\n selects: {\n [tableName: string]: Record<string, unknown>[]\n }\n texts: Record<string, unknown>[]\n}\n\nexport const transformArray = ({\n adapter,\n arrayTableName,\n baseTableName,\n blocks,\n blocksToDelete,\n data,\n field,\n locale,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n}: Args) => {\n const newRows: ArrayRowToInsert[] = []\n\n const hasUUID = adapter.tables[arrayTableName]._uuid\n\n if (isArrayOfRows(data)) {\n data.forEach((arrayRow, i) => {\n const newRow: ArrayRowToInsert = {\n arrays: {},\n locales: {},\n row: {\n _order: i + 1,\n },\n }\n\n // If we have declared a _uuid field on arrays,\n // that means the ID has to be unique,\n // and our ids within arrays are not unique.\n // So move the ID to a uuid field for storage\n // and allow the database to generate a serial id automatically\n if (hasUUID) {\n newRow.row._uuid = arrayRow.id\n delete arrayRow.id\n }\n\n if (locale) {\n newRow.locales[locale] = {\n _locale: locale,\n }\n }\n\n if (field.localized) {\n newRow.row._locale = locale\n }\n\n traverseFields({\n adapter,\n arrays: newRow.arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: '',\n data: arrayRow,\n fieldPrefix: '',\n fields: field.fields,\n locales: newRow.locales,\n numbers,\n parentTableName: arrayTableName,\n path: `${path || ''}${field.name}.${i}.`,\n relationships,\n relationshipsToDelete,\n row: newRow.row,\n selects,\n texts,\n })\n\n newRows.push(newRow)\n })\n }\n\n return newRows\n}\n"],"names":["isArrayOfRows","traverseFields","transformArray","adapter","arrayTableName","baseTableName","blocks","blocksToDelete","data","field","locale","numbers","path","relationships","relationshipsToDelete","selects","texts","newRows","hasUUID","tables","_uuid","forEach","arrayRow","i","newRow","arrays","locales","row","_order","id","_locale","localized","columnPrefix","fieldPrefix","fields","parentTableName","name","push"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAMpC,SAASA,aAAa,QAAQ,mCAAkC;AAChE,SAASC,cAAc,QAAQ,sBAAqB;AAuBpD,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,OAAO,EACPC,cAAc,EACdC,aAAa,EACbC,MAAM,EACNC,cAAc,EACdC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,OAAO,EACPC,IAAI,EACJC,aAAa,EACbC,qBAAqB,EACrBC,OAAO,EACPC,KAAK,EACA;IACL,MAAMC,UAA8B,EAAE;IAEtC,MAAMC,UAAUf,QAAQgB,MAAM,CAACf,eAAe,CAACgB,KAAK;IAEpD,IAAIpB,cAAcQ,OAAO;QACvBA,KAAKa,OAAO,CAAC,CAACC,UAAUC;YACtB,MAAMC,SAA2B;gBAC/BC,QAAQ,CAAC;gBACTC,SAAS,CAAC;gBACVC,KAAK;oBACHC,QAAQL,IAAI;gBACd;YACF;YAEA,+CAA+C;YAC/C,sCAAsC;YACtC,4CAA4C;YAC5C,6CAA6C;YAC7C,+DAA+D;YAC/D,IAAIL,SAAS;gBACXM,OAAOG,GAAG,CAACP,KAAK,GAAGE,SAASO,EAAE;gBAC9B,OAAOP,SAASO,EAAE;YACpB;YAEA,IAAInB,QAAQ;gBACVc,OAAOE,OAAO,CAAChB,OAAO,GAAG;oBACvBoB,SAASpB;gBACX;YACF;YAEA,IAAID,MAAMsB,SAAS,EAAE;gBACnBP,OAAOG,GAAG,CAACG,OAAO,GAAGpB;YACvB;YAEAT,eAAe;gBACbE;gBACAsB,QAAQD,OAAOC,MAAM;gBACrBpB;gBACAC;gBACAC;gBACAyB,cAAc;gBACdxB,MAAMc;gBACNW,aAAa;gBACbC,QAAQzB,MAAMyB,MAAM;gBACpBR,SAASF,OAAOE,OAAO;gBACvBf;gBACAwB,iBAAiB/B;gBACjBQ,MAAM,CAAC,EAAEA,QAAQ,GAAG,EAAEH,MAAM2B,IAAI,CAAC,CAAC,EAAEb,EAAE,CAAC,CAAC;gBACxCV;gBACAC;gBACAa,KAAKH,OAAOG,GAAG;gBACfZ;gBACAC;YACF;YAEAC,QAAQoB,IAAI,CAACb;QACf;IACF;IAEA,OAAOP;AACT,EAAC"}
|
@@ -16,7 +16,7 @@ export const transformBlocks = ({ adapter, baseTableName, blocks, blocksToDelete
|
|
16
16
|
}
|
17
17
|
};
|
18
18
|
if (field.localized && locale) newRow.row._locale = locale;
|
19
|
-
const blockTableName = `${baseTableName}_blocks_${blockType}
|
19
|
+
const blockTableName = adapter.tableNameMap.get(`${baseTableName}_blocks_${blockType}`);
|
20
20
|
const hasUUID = adapter.tables[blockTableName]._uuid;
|
21
21
|
// If we have declared a _uuid field on arrays,
|
22
22
|
// that means the ID has to be unique,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/transform/write/blocks.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { BlockField } from 'payload/types'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { BlockRowToInsert, RelationshipToDelete } from './types.js'\n\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: PostgresAdapter\n baseTableName: string\n blocks: {\n [blockType: string]: BlockRowToInsert[]\n }\n blocksToDelete: Set<string>\n data: Record<string, unknown>[]\n field: BlockField\n locale?: string\n numbers: Record<string, unknown>[]\n path: string\n relationships: Record<string, unknown>[]\n relationshipsToDelete: RelationshipToDelete[]\n selects: {\n [tableName: string]: Record<string, unknown>[]\n }\n texts: Record<string, unknown>[]\n}\nexport const transformBlocks = ({\n adapter,\n baseTableName,\n blocks,\n blocksToDelete,\n data,\n field,\n locale,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n}: Args) => {\n data.forEach((blockRow, i) => {\n if (typeof blockRow.blockType !== 'string') return\n const matchedBlock = field.blocks.find(({ slug }) => slug === blockRow.blockType)\n if (!matchedBlock) return\n const blockType = toSnakeCase(blockRow.blockType)\n\n if (!blocks[blockType]) blocks[blockType] = []\n\n const newRow: BlockRowToInsert = {\n arrays: {},\n locales: {},\n row: {\n _order: i + 1,\n _path: `${path}${field.name}`,\n },\n }\n\n if (field.localized && locale) newRow.row._locale = locale\n\n const blockTableName = `${baseTableName}_blocks_${blockType}
|
1
|
+
{"version":3,"sources":["../../../src/transform/write/blocks.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { BlockField } from 'payload/types'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { BlockRowToInsert, RelationshipToDelete } from './types.js'\n\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: PostgresAdapter\n baseTableName: string\n blocks: {\n [blockType: string]: BlockRowToInsert[]\n }\n blocksToDelete: Set<string>\n data: Record<string, unknown>[]\n field: BlockField\n locale?: string\n numbers: Record<string, unknown>[]\n path: string\n relationships: Record<string, unknown>[]\n relationshipsToDelete: RelationshipToDelete[]\n selects: {\n [tableName: string]: Record<string, unknown>[]\n }\n texts: Record<string, unknown>[]\n}\nexport const transformBlocks = ({\n adapter,\n baseTableName,\n blocks,\n blocksToDelete,\n data,\n field,\n locale,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n}: Args) => {\n data.forEach((blockRow, i) => {\n if (typeof blockRow.blockType !== 'string') return\n const matchedBlock = field.blocks.find(({ slug }) => slug === blockRow.blockType)\n if (!matchedBlock) return\n const blockType = toSnakeCase(blockRow.blockType)\n\n if (!blocks[blockType]) blocks[blockType] = []\n\n const newRow: BlockRowToInsert = {\n arrays: {},\n locales: {},\n row: {\n _order: i + 1,\n _path: `${path}${field.name}`,\n },\n }\n\n if (field.localized && locale) newRow.row._locale = locale\n\n const blockTableName = adapter.tableNameMap.get(`${baseTableName}_blocks_${blockType}`)\n\n const hasUUID = adapter.tables[blockTableName]._uuid\n\n // If we have declared a _uuid field on arrays,\n // that means the ID has to be unique,\n // and our ids within arrays are not unique.\n // So move the ID to a uuid field for storage\n // and allow the database to generate a serial id automatically\n if (hasUUID) {\n newRow.row._uuid = blockRow.id\n delete blockRow.id\n }\n\n traverseFields({\n adapter,\n arrays: newRow.arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: '',\n data: blockRow,\n fieldPrefix: '',\n fields: matchedBlock.fields,\n locales: newRow.locales,\n numbers,\n parentTableName: blockTableName,\n path: `${path || ''}${field.name}.${i}.`,\n relationships,\n relationshipsToDelete,\n row: newRow.row,\n selects,\n texts,\n })\n\n blocks[blockType].push(newRow)\n })\n}\n"],"names":["toSnakeCase","traverseFields","transformBlocks","adapter","baseTableName","blocks","blocksToDelete","data","field","locale","numbers","path","relationships","relationshipsToDelete","selects","texts","forEach","blockRow","i","blockType","matchedBlock","find","slug","newRow","arrays","locales","row","_order","_path","name","localized","_locale","blockTableName","tableNameMap","get","hasUUID","tables","_uuid","id","columnPrefix","fieldPrefix","fields","parentTableName","push"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAGpC,OAAOA,iBAAiB,gBAAe;AAKvC,SAASC,cAAc,QAAQ,sBAAqB;AAqBpD,OAAO,MAAMC,kBAAkB,CAAC,EAC9BC,OAAO,EACPC,aAAa,EACbC,MAAM,EACNC,cAAc,EACdC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,OAAO,EACPC,IAAI,EACJC,aAAa,EACbC,qBAAqB,EACrBC,OAAO,EACPC,KAAK,EACA;IACLR,KAAKS,OAAO,CAAC,CAACC,UAAUC;QACtB,IAAI,OAAOD,SAASE,SAAS,KAAK,UAAU;QAC5C,MAAMC,eAAeZ,MAAMH,MAAM,CAACgB,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASL,SAASE,SAAS;QAChF,IAAI,CAACC,cAAc;QACnB,MAAMD,YAAYnB,YAAYiB,SAASE,SAAS;QAEhD,IAAI,CAACd,MAAM,CAACc,UAAU,EAAEd,MAAM,CAACc,UAAU,GAAG,EAAE;QAE9C,MAAMI,SAA2B;YAC/BC,QAAQ,CAAC;YACTC,SAAS,CAAC;YACVC,KAAK;gBACHC,QAAQT,IAAI;gBACZU,OAAO,CAAC,EAAEjB,KAAK,EAAEH,MAAMqB,IAAI,CAAC,CAAC;YAC/B;QACF;QAEA,IAAIrB,MAAMsB,SAAS,IAAIrB,QAAQc,OAAOG,GAAG,CAACK,OAAO,GAAGtB;QAEpD,MAAMuB,iBAAiB7B,QAAQ8B,YAAY,CAACC,GAAG,CAAC,CAAC,EAAE9B,cAAc,QAAQ,EAAEe,UAAU,CAAC;QAEtF,MAAMgB,UAAUhC,QAAQiC,MAAM,CAACJ,eAAe,CAACK,KAAK;QAEpD,+CAA+C;QAC/C,sCAAsC;QACtC,4CAA4C;QAC5C,6CAA6C;QAC7C,+DAA+D;QAC/D,IAAIF,SAAS;YACXZ,OAAOG,GAAG,CAACW,KAAK,GAAGpB,SAASqB,EAAE;YAC9B,OAAOrB,SAASqB,EAAE;QACpB;QAEArC,eAAe;YACbE;YACAqB,QAAQD,OAAOC,MAAM;YACrBpB;YACAC;YACAC;YACAiC,cAAc;YACdhC,MAAMU;YACNuB,aAAa;YACbC,QAAQrB,aAAaqB,MAAM;YAC3BhB,SAASF,OAAOE,OAAO;YACvBf;YACAgC,iBAAiBV;YACjBrB,MAAM,CAAC,EAAEA,QAAQ,GAAG,EAAEH,MAAMqB,IAAI,CAAC,CAAC,EAAEX,EAAE,CAAC,CAAC;YACxCN;YACAC;YACAa,KAAKH,OAAOG,GAAG;YACfZ;YACAC;QACF;QAEAV,MAAM,CAACc,UAAU,CAACwB,IAAI,CAACpB;IACzB;AACF,EAAC"}
|
@@ -18,7 +18,7 @@ export const traverseFields = ({ adapter, arrays, baseTableName, blocks, blocksT
|
|
18
18
|
fieldData = data[field.name];
|
19
19
|
}
|
20
20
|
if (field.type === 'array') {
|
21
|
-
const arrayTableName = `${parentTableName}_${columnName}
|
21
|
+
const arrayTableName = adapter.tableNameMap.get(`${parentTableName}_${columnName}`);
|
22
22
|
if (!arrays[arrayTableName]) arrays[arrayTableName] = [];
|
23
23
|
if (field.localized) {
|
24
24
|
if (typeof data[field.name] === 'object' && data[field.name] !== null) {
|
@@ -360,7 +360,7 @@ export const traverseFields = ({ adapter, arrays, baseTableName, blocks, blocksT
|
|
360
360
|
return;
|
361
361
|
}
|
362
362
|
if (field.type === 'select' && field.hasMany) {
|
363
|
-
const selectTableName = `${parentTableName}_${columnName}
|
363
|
+
const selectTableName = adapter.tableNameMap.get(`${parentTableName}_${columnName}`);
|
364
364
|
if (!selects[selectTableName]) selects[selectTableName] = [];
|
365
365
|
if (field.localized) {
|
366
366
|
if (typeof data[field.name] === 'object' && data[field.name] !== null) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/transform/write/traverseFields.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Field } from 'payload/types'\n\nimport { fieldAffectsData } from 'payload/types'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { ArrayRowToInsert, BlockRowToInsert, RelationshipToDelete } from './types.js'\n\nimport { isArrayOfRows } from '../../utilities/isArrayOfRows.js'\nimport { transformArray } from './array.js'\nimport { transformBlocks } from './blocks.js'\nimport { transformNumbers } from './numbers.js'\nimport { transformRelationship } from './relationships.js'\nimport { transformSelects } from './selects.js'\nimport { transformTexts } from './texts.js'\n\ntype Args = {\n adapter: PostgresAdapter\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }\n /**\n * This is the name of the base table\n */\n baseTableName: string\n blocks: {\n [blockType: string]: BlockRowToInsert[]\n }\n blocksToDelete: Set<string>\n /**\n * A snake-case field prefix, representing prior fields\n * Ex: my_group_my_named_tab_\n */\n columnPrefix: string\n data: Record<string, unknown>\n existingLocales?: Record<string, unknown>[]\n /**\n * A prefix that will retain camel-case formatting, representing prior fields\n * Ex: myGroup_myNamedTab_\n */\n fieldPrefix: string\n fields: Field[]\n forcedLocale?: string\n locales: {\n [locale: string]: Record<string, unknown>\n }\n numbers: Record<string, unknown>[]\n /**\n * This is the name of the parent table\n */\n parentTableName: string\n path: string\n relationships: Record<string, unknown>[]\n relationshipsToDelete: RelationshipToDelete[]\n row: Record<string, unknown>\n selects: {\n [tableName: string]: Record<string, unknown>[]\n }\n texts: Record<string, unknown>[]\n}\n\nexport const traverseFields = ({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix,\n data,\n existingLocales,\n fieldPrefix,\n fields,\n forcedLocale,\n locales,\n numbers,\n parentTableName,\n path,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n}: Args) => {\n fields.forEach((field) => {\n let columnName = ''\n let fieldName = ''\n let fieldData: unknown\n\n if (fieldAffectsData(field)) {\n columnName = `${columnPrefix || ''}${toSnakeCase(field.name)}`\n fieldName = `${fieldPrefix || ''}${field.name}`\n fieldData = data[field.name]\n }\n\n if (field.type === 'array') {\n const arrayTableName = `${parentTableName}_${columnName}`\n\n if (!arrays[arrayTableName]) arrays[arrayTableName] = []\n\n if (field.localized) {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n const newRows = transformArray({\n adapter,\n arrayTableName,\n baseTableName,\n blocks,\n blocksToDelete,\n data: localeData,\n field,\n locale: localeKey,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n })\n\n arrays[arrayTableName] = arrays[arrayTableName].concat(newRows)\n }\n })\n }\n } else {\n const newRows = transformArray({\n adapter,\n arrayTableName,\n baseTableName,\n blocks,\n blocksToDelete,\n data: data[field.name],\n field,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n })\n\n arrays[arrayTableName] = arrays[arrayTableName].concat(newRows)\n }\n\n return\n }\n\n if (field.type === 'blocks') {\n field.blocks.forEach(({ slug }) => {\n blocksToDelete.add(toSnakeCase(slug))\n })\n\n if (field.localized) {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n transformBlocks({\n adapter,\n baseTableName,\n blocks,\n blocksToDelete,\n data: localeData,\n field,\n locale: localeKey,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n })\n }\n })\n }\n } else if (isArrayOfRows(fieldData)) {\n transformBlocks({\n adapter,\n baseTableName,\n blocks,\n blocksToDelete,\n data: fieldData,\n field,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n })\n }\n\n return\n }\n\n if (field.type === 'group') {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n if (field.localized) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnName}_`,\n data: localeData as Record<string, unknown>,\n existingLocales,\n fieldPrefix: `${fieldName}_`,\n fields: field.fields,\n forcedLocale: localeKey,\n locales,\n numbers,\n parentTableName,\n path: `${path || ''}${field.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n })\n } else {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnName}_`,\n data: data[field.name] as Record<string, unknown>,\n existingLocales,\n fieldPrefix: `${fieldName}_`,\n fields: field.fields,\n locales,\n numbers,\n parentTableName,\n path: `${path || ''}${field.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n }\n }\n\n return\n }\n\n if (field.type === 'tabs') {\n field.tabs.forEach((tab) => {\n if ('name' in tab) {\n if (typeof data[tab.name] === 'object' && data[tab.name] !== null) {\n if (tab.localized) {\n Object.entries(data[tab.name]).forEach(([localeKey, localeData]) => {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnPrefix || ''}${toSnakeCase(tab.name)}_`,\n data: localeData as Record<string, unknown>,\n existingLocales,\n fieldPrefix: `${fieldPrefix || ''}${tab.name}_`,\n fields: tab.fields,\n forcedLocale: localeKey,\n locales,\n numbers,\n parentTableName,\n path: `${path || ''}${tab.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n })\n } else {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnPrefix || ''}${toSnakeCase(tab.name)}_`,\n data: data[tab.name] as Record<string, unknown>,\n existingLocales,\n fieldPrefix: `${fieldPrefix || ''}${tab.name}_`,\n fields: tab.fields,\n locales,\n numbers,\n parentTableName,\n path: `${path || ''}${tab.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n }\n }\n } else {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix,\n data,\n existingLocales,\n fieldPrefix,\n fields: tab.fields,\n locales,\n numbers,\n parentTableName,\n path,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n }\n })\n }\n\n if (field.type === 'row' || field.type === 'collapsible') {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix,\n data,\n existingLocales,\n fieldPrefix,\n fields: field.fields,\n locales,\n numbers,\n parentTableName,\n path,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n const relationshipPath = `${path || ''}${field.name}`\n\n if (field.localized) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (localeData === null) {\n relationshipsToDelete.push({\n locale: localeKey,\n path: relationshipPath,\n })\n return\n }\n\n transformRelationship({\n baseRow: {\n locale: localeKey,\n path: relationshipPath,\n },\n data: localeData,\n field,\n relationships,\n })\n })\n }\n } else {\n if (fieldData === null || (Array.isArray(fieldData) && fieldData.length === 0)) {\n relationshipsToDelete.push({ path: relationshipPath })\n return\n }\n\n transformRelationship({\n baseRow: {\n path: relationshipPath,\n },\n data: fieldData,\n field,\n relationships,\n })\n }\n\n return\n }\n\n if (field.type === 'text' && field.hasMany) {\n const textPath = `${path || ''}${field.name}`\n\n if (field.localized) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n transformTexts({\n baseRow: {\n locale: localeKey,\n path: textPath,\n },\n data: localeData,\n texts,\n })\n }\n })\n }\n } else if (Array.isArray(fieldData)) {\n transformTexts({\n baseRow: {\n path: textPath,\n },\n data: fieldData,\n texts,\n })\n }\n\n return\n }\n\n if (field.type === 'number' && field.hasMany) {\n const numberPath = `${path || ''}${field.name}`\n\n if (field.localized) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n transformNumbers({\n baseRow: {\n locale: localeKey,\n path: numberPath,\n },\n data: localeData,\n numbers,\n })\n }\n })\n }\n } else if (Array.isArray(fieldData)) {\n transformNumbers({\n baseRow: {\n path: numberPath,\n },\n data: fieldData,\n numbers,\n })\n }\n\n return\n }\n\n if (field.type === 'select' && field.hasMany) {\n const selectTableName = `${parentTableName}_${columnName}`\n if (!selects[selectTableName]) selects[selectTableName] = []\n\n if (field.localized) {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n const newRows = transformSelects({\n id: data._uuid || data.id,\n data: localeData,\n locale: localeKey,\n })\n\n selects[selectTableName] = selects[selectTableName].concat(newRows)\n }\n })\n }\n } else if (Array.isArray(data[field.name])) {\n const newRows = transformSelects({\n id: data._uuid || data.id,\n data: data[field.name],\n })\n\n selects[selectTableName] = selects[selectTableName].concat(newRows)\n }\n\n return\n }\n\n if (fieldAffectsData(field)) {\n const valuesToTransform: { localeKey?: string; ref: unknown; value: unknown }[] = []\n\n if (field.localized) {\n if (typeof fieldData === 'object' && fieldData !== null) {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (!locales[localeKey]) locales[localeKey] = {}\n\n valuesToTransform.push({\n localeKey,\n ref: locales,\n value: localeData,\n })\n })\n }\n } else {\n let ref = row\n\n if (forcedLocale) {\n if (!locales[forcedLocale]) locales[forcedLocale] = {}\n ref = locales[forcedLocale]\n }\n\n valuesToTransform.push({ ref, value: fieldData })\n }\n\n valuesToTransform.forEach(({ localeKey, ref, value }) => {\n if (typeof value !== 'undefined') {\n let formattedValue = value\n\n if (field.type === 'date' && field.name === 'updatedAt') {\n formattedValue = new Date().toISOString()\n }\n\n if (localeKey) {\n ref[localeKey][fieldName] = formattedValue\n } else {\n ref[fieldName] = formattedValue\n }\n }\n })\n }\n })\n}\n"],"names":["fieldAffectsData","toSnakeCase","isArrayOfRows","transformArray","transformBlocks","transformNumbers","transformRelationship","transformSelects","transformTexts","traverseFields","adapter","arrays","baseTableName","blocks","blocksToDelete","columnPrefix","data","existingLocales","fieldPrefix","fields","forcedLocale","locales","numbers","parentTableName","path","relationships","relationshipsToDelete","row","selects","texts","forEach","field","columnName","fieldName","fieldData","name","type","arrayTableName","localized","Object","entries","localeKey","localeData","Array","isArray","newRows","locale","concat","slug","add","tabs","tab","relationshipPath","push","baseRow","length","hasMany","textPath","numberPath","selectTableName","id","_uuid","valuesToTransform","ref","value","formattedValue","Date","toISOString"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAGpC,SAASA,gBAAgB,QAAQ,gBAAe;AAChD,OAAOC,iBAAiB,gBAAe;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AM;oBACvDK,OAAOC,OAAO,CAACN,WAAWJ,OAAO,CAAC,CAAC,CAACW,WAAWC,WAAW;wBACxD,IAAI,CAACrB,OAAO,CAACoB,UAAU,EAAEpB,OAAO,CAACoB,UAAU,GAAG,CAAC;wBAE/CqB,kBAAkBT,IAAI,CAAC;4BACrBZ;4BACAsB,KAAK1C;4BACL2C,OAAOtB;wBACT;oBACF;gBACF;YACF,OAAO;gBACL,IAAIqB,MAAMpC;gBAEV,IAAIP,cAAc;oBAChB,IAAI,CAACC,OAAO,CAACD,aAAa,EAAEC,OAAO,CAACD,aAAa,GAAG,CAAC;oBACrD2C,MAAM1C,OAAO,CAACD,aAAa;gBAC7B;gBAEA0C,kBAAkBT,IAAI,CAAC;oBAAEU;oBAAKC,OAAO9B;gBAAU;YACjD;YAEA4B,kBAAkBhC,OAAO,CAAC,CAAC,EAAEW,SAAS,EAAEsB,GAAG,EAAEC,KAAK,EAAE;gBAClD,IAAI,OAAOA,UAAU,aAAa;oBAChC,IAAIC,iBAAiBD;oBAErB,IAAIjC,MAAMK,IAAI,KAAK,UAAUL,MAAMI,IAAI,KAAK,aAAa;wBACvD8B,iBAAiB,IAAIC,OAAOC,WAAW;oBACzC;oBAEA,IAAI1B,WAAW;wBACbsB,GAAG,CAACtB,UAAU,CAACR,UAAU,GAAGgC;oBAC9B,OAAO;wBACLF,GAAG,CAAC9B,UAAU,GAAGgC;oBACnB;gBACF;YACF;QACF;IACF;AACF,EAAC"}
|
1
|
+
{"version":3,"sources":["../../../src/transform/write/traverseFields.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Field } from 'payload/types'\n\nimport { fieldAffectsData } from 'payload/types'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { ArrayRowToInsert, BlockRowToInsert, RelationshipToDelete } from './types.js'\n\nimport { isArrayOfRows } from '../../utilities/isArrayOfRows.js'\nimport { transformArray } from './array.js'\nimport { transformBlocks } from './blocks.js'\nimport { transformNumbers } from './numbers.js'\nimport { transformRelationship } from './relationships.js'\nimport { transformSelects } from './selects.js'\nimport { transformTexts } from './texts.js'\n\ntype Args = {\n adapter: PostgresAdapter\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }\n /**\n * This is the name of the base table\n */\n baseTableName: string\n blocks: {\n [blockType: string]: BlockRowToInsert[]\n }\n blocksToDelete: Set<string>\n /**\n * A snake-case field prefix, representing prior fields\n * Ex: my_group_my_named_tab_\n */\n columnPrefix: string\n data: Record<string, unknown>\n existingLocales?: Record<string, unknown>[]\n /**\n * A prefix that will retain camel-case formatting, representing prior fields\n * Ex: myGroup_myNamedTab_\n */\n fieldPrefix: string\n fields: Field[]\n forcedLocale?: string\n locales: {\n [locale: string]: Record<string, unknown>\n }\n numbers: Record<string, unknown>[]\n /**\n * This is the name of the parent table\n */\n parentTableName: string\n path: string\n relationships: Record<string, unknown>[]\n relationshipsToDelete: RelationshipToDelete[]\n row: Record<string, unknown>\n selects: {\n [tableName: string]: Record<string, unknown>[]\n }\n texts: Record<string, unknown>[]\n}\n\nexport const traverseFields = ({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix,\n data,\n existingLocales,\n fieldPrefix,\n fields,\n forcedLocale,\n locales,\n numbers,\n parentTableName,\n path,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n}: Args) => {\n fields.forEach((field) => {\n let columnName = ''\n let fieldName = ''\n let fieldData: unknown\n\n if (fieldAffectsData(field)) {\n columnName = `${columnPrefix || ''}${toSnakeCase(field.name)}`\n fieldName = `${fieldPrefix || ''}${field.name}`\n fieldData = data[field.name]\n }\n\n if (field.type === 'array') {\n const arrayTableName = adapter.tableNameMap.get(`${parentTableName}_${columnName}`)\n\n if (!arrays[arrayTableName]) arrays[arrayTableName] = []\n\n if (field.localized) {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n const newRows = transformArray({\n adapter,\n arrayTableName,\n baseTableName,\n blocks,\n blocksToDelete,\n data: localeData,\n field,\n locale: localeKey,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n })\n\n arrays[arrayTableName] = arrays[arrayTableName].concat(newRows)\n }\n })\n }\n } else {\n const newRows = transformArray({\n adapter,\n arrayTableName,\n baseTableName,\n blocks,\n blocksToDelete,\n data: data[field.name],\n field,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n })\n\n arrays[arrayTableName] = arrays[arrayTableName].concat(newRows)\n }\n\n return\n }\n\n if (field.type === 'blocks') {\n field.blocks.forEach(({ slug }) => {\n blocksToDelete.add(toSnakeCase(slug))\n })\n\n if (field.localized) {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n transformBlocks({\n adapter,\n baseTableName,\n blocks,\n blocksToDelete,\n data: localeData,\n field,\n locale: localeKey,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n })\n }\n })\n }\n } else if (isArrayOfRows(fieldData)) {\n transformBlocks({\n adapter,\n baseTableName,\n blocks,\n blocksToDelete,\n data: fieldData,\n field,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n })\n }\n\n return\n }\n\n if (field.type === 'group') {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n if (field.localized) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnName}_`,\n data: localeData as Record<string, unknown>,\n existingLocales,\n fieldPrefix: `${fieldName}_`,\n fields: field.fields,\n forcedLocale: localeKey,\n locales,\n numbers,\n parentTableName,\n path: `${path || ''}${field.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n })\n } else {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnName}_`,\n data: data[field.name] as Record<string, unknown>,\n existingLocales,\n fieldPrefix: `${fieldName}_`,\n fields: field.fields,\n locales,\n numbers,\n parentTableName,\n path: `${path || ''}${field.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n }\n }\n\n return\n }\n\n if (field.type === 'tabs') {\n field.tabs.forEach((tab) => {\n if ('name' in tab) {\n if (typeof data[tab.name] === 'object' && data[tab.name] !== null) {\n if (tab.localized) {\n Object.entries(data[tab.name]).forEach(([localeKey, localeData]) => {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnPrefix || ''}${toSnakeCase(tab.name)}_`,\n data: localeData as Record<string, unknown>,\n existingLocales,\n fieldPrefix: `${fieldPrefix || ''}${tab.name}_`,\n fields: tab.fields,\n forcedLocale: localeKey,\n locales,\n numbers,\n parentTableName,\n path: `${path || ''}${tab.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n })\n } else {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnPrefix || ''}${toSnakeCase(tab.name)}_`,\n data: data[tab.name] as Record<string, unknown>,\n existingLocales,\n fieldPrefix: `${fieldPrefix || ''}${tab.name}_`,\n fields: tab.fields,\n locales,\n numbers,\n parentTableName,\n path: `${path || ''}${tab.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n }\n }\n } else {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix,\n data,\n existingLocales,\n fieldPrefix,\n fields: tab.fields,\n locales,\n numbers,\n parentTableName,\n path,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n }\n })\n }\n\n if (field.type === 'row' || field.type === 'collapsible') {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix,\n data,\n existingLocales,\n fieldPrefix,\n fields: field.fields,\n locales,\n numbers,\n parentTableName,\n path,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n const relationshipPath = `${path || ''}${field.name}`\n\n if (field.localized) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (localeData === null) {\n relationshipsToDelete.push({\n locale: localeKey,\n path: relationshipPath,\n })\n return\n }\n\n transformRelationship({\n baseRow: {\n locale: localeKey,\n path: relationshipPath,\n },\n data: localeData,\n field,\n relationships,\n })\n })\n }\n } else {\n if (fieldData === null || (Array.isArray(fieldData) && fieldData.length === 0)) {\n relationshipsToDelete.push({ path: relationshipPath })\n return\n }\n\n transformRelationship({\n baseRow: {\n path: relationshipPath,\n },\n data: fieldData,\n field,\n relationships,\n })\n }\n\n return\n }\n\n if (field.type === 'text' && field.hasMany) {\n const textPath = `${path || ''}${field.name}`\n\n if (field.localized) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n transformTexts({\n baseRow: {\n locale: localeKey,\n path: textPath,\n },\n data: localeData,\n texts,\n })\n }\n })\n }\n } else if (Array.isArray(fieldData)) {\n transformTexts({\n baseRow: {\n path: textPath,\n },\n data: fieldData,\n texts,\n })\n }\n\n return\n }\n\n if (field.type === 'number' && field.hasMany) {\n const numberPath = `${path || ''}${field.name}`\n\n if (field.localized) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n transformNumbers({\n baseRow: {\n locale: localeKey,\n path: numberPath,\n },\n data: localeData,\n numbers,\n })\n }\n })\n }\n } else if (Array.isArray(fieldData)) {\n transformNumbers({\n baseRow: {\n path: numberPath,\n },\n data: fieldData,\n numbers,\n })\n }\n\n return\n }\n\n if (field.type === 'select' && field.hasMany) {\n const selectTableName = adapter.tableNameMap.get(`${parentTableName}_${columnName}`)\n if (!selects[selectTableName]) selects[selectTableName] = []\n\n if (field.localized) {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n const newRows = transformSelects({\n id: data._uuid || data.id,\n data: localeData,\n locale: localeKey,\n })\n\n selects[selectTableName] = selects[selectTableName].concat(newRows)\n }\n })\n }\n } else if (Array.isArray(data[field.name])) {\n const newRows = transformSelects({\n id: data._uuid || data.id,\n data: data[field.name],\n })\n\n selects[selectTableName] = selects[selectTableName].concat(newRows)\n }\n\n return\n }\n\n if (fieldAffectsData(field)) {\n const valuesToTransform: { localeKey?: string; ref: unknown; value: unknown }[] = []\n\n if (field.localized) {\n if (typeof fieldData === 'object' && fieldData !== null) {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (!locales[localeKey]) locales[localeKey] = {}\n\n valuesToTransform.push({\n localeKey,\n ref: locales,\n value: localeData,\n })\n })\n }\n } else {\n let ref = row\n\n if (forcedLocale) {\n if (!locales[forcedLocale]) locales[forcedLocale] = {}\n ref = locales[forcedLocale]\n }\n\n valuesToTransform.push({ ref, value: fieldData })\n }\n\n valuesToTransform.forEach(({ localeKey, ref, value }) => {\n if (typeof value !== 'undefined') {\n let formattedValue = value\n\n if (field.type === 'date' && field.name === 'updatedAt') {\n formattedValue = new Date().toISOString()\n }\n\n if (localeKey) {\n ref[localeKey][fieldName] = formattedValue\n } else {\n ref[fieldName] = formattedValue\n }\n }\n })\n }\n })\n}\n"],"names":["fieldAffectsData","toSnakeCase","isArrayOfRows","transformArray","transformBlocks","transformNumbers","transformRelationship","transformSelects","transformTexts","traverseFields","adapter","arrays","baseTableName","blocks","blocksToDelete","columnPrefix","data","existingLocales","fieldPrefix","fields","forcedLocale","locales","numbers","parentTableName","path","relationships","relationshipsToDelete","row","selects","texts","forEach","field","columnName","fieldName","fieldData","name","type","arrayTableName","tableNameMap","get","localized","Object","entries","localeKey","localeData","Array","isArray","newRows","locale","concat","slug","add","tabs","tab","relationshipPath","push","baseRow","length","hasMany","textPath","numberPath","selectTableName","id","_uuid","valuesToTransform","ref","value","formattedValue","Date","toISOString"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAGpC,SAASA,gBAAgB,QAAQ,gBAAe;AAChD,OAAOC,iBAAiB,gBAAe;AAKvC,SAASC,aAAa,QAAQ,mCAAkC;AAChE,SAASC,cAAc,QAAQ,aAAY;AAC3C,SAASC,eAAe,QAAQ,cAAa;AAC7C,SAASC,gBAAgB,QAAQ,eAAc;AAC/C,SAASC,qBAAqB,QAAQ,qBAAoB;AAC1D,SAASC,gBAAgB,QAAQ,eAAc;AAC/C,SAASC,cAAc,QAAQ,aAAY;AA+C3C,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,OAAO,EACPC,MAAM,EACNC,aAAa,EACbC,MAAM,EACNC,cAAc,EACdC,YAAY,EACZC,IAAI,EACJC,eAAe,EACfC,WAAW,EACXC,MAAM,EACNC,YAAY,EACZC,OAAO,EACPC,OAAO,EACPC,eAAe,EACfC,IAAI,EACJC,aAAa,EACbC,qBAAqB,E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Aa;gBAC7B;gBAEA4C,kBAAkBT,IAAI,CAAC;oBAAEU;oBAAKC,OAAOhC;gBAAU;YACjD;YAEA8B,kBAAkBlC,OAAO,CAAC,CAAC,EAAEa,SAAS,EAAEsB,GAAG,EAAEC,KAAK,EAAE;gBAClD,IAAI,OAAOA,UAAU,aAAa;oBAChC,IAAIC,iBAAiBD;oBAErB,IAAInC,MAAMK,IAAI,KAAK,UAAUL,MAAMI,IAAI,KAAK,aAAa;wBACvDgC,iBAAiB,IAAIC,OAAOC,WAAW;oBACzC;oBAEA,IAAI1B,WAAW;wBACbsB,GAAG,CAACtB,UAAU,CAACV,UAAU,GAAGkC;oBAC9B,OAAO;wBACLF,GAAG,CAAChC,UAAU,GAAGkC;oBACnB;gBACF;YACF;QACF;IACF;AACF,EAAC"}
|
package/dist/types.d.ts
CHANGED
@@ -4,7 +4,7 @@ import type { PgColumn, PgEnum, PgSchema, PgTableWithColumns, PgTransaction } fr
|
|
4
4
|
import type { PgTableFn } from 'drizzle-orm/pg-core/table';
|
5
5
|
import type { Payload } from 'payload';
|
6
6
|
import type { BaseDatabaseAdapter } from 'payload/database';
|
7
|
-
import type {
|
7
|
+
import type { PayloadRequestWithData } from 'payload/types';
|
8
8
|
import type { Pool, PoolConfig } from 'pg';
|
9
9
|
export type DrizzleDB = NodePgDatabase<Record<string, unknown>>;
|
10
10
|
export type Args = {
|
@@ -32,10 +32,6 @@ export type GenericEnum = PgEnum<[string, ...string[]]>;
|
|
32
32
|
export type GenericRelation = Relations<string, Record<string, Relation<string>>>;
|
33
33
|
export type DrizzleTransaction = PgTransaction<NodePgQueryResultHKT, Record<string, unknown>, ExtractTablesWithRelations<Record<string, unknown>>>;
|
34
34
|
export type PostgresAdapter = BaseDatabaseAdapter & {
|
35
|
-
/**
|
36
|
-
* Used internally to map the block name to the table name
|
37
|
-
*/
|
38
|
-
blockTableNames: Record<string, string>;
|
39
35
|
drizzle: DrizzleDB;
|
40
36
|
enums: Record<string, GenericEnum>;
|
41
37
|
/**
|
@@ -63,6 +59,7 @@ export type PostgresAdapter = BaseDatabaseAdapter & {
|
|
63
59
|
resolve: () => Promise<void>;
|
64
60
|
};
|
65
61
|
};
|
62
|
+
tableNameMap: Map<string, string>;
|
66
63
|
tables: Record<string, GenericTable | PgTableWithColumns<any>>;
|
67
64
|
versionsSuffix?: string;
|
68
65
|
};
|
@@ -72,11 +69,11 @@ export type PostgresAdapterResult = (args: {
|
|
72
69
|
}) => PostgresAdapter;
|
73
70
|
export type MigrateUpArgs = {
|
74
71
|
payload: Payload;
|
75
|
-
req?: Partial<
|
72
|
+
req?: Partial<PayloadRequestWithData>;
|
76
73
|
};
|
77
74
|
export type MigrateDownArgs = {
|
78
75
|
payload: Payload;
|
79
|
-
req?: Partial<
|
76
|
+
req?: Partial<PayloadRequestWithData>;
|
80
77
|
};
|
81
78
|
declare module 'payload' {
|
82
79
|
interface DatabaseAdapter extends Omit<Args, 'migrationDir' | 'pool'>, BaseDatabaseAdapter {
|
package/dist/types.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,0BAA0B,EAC1B,QAAQ,EACR,SAAS,EACV,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AACrF,OAAO,KAAK,EACV,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,kBAAkB,EAClB,aAAa,EACd,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAC3D,OAAO,KAAK,EAAE,
|
1
|
+
{"version":3,"file":"types.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