chore(eslint): lint entire codebase including db packages (#8042)
This commit is contained in:
@@ -25,3 +25,6 @@ fb7d1be2f3325d076b7c967b1730afcef37922c2
|
||||
|
||||
# Upgrade to typescript-eslint v8, then prettier & lint everywhere
|
||||
86fdad0bb8ab27810599c8a32f3d8cba1341e1df
|
||||
|
||||
# Prettier and lint remaining db packages
|
||||
7fd736ea5b2e9fc4ef936e9dc9e5e3d722f6d8bf
|
||||
|
||||
@@ -29,7 +29,9 @@ export const connect: Connect = async function connect(
|
||||
useFacet: undefined,
|
||||
}
|
||||
|
||||
if (hotReload) connectionOptions.autoIndex = false
|
||||
if (hotReload) {
|
||||
connectionOptions.autoIndex = false
|
||||
}
|
||||
|
||||
try {
|
||||
this.connection = (await mongoose.connect(urlToConnect, connectionOptions)).connection
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { CollationOptions, TransactionOptions } from 'mongodb'
|
||||
import type { MongoMemoryReplSet } from 'mongodb-memory-server'
|
||||
import type { ClientSession, ConnectOptions, Connection } from 'mongoose'
|
||||
import type { ClientSession, Connection, ConnectOptions } from 'mongoose'
|
||||
import type { BaseDatabaseAdapter, DatabaseAdapterObj, Payload } from 'payload'
|
||||
|
||||
import fs from 'fs'
|
||||
@@ -83,7 +83,7 @@ export interface Args {
|
||||
name: string
|
||||
up: (args: MigrateUpArgs) => Promise<void>
|
||||
}[]
|
||||
transactionOptions?: TransactionOptions | false
|
||||
transactionOptions?: false | TransactionOptions
|
||||
/** The URL to connect to MongoDB or false to start payload and prevent connecting */
|
||||
url: false | string
|
||||
}
|
||||
@@ -150,8 +150,8 @@ export function mongooseAdapter({
|
||||
// Mongoose-specific
|
||||
autoPluralization,
|
||||
collections: {},
|
||||
connectOptions: connectOptions || {},
|
||||
connection: undefined,
|
||||
connectOptions: connectOptions || {},
|
||||
count,
|
||||
disableIndexHints,
|
||||
globals: undefined,
|
||||
@@ -221,7 +221,9 @@ function findMigrationDir(migrationDir?: string): string {
|
||||
const relativeMigrations = path.resolve(cwd, 'migrations')
|
||||
|
||||
// Use arg if provided
|
||||
if (migrationDir) return migrationDir
|
||||
if (migrationDir) {
|
||||
return migrationDir
|
||||
}
|
||||
|
||||
// Check other common locations
|
||||
if (fs.existsSync(srcDir)) {
|
||||
|
||||
@@ -24,8 +24,8 @@ import type {
|
||||
SelectField,
|
||||
Tab,
|
||||
TabsField,
|
||||
TextField,
|
||||
TextareaField,
|
||||
TextField,
|
||||
UploadField,
|
||||
} from 'payload'
|
||||
|
||||
@@ -92,7 +92,7 @@ const formatBaseSchema = (field: FieldAffectingData, buildSchemaOptions: BuildSc
|
||||
const localizeSchema = (
|
||||
entity: NonPresentationalField | Tab,
|
||||
schema,
|
||||
localization: SanitizedLocalizationConfig | false,
|
||||
localization: false | SanitizedLocalizationConfig,
|
||||
) => {
|
||||
if (fieldIsLocalized(entity) && localization && Array.isArray(localization.locales)) {
|
||||
return {
|
||||
@@ -384,7 +384,9 @@ const fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {
|
||||
...formatBaseSchema(field, buildSchemaOptions),
|
||||
type: String,
|
||||
enum: field.options.map((option) => {
|
||||
if (typeof option === 'object') return option.value
|
||||
if (typeof option === 'object') {
|
||||
return option.value
|
||||
}
|
||||
return option
|
||||
}),
|
||||
}
|
||||
@@ -511,7 +513,9 @@ const fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {
|
||||
...formatBaseSchema(field, buildSchemaOptions),
|
||||
type: String,
|
||||
enum: field.options.map((option) => {
|
||||
if (typeof option === 'object') return option.value
|
||||
if (typeof option === 'object') {
|
||||
return option.value
|
||||
}
|
||||
return option
|
||||
}),
|
||||
}
|
||||
|
||||
@@ -48,7 +48,9 @@ export async function buildSearchParam({
|
||||
}): Promise<SearchParam> {
|
||||
// Replace GraphQL nested field double underscore formatting
|
||||
let sanitizedPath = incomingPath.replace(/__/g, '.')
|
||||
if (sanitizedPath === 'id') sanitizedPath = '_id'
|
||||
if (sanitizedPath === 'id') {
|
||||
sanitizedPath = '_id'
|
||||
}
|
||||
|
||||
let paths: PathToQuery[] = []
|
||||
|
||||
@@ -99,7 +101,9 @@ export async function buildSearchParam({
|
||||
val,
|
||||
})
|
||||
|
||||
if (rawQuery) return { value: rawQuery }
|
||||
if (rawQuery) {
|
||||
return { value: rawQuery }
|
||||
}
|
||||
|
||||
// If there are multiple collections to search through,
|
||||
// Recursively build up a list of query constraints
|
||||
@@ -190,7 +194,9 @@ export async function buildSearchParam({
|
||||
if (field.type === 'relationship' || field.type === 'upload') {
|
||||
let hasNumberIDRelation
|
||||
let multiIDCondition = '$or'
|
||||
if (operatorKey === '$ne') multiIDCondition = '$and'
|
||||
if (operatorKey === '$ne') {
|
||||
multiIDCondition = '$and'
|
||||
}
|
||||
|
||||
const result = {
|
||||
value: {
|
||||
@@ -215,10 +221,11 @@ export async function buildSearchParam({
|
||||
},
|
||||
)
|
||||
|
||||
if (hasNumberIDRelation)
|
||||
if (hasNumberIDRelation) {
|
||||
result.value[multiIDCondition].push({
|
||||
[path]: { [operatorKey]: parseFloat(formattedValue) },
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,9 @@ export async function parseParams({
|
||||
payload,
|
||||
where: condition,
|
||||
})
|
||||
if (builtConditions.length > 0) result[conditionOperator] = builtConditions
|
||||
if (builtConditions.length > 0) {
|
||||
result[conditionOperator] = builtConditions
|
||||
}
|
||||
} else {
|
||||
// It's a path - and there can be multiple comparisons on a single path.
|
||||
// For example - title like 'test' and title not equal to 'tester'
|
||||
|
||||
@@ -46,8 +46,12 @@ export const sanitizeQueryValue = ({
|
||||
|
||||
// Cast incoming values as proper searchable types
|
||||
if (field.type === 'checkbox' && typeof val === 'string') {
|
||||
if (val.toLowerCase() === 'true') formattedValue = true
|
||||
if (val.toLowerCase() === 'false') formattedValue = false
|
||||
if (val.toLowerCase() === 'true') {
|
||||
formattedValue = true
|
||||
}
|
||||
if (val.toLowerCase() === 'false') {
|
||||
formattedValue = false
|
||||
}
|
||||
}
|
||||
|
||||
if (['all', 'in', 'not_in'].includes(operator) && typeof formattedValue === 'string') {
|
||||
@@ -95,11 +99,14 @@ export const sanitizeQueryValue = ({
|
||||
if (operator === 'in' && Array.isArray(formattedValue)) {
|
||||
formattedValue = formattedValue.reduce((formattedValues, inVal) => {
|
||||
const newValues = [inVal]
|
||||
if (mongoose.Types.ObjectId.isValid(inVal))
|
||||
if (mongoose.Types.ObjectId.isValid(inVal)) {
|
||||
newValues.push(new mongoose.Types.ObjectId(inVal))
|
||||
}
|
||||
|
||||
const parsedNumber = parseFloat(inVal)
|
||||
if (!Number.isNaN(parsedNumber)) newValues.push(parsedNumber)
|
||||
if (!Number.isNaN(parsedNumber)) {
|
||||
newValues.push(parsedNumber)
|
||||
}
|
||||
|
||||
return [...formattedValues, ...newValues]
|
||||
}, [])
|
||||
@@ -129,8 +136,12 @@ export const sanitizeQueryValue = ({
|
||||
$geometry: { type: 'Point', coordinates: [parseFloat(lng), parseFloat(lat)] },
|
||||
}
|
||||
|
||||
if (maxDistance) formattedValue.$maxDistance = parseFloat(maxDistance)
|
||||
if (minDistance) formattedValue.$minDistance = parseFloat(minDistance)
|
||||
if (maxDistance) {
|
||||
formattedValue.$maxDistance = parseFloat(maxDistance)
|
||||
}
|
||||
if (minDistance) {
|
||||
formattedValue.$minDistance = parseFloat(minDistance)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import type { CommitTransaction } from 'payload'
|
||||
|
||||
export const commitTransaction: CommitTransaction = async function commitTransaction(id) {
|
||||
if (id instanceof Promise) return
|
||||
if (id instanceof Promise) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!this.sessions[id]?.inTransaction()) {
|
||||
return
|
||||
|
||||
@@ -20,8 +20,8 @@ import type {
|
||||
SanitizedConfig,
|
||||
SelectField,
|
||||
TabsField,
|
||||
TextField,
|
||||
TextareaField,
|
||||
TextField,
|
||||
UploadField,
|
||||
} from 'payload'
|
||||
|
||||
|
||||
@@ -35,7 +35,9 @@ export const getDBName = ({
|
||||
result = name ?? slug
|
||||
}
|
||||
|
||||
if (versions) result = `_${result}_versions`
|
||||
if (versions) {
|
||||
result = `_${result}_versions`
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -17,5 +17,7 @@ export async function withSession(
|
||||
transactionID = await req.transactionID
|
||||
}
|
||||
|
||||
if (req) return db.sessions[transactionID] ? { session: db.sessions[transactionID] } : {}
|
||||
if (req) {
|
||||
return db.sessions[transactionID] ? { session: db.sessions[transactionID] } : {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,9 @@ export const connect: Connect = async function connect(
|
||||
}
|
||||
} catch (err) {
|
||||
this.payload.logger.error(`Error: cannot connect to Postgres. Details: ${err.message}`, err)
|
||||
if (typeof this.rejectInitializing === 'function') this.rejectInitializing()
|
||||
if (typeof this.rejectInitializing === 'function') {
|
||||
this.rejectInitializing()
|
||||
}
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
@@ -90,7 +92,9 @@ export const connect: Connect = async function connect(
|
||||
await pushDevSchema(this as unknown as DrizzleAdapter)
|
||||
}
|
||||
|
||||
if (typeof this.resolveInitializing === 'function') this.resolveInitializing()
|
||||
if (typeof this.resolveInitializing === 'function') {
|
||||
this.resolveInitializing()
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV === 'production' && this.prodMigrations) {
|
||||
await this.migrate({ migrations: this.prodMigrations })
|
||||
|
||||
@@ -193,7 +193,9 @@ export const traverseFields = ({ doc, fields, locale, path, rows }: Args) => {
|
||||
const matchedRelationship = rows.find((row) => {
|
||||
const matchesPath = row.path === relationshipPath
|
||||
|
||||
if (locale) return matchesPath && locale === row.locale
|
||||
if (locale) {
|
||||
return matchesPath && locale === row.locale
|
||||
}
|
||||
|
||||
return row.path === relationshipPath
|
||||
})
|
||||
|
||||
@@ -35,7 +35,9 @@ export const migrateRelationships = async ({
|
||||
req,
|
||||
tableName,
|
||||
}: Args) => {
|
||||
if (pathsToQuery.size === 0) return
|
||||
if (pathsToQuery.size === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
let offset = 0
|
||||
|
||||
@@ -54,7 +56,9 @@ export const migrateRelationships = async ({
|
||||
|
||||
paginationResult = await adapter.drizzle.execute(sql.raw(`${paginationStatement}`))
|
||||
|
||||
if (paginationResult.rows.length === 0) return
|
||||
if (paginationResult.rows.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
offset += 1
|
||||
|
||||
@@ -74,7 +78,9 @@ export const migrateRelationships = async ({
|
||||
const parentID = row.parent_id
|
||||
|
||||
if (typeof parentID === 'string' || typeof parentID === 'number') {
|
||||
if (!docsToResave[parentID]) docsToResave[parentID] = []
|
||||
if (!docsToResave[parentID]) {
|
||||
docsToResave[parentID] = []
|
||||
}
|
||||
docsToResave[parentID].push(row)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -28,7 +28,7 @@ export type Args = {
|
||||
* @experimental This only works when there are not other tables or enums of the same name in the database under a different schema. Awaiting fix from Drizzle.
|
||||
*/
|
||||
schemaName?: string
|
||||
transactionOptions?: PgTransactionConfig | false
|
||||
transactionOptions?: false | PgTransactionConfig
|
||||
versionsSuffix?: string
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,9 @@ export const connect: Connect = async function connect(
|
||||
}
|
||||
} catch (err) {
|
||||
this.payload.logger.error(`Error: cannot connect to SQLite. Details: ${err.message}`, err)
|
||||
if (typeof this.rejectInitializing === 'function') this.rejectInitializing()
|
||||
if (typeof this.rejectInitializing === 'function') {
|
||||
this.rejectInitializing()
|
||||
}
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
@@ -51,7 +53,9 @@ export const connect: Connect = async function connect(
|
||||
await pushDevSchema(this as unknown as DrizzleAdapter)
|
||||
}
|
||||
|
||||
if (typeof this.resolveInitializing === 'function') this.resolveInitializing()
|
||||
if (typeof this.resolveInitializing === 'function') {
|
||||
this.resolveInitializing()
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV === 'production' && this.prodMigrations) {
|
||||
await this.migrate({ migrations: this.prodMigrations })
|
||||
|
||||
@@ -51,8 +51,8 @@ type Args = {
|
||||
disableUnique: boolean
|
||||
fields: Field[]
|
||||
locales?: [string, ...string[]]
|
||||
rootRelationsToBuild?: RelationMap
|
||||
rootRelationships?: Set<string>
|
||||
rootRelationsToBuild?: RelationMap
|
||||
rootTableIDColType?: IDType
|
||||
rootTableName?: string
|
||||
tableName: string
|
||||
@@ -82,8 +82,8 @@ export const buildTable = ({
|
||||
disableUnique = false,
|
||||
fields,
|
||||
locales,
|
||||
rootRelationsToBuild,
|
||||
rootRelationships,
|
||||
rootRelationsToBuild,
|
||||
rootTableIDColType,
|
||||
rootTableName: incomingRootTableName,
|
||||
tableName,
|
||||
@@ -131,8 +131,8 @@ export const buildTable = ({
|
||||
localesIndexes,
|
||||
newTableName: tableName,
|
||||
parentTableName: tableName,
|
||||
relationsToBuild,
|
||||
relationships,
|
||||
relationsToBuild,
|
||||
rootRelationsToBuild: rootRelationsToBuild || relationsToBuild,
|
||||
rootTableIDColType: rootTableIDColType || idColType,
|
||||
rootTableName,
|
||||
@@ -375,8 +375,12 @@ export const buildTable = ({
|
||||
const relatedCollectionCustomIDType =
|
||||
adapter.payload.collections[relationshipConfig.slug]?.customIDType
|
||||
|
||||
if (relatedCollectionCustomIDType === 'number') colType = 'numeric'
|
||||
if (relatedCollectionCustomIDType === 'text') colType = 'text'
|
||||
if (relatedCollectionCustomIDType === 'number') {
|
||||
colType = 'numeric'
|
||||
}
|
||||
if (relatedCollectionCustomIDType === 'text') {
|
||||
colType = 'text'
|
||||
}
|
||||
|
||||
relationshipColumns[`${relationTo}ID`] = getIDColumn({
|
||||
name: `${formattedRelationTo}_id`,
|
||||
|
||||
@@ -20,8 +20,9 @@ export const createIndex = ({ name, columnName, tableName, unique }: CreateIndex
|
||||
} else {
|
||||
columns = [table[name]]
|
||||
}
|
||||
if (unique)
|
||||
if (unique) {
|
||||
return uniqueIndex(`${tableName}_${columnName}_idx`).on(columns[0], ...columns.slice(1))
|
||||
}
|
||||
return index(`${tableName}_${columnName}_idx`).on(columns[0], ...columns.slice(1))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,13 +9,13 @@ import {
|
||||
} from '@payloadcms/drizzle'
|
||||
import { relations } from 'drizzle-orm'
|
||||
import {
|
||||
SQLiteIntegerBuilder,
|
||||
SQLiteNumericBuilder,
|
||||
SQLiteTextBuilder,
|
||||
foreignKey,
|
||||
index,
|
||||
integer,
|
||||
numeric,
|
||||
SQLiteIntegerBuilder,
|
||||
SQLiteNumericBuilder,
|
||||
SQLiteTextBuilder,
|
||||
text,
|
||||
} from 'drizzle-orm/sqlite-core'
|
||||
import { InvalidConfiguration } from 'payload'
|
||||
@@ -46,8 +46,8 @@ type Args = {
|
||||
localesIndexes: Record<string, (cols: GenericColumns) => IndexBuilder>
|
||||
newTableName: string
|
||||
parentTableName: string
|
||||
relationsToBuild: RelationMap
|
||||
relationships: Set<string>
|
||||
relationsToBuild: RelationMap
|
||||
rootRelationsToBuild?: RelationMap
|
||||
rootTableIDColType: IDType
|
||||
rootTableName: string
|
||||
@@ -83,8 +83,8 @@ export const traverseFields = ({
|
||||
localesIndexes,
|
||||
newTableName,
|
||||
parentTableName,
|
||||
relationsToBuild,
|
||||
relationships,
|
||||
relationsToBuild,
|
||||
rootRelationsToBuild,
|
||||
rootTableIDColType,
|
||||
rootTableName,
|
||||
@@ -99,12 +99,20 @@ export const traverseFields = ({
|
||||
let hasLocalizedManyNumberField = false
|
||||
|
||||
let parentIDColType: IDType = 'integer'
|
||||
if (columns.id instanceof SQLiteIntegerBuilder) parentIDColType = 'integer'
|
||||
if (columns.id instanceof SQLiteNumericBuilder) parentIDColType = 'numeric'
|
||||
if (columns.id instanceof SQLiteTextBuilder) parentIDColType = 'text'
|
||||
if (columns.id instanceof SQLiteIntegerBuilder) {
|
||||
parentIDColType = 'integer'
|
||||
}
|
||||
if (columns.id instanceof SQLiteNumericBuilder) {
|
||||
parentIDColType = 'numeric'
|
||||
}
|
||||
if (columns.id instanceof SQLiteTextBuilder) {
|
||||
parentIDColType = 'text'
|
||||
}
|
||||
|
||||
fields.forEach((field) => {
|
||||
if ('name' in field && field.name === 'id') return
|
||||
if ('name' in field && field.name === 'id') {
|
||||
return
|
||||
}
|
||||
let columnName: string
|
||||
let fieldName: string
|
||||
|
||||
@@ -379,8 +387,8 @@ export const traverseFields = ({
|
||||
disableNotNull: disableNotNullFromHere,
|
||||
disableUnique,
|
||||
fields: disableUnique ? idToUUID(field.fields) : field.fields,
|
||||
rootRelationsToBuild,
|
||||
rootRelationships: relationships,
|
||||
rootRelationsToBuild,
|
||||
rootTableIDColType,
|
||||
rootTableName,
|
||||
tableName: arrayTableName,
|
||||
@@ -401,12 +409,14 @@ export const traverseFields = ({
|
||||
}
|
||||
|
||||
if (subHasManyTextField) {
|
||||
if (!hasManyTextField || subHasManyTextField === 'index')
|
||||
if (!hasManyTextField || subHasManyTextField === 'index') {
|
||||
hasManyTextField = subHasManyTextField
|
||||
}
|
||||
}
|
||||
if (subHasManyNumberField) {
|
||||
if (!hasManyNumberField || subHasManyNumberField === 'index')
|
||||
if (!hasManyNumberField || subHasManyNumberField === 'index') {
|
||||
hasManyNumberField = subHasManyNumberField
|
||||
}
|
||||
}
|
||||
|
||||
relationsToBuild.set(fieldName, {
|
||||
@@ -481,13 +491,13 @@ export const traverseFields = ({
|
||||
|
||||
const baseExtraConfig: BaseExtraConfig = {
|
||||
_orderIdx: (cols) => index(`${blockTableName}_order_idx`).on(cols._order),
|
||||
_parentIDIdx: (cols) => index(`${blockTableName}_parent_id_idx`).on(cols._parentID),
|
||||
_parentIdFk: (cols) =>
|
||||
foreignKey({
|
||||
name: `${blockTableName}_parent_id_fk`,
|
||||
columns: [cols._parentID],
|
||||
foreignColumns: [adapter.tables[rootTableName].id],
|
||||
}).onDelete('cascade'),
|
||||
_parentIDIdx: (cols) => index(`${blockTableName}_parent_id_idx`).on(cols._parentID),
|
||||
_pathIdx: (cols) => index(`${blockTableName}_path_idx`).on(cols._path),
|
||||
}
|
||||
|
||||
@@ -515,8 +525,8 @@ export const traverseFields = ({
|
||||
disableNotNull: disableNotNullFromHere,
|
||||
disableUnique,
|
||||
fields: disableUnique ? idToUUID(block.fields) : block.fields,
|
||||
rootRelationsToBuild,
|
||||
rootRelationships: relationships,
|
||||
rootRelationsToBuild,
|
||||
rootTableIDColType,
|
||||
rootTableName,
|
||||
tableName: blockTableName,
|
||||
@@ -537,13 +547,15 @@ export const traverseFields = ({
|
||||
}
|
||||
|
||||
if (subHasManyTextField) {
|
||||
if (!hasManyTextField || subHasManyTextField === 'index')
|
||||
if (!hasManyTextField || subHasManyTextField === 'index') {
|
||||
hasManyTextField = subHasManyTextField
|
||||
}
|
||||
}
|
||||
|
||||
if (subHasManyNumberField) {
|
||||
if (!hasManyNumberField || subHasManyNumberField === 'index')
|
||||
if (!hasManyNumberField || subHasManyNumberField === 'index') {
|
||||
hasManyNumberField = subHasManyNumberField
|
||||
}
|
||||
}
|
||||
|
||||
adapter.relations[`relations_${blockTableName}`] = relations(
|
||||
@@ -629,8 +641,8 @@ export const traverseFields = ({
|
||||
localesIndexes,
|
||||
newTableName,
|
||||
parentTableName,
|
||||
relationsToBuild,
|
||||
relationships,
|
||||
relationsToBuild,
|
||||
rootRelationsToBuild,
|
||||
rootTableIDColType,
|
||||
rootTableName,
|
||||
@@ -638,12 +650,24 @@ export const traverseFields = ({
|
||||
withinLocalizedArrayOrBlock,
|
||||
})
|
||||
|
||||
if (groupHasLocalizedField) hasLocalizedField = true
|
||||
if (groupHasLocalizedRelationshipField) hasLocalizedRelationshipField = true
|
||||
if (groupHasManyTextField) hasManyTextField = true
|
||||
if (groupHasLocalizedManyTextField) hasLocalizedManyTextField = true
|
||||
if (groupHasManyNumberField) hasManyNumberField = true
|
||||
if (groupHasLocalizedManyNumberField) hasLocalizedManyNumberField = true
|
||||
if (groupHasLocalizedField) {
|
||||
hasLocalizedField = true
|
||||
}
|
||||
if (groupHasLocalizedRelationshipField) {
|
||||
hasLocalizedRelationshipField = true
|
||||
}
|
||||
if (groupHasManyTextField) {
|
||||
hasManyTextField = true
|
||||
}
|
||||
if (groupHasLocalizedManyTextField) {
|
||||
hasLocalizedManyTextField = true
|
||||
}
|
||||
if (groupHasManyNumberField) {
|
||||
hasManyNumberField = true
|
||||
}
|
||||
if (groupHasLocalizedManyNumberField) {
|
||||
hasLocalizedManyNumberField = true
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -671,8 +695,8 @@ export const traverseFields = ({
|
||||
localesIndexes,
|
||||
newTableName: `${parentTableName}_${columnName}`,
|
||||
parentTableName,
|
||||
relationsToBuild,
|
||||
relationships,
|
||||
relationsToBuild,
|
||||
rootRelationsToBuild,
|
||||
rootTableIDColType,
|
||||
rootTableName,
|
||||
@@ -680,12 +704,24 @@ export const traverseFields = ({
|
||||
withinLocalizedArrayOrBlock,
|
||||
})
|
||||
|
||||
if (groupHasLocalizedField) hasLocalizedField = true
|
||||
if (groupHasLocalizedRelationshipField) hasLocalizedRelationshipField = true
|
||||
if (groupHasManyTextField) hasManyTextField = true
|
||||
if (groupHasLocalizedManyTextField) hasLocalizedManyTextField = true
|
||||
if (groupHasManyNumberField) hasManyNumberField = true
|
||||
if (groupHasLocalizedManyNumberField) hasLocalizedManyNumberField = true
|
||||
if (groupHasLocalizedField) {
|
||||
hasLocalizedField = true
|
||||
}
|
||||
if (groupHasLocalizedRelationshipField) {
|
||||
hasLocalizedRelationshipField = true
|
||||
}
|
||||
if (groupHasManyTextField) {
|
||||
hasManyTextField = true
|
||||
}
|
||||
if (groupHasLocalizedManyTextField) {
|
||||
hasLocalizedManyTextField = true
|
||||
}
|
||||
if (groupHasManyNumberField) {
|
||||
hasManyNumberField = true
|
||||
}
|
||||
if (groupHasLocalizedManyNumberField) {
|
||||
hasLocalizedManyNumberField = true
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -714,8 +750,8 @@ export const traverseFields = ({
|
||||
localesIndexes,
|
||||
newTableName,
|
||||
parentTableName,
|
||||
relationsToBuild,
|
||||
relationships,
|
||||
relationsToBuild,
|
||||
rootRelationsToBuild,
|
||||
rootTableIDColType,
|
||||
rootTableName,
|
||||
@@ -723,12 +759,24 @@ export const traverseFields = ({
|
||||
withinLocalizedArrayOrBlock,
|
||||
})
|
||||
|
||||
if (tabHasLocalizedField) hasLocalizedField = true
|
||||
if (tabHasLocalizedRelationshipField) hasLocalizedRelationshipField = true
|
||||
if (tabHasManyTextField) hasManyTextField = true
|
||||
if (tabHasLocalizedManyTextField) hasLocalizedManyTextField = true
|
||||
if (tabHasManyNumberField) hasManyNumberField = true
|
||||
if (tabHasLocalizedManyNumberField) hasLocalizedManyNumberField = true
|
||||
if (tabHasLocalizedField) {
|
||||
hasLocalizedField = true
|
||||
}
|
||||
if (tabHasLocalizedRelationshipField) {
|
||||
hasLocalizedRelationshipField = true
|
||||
}
|
||||
if (tabHasManyTextField) {
|
||||
hasManyTextField = true
|
||||
}
|
||||
if (tabHasLocalizedManyTextField) {
|
||||
hasLocalizedManyTextField = true
|
||||
}
|
||||
if (tabHasManyNumberField) {
|
||||
hasManyNumberField = true
|
||||
}
|
||||
if (tabHasLocalizedManyNumberField) {
|
||||
hasLocalizedManyNumberField = true
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -757,8 +805,8 @@ export const traverseFields = ({
|
||||
localesIndexes,
|
||||
newTableName,
|
||||
parentTableName,
|
||||
relationsToBuild,
|
||||
relationships,
|
||||
relationsToBuild,
|
||||
rootRelationsToBuild,
|
||||
rootTableIDColType,
|
||||
rootTableName,
|
||||
@@ -766,12 +814,24 @@ export const traverseFields = ({
|
||||
withinLocalizedArrayOrBlock,
|
||||
})
|
||||
|
||||
if (rowHasLocalizedField) hasLocalizedField = true
|
||||
if (rowHasLocalizedRelationshipField) hasLocalizedRelationshipField = true
|
||||
if (rowHasManyTextField) hasManyTextField = true
|
||||
if (rowHasLocalizedManyTextField) hasLocalizedManyTextField = true
|
||||
if (rowHasManyNumberField) hasManyNumberField = true
|
||||
if (rowHasLocalizedManyNumberField) hasLocalizedManyNumberField = true
|
||||
if (rowHasLocalizedField) {
|
||||
hasLocalizedField = true
|
||||
}
|
||||
if (rowHasLocalizedRelationshipField) {
|
||||
hasLocalizedRelationshipField = true
|
||||
}
|
||||
if (rowHasManyTextField) {
|
||||
hasManyTextField = true
|
||||
}
|
||||
if (rowHasLocalizedManyTextField) {
|
||||
hasLocalizedManyTextField = true
|
||||
}
|
||||
if (rowHasManyNumberField) {
|
||||
hasManyNumberField = true
|
||||
}
|
||||
if (rowHasLocalizedManyNumberField) {
|
||||
hasLocalizedManyNumberField = true
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -792,8 +852,12 @@ export const traverseFields = ({
|
||||
const relatedCollectionCustomID = relationshipConfig.fields.find(
|
||||
(field) => fieldAffectsData(field) && field.name === 'id',
|
||||
)
|
||||
if (relatedCollectionCustomID?.type === 'number') colType = 'numeric'
|
||||
if (relatedCollectionCustomID?.type === 'text') colType = 'text'
|
||||
if (relatedCollectionCustomID?.type === 'number') {
|
||||
colType = 'numeric'
|
||||
}
|
||||
if (relatedCollectionCustomID?.type === 'text') {
|
||||
colType = 'text'
|
||||
}
|
||||
|
||||
// make the foreign key column for relationship using the correct id column type
|
||||
targetTable[fieldName] = getIDColumn({
|
||||
|
||||
@@ -5,8 +5,9 @@ export const withDefault = (
|
||||
column: SQLiteColumnBuilder,
|
||||
field: FieldAffectingData,
|
||||
): SQLiteColumnBuilder => {
|
||||
if (typeof field.defaultValue === 'undefined' || typeof field.defaultValue === 'function')
|
||||
if (typeof field.defaultValue === 'undefined' || typeof field.defaultValue === 'function') {
|
||||
return column
|
||||
}
|
||||
|
||||
if (typeof field.defaultValue === 'string' && field.defaultValue.includes("'")) {
|
||||
const escapedString = field.defaultValue.replaceAll("'", "''")
|
||||
|
||||
@@ -26,7 +26,7 @@ export type Args = {
|
||||
push?: boolean
|
||||
relationshipsSuffix?: string
|
||||
schemaName?: string
|
||||
transactionOptions?: SQLiteTransactionConfig | false
|
||||
transactionOptions?: false | SQLiteTransactionConfig
|
||||
versionsSuffix?: string
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { DrizzleAdapter } from '@payloadcms/drizzle/types'
|
||||
import type { Connect } from 'payload'
|
||||
|
||||
import { pushDevSchema } from '@payloadcms/drizzle'
|
||||
import { VercelPool, sql } from '@vercel/postgres'
|
||||
import { sql, VercelPool } from '@vercel/postgres'
|
||||
import { drizzle } from 'drizzle-orm/node-postgres'
|
||||
|
||||
import type { VercelPostgresAdapter } from './types.js'
|
||||
@@ -40,7 +40,9 @@ export const connect: Connect = async function connect(
|
||||
}
|
||||
} catch (err) {
|
||||
this.payload.logger.error(`Error: cannot connect to Postgres. Details: ${err.message}`, err)
|
||||
if (typeof this.rejectInitializing === 'function') this.rejectInitializing()
|
||||
if (typeof this.rejectInitializing === 'function') {
|
||||
this.rejectInitializing()
|
||||
}
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
@@ -53,7 +55,9 @@ export const connect: Connect = async function connect(
|
||||
await pushDevSchema(this as unknown as DrizzleAdapter)
|
||||
}
|
||||
|
||||
if (typeof this.resolveInitializing === 'function') this.resolveInitializing()
|
||||
if (typeof this.resolveInitializing === 'function') {
|
||||
this.resolveInitializing()
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV === 'production' && this.prodMigrations) {
|
||||
await this.migrate({ migrations: this.prodMigrations })
|
||||
|
||||
@@ -193,7 +193,9 @@ export const traverseFields = ({ doc, fields, locale, path, rows }: Args) => {
|
||||
const matchedRelationship = rows.find((row) => {
|
||||
const matchesPath = row.path === relationshipPath
|
||||
|
||||
if (locale) return matchesPath && locale === row.locale
|
||||
if (locale) {
|
||||
return matchesPath && locale === row.locale
|
||||
}
|
||||
|
||||
return row.path === relationshipPath
|
||||
})
|
||||
|
||||
@@ -35,7 +35,9 @@ export const migrateRelationships = async ({
|
||||
req,
|
||||
tableName,
|
||||
}: Args) => {
|
||||
if (pathsToQuery.size === 0) return
|
||||
if (pathsToQuery.size === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
let offset = 0
|
||||
|
||||
@@ -54,7 +56,9 @@ export const migrateRelationships = async ({
|
||||
|
||||
paginationResult = await adapter.drizzle.execute(sql.raw(`${paginationStatement}`))
|
||||
|
||||
if (paginationResult.rows.length === 0) return
|
||||
if (paginationResult.rows.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
offset += 1
|
||||
|
||||
@@ -74,7 +78,9 @@ export const migrateRelationships = async ({
|
||||
const parentID = row.parent_id
|
||||
|
||||
if (typeof parentID === 'string' || typeof parentID === 'number') {
|
||||
if (!docsToResave[parentID]) docsToResave[parentID] = []
|
||||
if (!docsToResave[parentID]) {
|
||||
docsToResave[parentID] = []
|
||||
}
|
||||
docsToResave[parentID].push(row)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -33,7 +33,7 @@ export type Args = {
|
||||
* @experimental This only works when there are not other tables or enums of the same name in the database under a different schema. Awaiting fix from Drizzle.
|
||||
*/
|
||||
schemaName?: string
|
||||
transactionOptions?: PgTransactionConfig | false
|
||||
transactionOptions?: false | PgTransactionConfig
|
||||
versionsSuffix?: string
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Count , SanitizedCollectionConfig } from 'payload'
|
||||
import type { Count, SanitizedCollectionConfig } from 'payload'
|
||||
|
||||
import toSnakeCase from 'to-snake-case'
|
||||
|
||||
|
||||
@@ -47,7 +47,9 @@ export const createTableName = ({
|
||||
|
||||
let defaultTableName = `${prefix}${toSnakeCase(name ?? slug)}`
|
||||
|
||||
if (versions) defaultTableName = `_${defaultTableName}${adapter.versionsSuffix}`
|
||||
if (versions) {
|
||||
defaultTableName = `_${defaultTableName}${adapter.versionsSuffix}`
|
||||
}
|
||||
|
||||
let customTableNameResult: string
|
||||
|
||||
@@ -61,8 +63,9 @@ export const createTableName = ({
|
||||
? customNameDefinition({ tableName: parentTableName })
|
||||
: customNameDefinition
|
||||
|
||||
if (versionsCustomName)
|
||||
if (versionsCustomName) {
|
||||
customTableNameResult = `_${customTableNameResult}${adapter.versionsSuffix}`
|
||||
}
|
||||
}
|
||||
|
||||
const result = customTableNameResult || defaultTableName
|
||||
|
||||
@@ -25,7 +25,9 @@ export async function createVersion<T extends TypeWithID>(
|
||||
const tableName = this.tableNameMap.get(`_${defaultTableName}${this.versionsSuffix}`)
|
||||
|
||||
const version = { ...versionData }
|
||||
if (version.id) delete version.id
|
||||
if (version.id) {
|
||||
delete version.id
|
||||
}
|
||||
|
||||
const result = await upsertRow<TypeWithVersion<T>>({
|
||||
adapter: this,
|
||||
|
||||
@@ -4,7 +4,9 @@ import type { DrizzleAdapter } from './types.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/require-await
|
||||
export const destroy: Destroy = async function destroy(this: DrizzleAdapter) {
|
||||
if (this.enums) this.enums = {}
|
||||
if (this.enums) {
|
||||
this.enums = {}
|
||||
}
|
||||
this.schema = {}
|
||||
this.tables = {}
|
||||
this.relations = {}
|
||||
|
||||
@@ -22,7 +22,9 @@ export function findMigrationDir(migrationDir?: string): string {
|
||||
const relativeMigrations = path.resolve(cwd, 'migrations')
|
||||
|
||||
// Use arg if provided
|
||||
if (migrationDir) return migrationDir
|
||||
if (migrationDir) {
|
||||
return migrationDir
|
||||
}
|
||||
|
||||
// Check other common locations
|
||||
if (fs.existsSync(srcDir)) {
|
||||
|
||||
@@ -57,7 +57,9 @@ export async function migrateReset(this: DrizzleAdapter): Promise<void> {
|
||||
} catch (err: unknown) {
|
||||
let msg = `Error running migration ${migrationFile.name}.`
|
||||
|
||||
if (err instanceof Error) msg += ` ${err.message}`
|
||||
if (err instanceof Error) {
|
||||
msg += ` ${err.message}`
|
||||
}
|
||||
|
||||
await killTransaction(req)
|
||||
payload.logger.error({
|
||||
|
||||
@@ -7,7 +7,9 @@ export const convertPathToJSONTraversal = (incomingSegments: string[]) => {
|
||||
return segments.reduce((res, segment, i) => {
|
||||
const formattedSegment = formatJSONPathSegment(segment)
|
||||
|
||||
if (i + 1 === segments.length) return `${res}->>${formattedSegment}`
|
||||
if (i + 1 === segments.length) {
|
||||
return `${res}->>${formattedSegment}`
|
||||
}
|
||||
return `${res}->${formattedSegment}`
|
||||
}, '')
|
||||
}
|
||||
|
||||
@@ -47,8 +47,8 @@ type Args = {
|
||||
disableNotNull: boolean
|
||||
disableUnique: boolean
|
||||
fields: Field[]
|
||||
rootRelationsToBuild?: RelationMap
|
||||
rootRelationships?: Set<string>
|
||||
rootRelationsToBuild?: RelationMap
|
||||
rootTableIDColType?: string
|
||||
rootTableName?: string
|
||||
tableName: string
|
||||
@@ -77,8 +77,8 @@ export const buildTable = ({
|
||||
disableNotNull,
|
||||
disableUnique = false,
|
||||
fields,
|
||||
rootRelationsToBuild,
|
||||
rootRelationships,
|
||||
rootRelationsToBuild,
|
||||
rootTableIDColType,
|
||||
rootTableName: incomingRootTableName,
|
||||
tableName,
|
||||
@@ -125,8 +125,8 @@ export const buildTable = ({
|
||||
localesIndexes,
|
||||
newTableName: tableName,
|
||||
parentTableName: tableName,
|
||||
relationsToBuild,
|
||||
relationships,
|
||||
relationsToBuild,
|
||||
rootRelationsToBuild: rootRelationsToBuild || relationsToBuild,
|
||||
rootTableIDColType: rootTableIDColType || idColType,
|
||||
rootTableName,
|
||||
@@ -358,8 +358,12 @@ export const buildTable = ({
|
||||
const relatedCollectionCustomIDType =
|
||||
adapter.payload.collections[relationshipConfig.slug]?.customIDType
|
||||
|
||||
if (relatedCollectionCustomIDType === 'number') colType = 'numeric'
|
||||
if (relatedCollectionCustomIDType === 'text') colType = 'varchar'
|
||||
if (relatedCollectionCustomIDType === 'number') {
|
||||
colType = 'numeric'
|
||||
}
|
||||
if (relatedCollectionCustomIDType === 'text') {
|
||||
colType = 'varchar'
|
||||
}
|
||||
|
||||
relationshipColumns[`${relationTo}ID`] = parentIDColumnMap[colType](
|
||||
`${formattedRelationTo}_id`,
|
||||
|
||||
@@ -20,8 +20,9 @@ export const createIndex = ({ name, columnName, tableName, unique }: CreateIndex
|
||||
} else {
|
||||
columns = [table[name]]
|
||||
}
|
||||
if (unique)
|
||||
if (unique) {
|
||||
return uniqueIndex(`${tableName}_${columnName}_idx`).on(columns[0], ...columns.slice(1))
|
||||
}
|
||||
return index(`${tableName}_${columnName}_idx`).on(columns[0], ...columns.slice(1))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,15 @@ import type { Field, TabAsField } from 'payload'
|
||||
|
||||
import { relations } from 'drizzle-orm'
|
||||
import {
|
||||
PgNumericBuilder,
|
||||
PgUUIDBuilder,
|
||||
PgVarcharBuilder,
|
||||
boolean,
|
||||
foreignKey,
|
||||
index,
|
||||
integer,
|
||||
jsonb,
|
||||
numeric,
|
||||
PgNumericBuilder,
|
||||
PgUUIDBuilder,
|
||||
PgVarcharBuilder,
|
||||
text,
|
||||
timestamp,
|
||||
varchar,
|
||||
@@ -52,8 +52,8 @@ type Args = {
|
||||
localesIndexes: Record<string, (cols: GenericColumns) => IndexBuilder>
|
||||
newTableName: string
|
||||
parentTableName: string
|
||||
relationsToBuild: RelationMap
|
||||
relationships: Set<string>
|
||||
relationsToBuild: RelationMap
|
||||
rootRelationsToBuild?: RelationMap
|
||||
rootTableIDColType: string
|
||||
rootTableName: string
|
||||
@@ -88,8 +88,8 @@ export const traverseFields = ({
|
||||
localesIndexes,
|
||||
newTableName,
|
||||
parentTableName,
|
||||
relationsToBuild,
|
||||
relationships,
|
||||
relationsToBuild,
|
||||
rootRelationsToBuild,
|
||||
rootTableIDColType,
|
||||
rootTableName,
|
||||
@@ -105,12 +105,20 @@ export const traverseFields = ({
|
||||
let hasLocalizedManyNumberField = false
|
||||
|
||||
let parentIDColType: IDType = 'integer'
|
||||
if (columns.id instanceof PgUUIDBuilder) parentIDColType = 'uuid'
|
||||
if (columns.id instanceof PgNumericBuilder) parentIDColType = 'numeric'
|
||||
if (columns.id instanceof PgVarcharBuilder) parentIDColType = 'varchar'
|
||||
if (columns.id instanceof PgUUIDBuilder) {
|
||||
parentIDColType = 'uuid'
|
||||
}
|
||||
if (columns.id instanceof PgNumericBuilder) {
|
||||
parentIDColType = 'numeric'
|
||||
}
|
||||
if (columns.id instanceof PgVarcharBuilder) {
|
||||
parentIDColType = 'varchar'
|
||||
}
|
||||
|
||||
fields.forEach((field) => {
|
||||
if ('name' in field && field.name === 'id') return
|
||||
if ('name' in field && field.name === 'id') {
|
||||
return
|
||||
}
|
||||
let columnName: string
|
||||
let fieldName: string
|
||||
|
||||
@@ -396,8 +404,8 @@ export const traverseFields = ({
|
||||
disableNotNull: disableNotNullFromHere,
|
||||
disableUnique,
|
||||
fields: disableUnique ? idToUUID(field.fields) : field.fields,
|
||||
rootRelationsToBuild,
|
||||
rootRelationships: relationships,
|
||||
rootRelationsToBuild,
|
||||
rootTableIDColType,
|
||||
rootTableName,
|
||||
tableName: arrayTableName,
|
||||
@@ -418,12 +426,14 @@ export const traverseFields = ({
|
||||
}
|
||||
|
||||
if (subHasManyTextField) {
|
||||
if (!hasManyTextField || subHasManyTextField === 'index')
|
||||
if (!hasManyTextField || subHasManyTextField === 'index') {
|
||||
hasManyTextField = subHasManyTextField
|
||||
}
|
||||
}
|
||||
if (subHasManyNumberField) {
|
||||
if (!hasManyNumberField || subHasManyNumberField === 'index')
|
||||
if (!hasManyNumberField || subHasManyNumberField === 'index') {
|
||||
hasManyNumberField = subHasManyNumberField
|
||||
}
|
||||
}
|
||||
|
||||
relationsToBuild.set(fieldName, {
|
||||
@@ -494,13 +504,13 @@ export const traverseFields = ({
|
||||
|
||||
const baseExtraConfig: BaseExtraConfig = {
|
||||
_orderIdx: (cols) => index(`${blockTableName}_order_idx`).on(cols._order),
|
||||
_parentIDIdx: (cols) => index(`${blockTableName}_parent_id_idx`).on(cols._parentID),
|
||||
_parentIdFk: (cols) =>
|
||||
foreignKey({
|
||||
name: `${blockTableName}_parent_id_fk`,
|
||||
columns: [cols._parentID],
|
||||
foreignColumns: [adapter.tables[rootTableName].id],
|
||||
}).onDelete('cascade'),
|
||||
_parentIDIdx: (cols) => index(`${blockTableName}_parent_id_idx`).on(cols._parentID),
|
||||
_pathIdx: (cols) => index(`${blockTableName}_path_idx`).on(cols._path),
|
||||
}
|
||||
|
||||
@@ -528,8 +538,8 @@ export const traverseFields = ({
|
||||
disableNotNull: disableNotNullFromHere,
|
||||
disableUnique,
|
||||
fields: disableUnique ? idToUUID(block.fields) : block.fields,
|
||||
rootRelationsToBuild,
|
||||
rootRelationships: relationships,
|
||||
rootRelationsToBuild,
|
||||
rootTableIDColType,
|
||||
rootTableName,
|
||||
tableName: blockTableName,
|
||||
@@ -550,13 +560,15 @@ export const traverseFields = ({
|
||||
}
|
||||
|
||||
if (subHasManyTextField) {
|
||||
if (!hasManyTextField || subHasManyTextField === 'index')
|
||||
if (!hasManyTextField || subHasManyTextField === 'index') {
|
||||
hasManyTextField = subHasManyTextField
|
||||
}
|
||||
}
|
||||
|
||||
if (subHasManyNumberField) {
|
||||
if (!hasManyNumberField || subHasManyNumberField === 'index')
|
||||
if (!hasManyNumberField || subHasManyNumberField === 'index') {
|
||||
hasManyNumberField = subHasManyNumberField
|
||||
}
|
||||
}
|
||||
|
||||
adapter.relations[`relations_${blockTableName}`] = relations(
|
||||
@@ -641,8 +653,8 @@ export const traverseFields = ({
|
||||
localesIndexes,
|
||||
newTableName,
|
||||
parentTableName,
|
||||
relationsToBuild,
|
||||
relationships,
|
||||
relationsToBuild,
|
||||
rootRelationsToBuild,
|
||||
rootTableIDColType,
|
||||
rootTableName,
|
||||
@@ -650,12 +662,24 @@ export const traverseFields = ({
|
||||
withinLocalizedArrayOrBlock,
|
||||
})
|
||||
|
||||
if (groupHasLocalizedField) hasLocalizedField = true
|
||||
if (groupHasLocalizedRelationshipField) hasLocalizedRelationshipField = true
|
||||
if (groupHasManyTextField) hasManyTextField = true
|
||||
if (groupHasLocalizedManyTextField) hasLocalizedManyTextField = true
|
||||
if (groupHasManyNumberField) hasManyNumberField = true
|
||||
if (groupHasLocalizedManyNumberField) hasLocalizedManyNumberField = true
|
||||
if (groupHasLocalizedField) {
|
||||
hasLocalizedField = true
|
||||
}
|
||||
if (groupHasLocalizedRelationshipField) {
|
||||
hasLocalizedRelationshipField = true
|
||||
}
|
||||
if (groupHasManyTextField) {
|
||||
hasManyTextField = true
|
||||
}
|
||||
if (groupHasLocalizedManyTextField) {
|
||||
hasLocalizedManyTextField = true
|
||||
}
|
||||
if (groupHasManyNumberField) {
|
||||
hasManyNumberField = true
|
||||
}
|
||||
if (groupHasLocalizedManyNumberField) {
|
||||
hasLocalizedManyNumberField = true
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -682,8 +706,8 @@ export const traverseFields = ({
|
||||
localesIndexes,
|
||||
newTableName: `${parentTableName}_${columnName}`,
|
||||
parentTableName,
|
||||
relationsToBuild,
|
||||
relationships,
|
||||
relationsToBuild,
|
||||
rootRelationsToBuild,
|
||||
rootTableIDColType,
|
||||
rootTableName,
|
||||
@@ -691,12 +715,24 @@ export const traverseFields = ({
|
||||
withinLocalizedArrayOrBlock,
|
||||
})
|
||||
|
||||
if (groupHasLocalizedField) hasLocalizedField = true
|
||||
if (groupHasLocalizedRelationshipField) hasLocalizedRelationshipField = true
|
||||
if (groupHasManyTextField) hasManyTextField = true
|
||||
if (groupHasLocalizedManyTextField) hasLocalizedManyTextField = true
|
||||
if (groupHasManyNumberField) hasManyNumberField = true
|
||||
if (groupHasLocalizedManyNumberField) hasLocalizedManyNumberField = true
|
||||
if (groupHasLocalizedField) {
|
||||
hasLocalizedField = true
|
||||
}
|
||||
if (groupHasLocalizedRelationshipField) {
|
||||
hasLocalizedRelationshipField = true
|
||||
}
|
||||
if (groupHasManyTextField) {
|
||||
hasManyTextField = true
|
||||
}
|
||||
if (groupHasLocalizedManyTextField) {
|
||||
hasLocalizedManyTextField = true
|
||||
}
|
||||
if (groupHasManyNumberField) {
|
||||
hasManyNumberField = true
|
||||
}
|
||||
if (groupHasLocalizedManyNumberField) {
|
||||
hasLocalizedManyNumberField = true
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -724,8 +760,8 @@ export const traverseFields = ({
|
||||
localesIndexes,
|
||||
newTableName,
|
||||
parentTableName,
|
||||
relationsToBuild,
|
||||
relationships,
|
||||
relationsToBuild,
|
||||
rootRelationsToBuild,
|
||||
rootTableIDColType,
|
||||
rootTableName,
|
||||
@@ -733,12 +769,24 @@ export const traverseFields = ({
|
||||
withinLocalizedArrayOrBlock,
|
||||
})
|
||||
|
||||
if (tabHasLocalizedField) hasLocalizedField = true
|
||||
if (tabHasLocalizedRelationshipField) hasLocalizedRelationshipField = true
|
||||
if (tabHasManyTextField) hasManyTextField = true
|
||||
if (tabHasLocalizedManyTextField) hasLocalizedManyTextField = true
|
||||
if (tabHasManyNumberField) hasManyNumberField = true
|
||||
if (tabHasLocalizedManyNumberField) hasLocalizedManyNumberField = true
|
||||
if (tabHasLocalizedField) {
|
||||
hasLocalizedField = true
|
||||
}
|
||||
if (tabHasLocalizedRelationshipField) {
|
||||
hasLocalizedRelationshipField = true
|
||||
}
|
||||
if (tabHasManyTextField) {
|
||||
hasManyTextField = true
|
||||
}
|
||||
if (tabHasLocalizedManyTextField) {
|
||||
hasLocalizedManyTextField = true
|
||||
}
|
||||
if (tabHasManyNumberField) {
|
||||
hasManyNumberField = true
|
||||
}
|
||||
if (tabHasLocalizedManyNumberField) {
|
||||
hasLocalizedManyNumberField = true
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -766,8 +814,8 @@ export const traverseFields = ({
|
||||
localesIndexes,
|
||||
newTableName,
|
||||
parentTableName,
|
||||
relationsToBuild,
|
||||
relationships,
|
||||
relationsToBuild,
|
||||
rootRelationsToBuild,
|
||||
rootTableIDColType,
|
||||
rootTableName,
|
||||
@@ -775,12 +823,24 @@ export const traverseFields = ({
|
||||
withinLocalizedArrayOrBlock,
|
||||
})
|
||||
|
||||
if (rowHasLocalizedField) hasLocalizedField = true
|
||||
if (rowHasLocalizedRelationshipField) hasLocalizedRelationshipField = true
|
||||
if (rowHasManyTextField) hasManyTextField = true
|
||||
if (rowHasLocalizedManyTextField) hasLocalizedManyTextField = true
|
||||
if (rowHasManyNumberField) hasManyNumberField = true
|
||||
if (rowHasLocalizedManyNumberField) hasLocalizedManyNumberField = true
|
||||
if (rowHasLocalizedField) {
|
||||
hasLocalizedField = true
|
||||
}
|
||||
if (rowHasLocalizedRelationshipField) {
|
||||
hasLocalizedRelationshipField = true
|
||||
}
|
||||
if (rowHasManyTextField) {
|
||||
hasManyTextField = true
|
||||
}
|
||||
if (rowHasLocalizedManyTextField) {
|
||||
hasLocalizedManyTextField = true
|
||||
}
|
||||
if (rowHasManyNumberField) {
|
||||
hasManyNumberField = true
|
||||
}
|
||||
if (rowHasLocalizedManyNumberField) {
|
||||
hasLocalizedManyNumberField = true
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -801,8 +861,12 @@ export const traverseFields = ({
|
||||
const relatedCollectionCustomID = relationshipConfig.fields.find(
|
||||
(field) => fieldAffectsData(field) && field.name === 'id',
|
||||
)
|
||||
if (relatedCollectionCustomID?.type === 'number') colType = 'numeric'
|
||||
if (relatedCollectionCustomID?.type === 'text') colType = 'varchar'
|
||||
if (relatedCollectionCustomID?.type === 'number') {
|
||||
colType = 'numeric'
|
||||
}
|
||||
if (relatedCollectionCustomID?.type === 'text') {
|
||||
colType = 'varchar'
|
||||
}
|
||||
|
||||
// make the foreign key column for relationship using the correct id column type
|
||||
targetTable[fieldName] = parentIDColumnMap[colType](`${columnName}_id`).references(
|
||||
|
||||
@@ -5,8 +5,9 @@ export const withDefault = (
|
||||
column: PgColumnBuilder,
|
||||
field: FieldAffectingData,
|
||||
): PgColumnBuilder => {
|
||||
if (typeof field.defaultValue === 'undefined' || typeof field.defaultValue === 'function')
|
||||
if (typeof field.defaultValue === 'undefined' || typeof field.defaultValue === 'function') {
|
||||
return column
|
||||
}
|
||||
|
||||
if (typeof field.defaultValue === 'string' && field.defaultValue.includes("'")) {
|
||||
const escapedString = field.defaultValue.replaceAll("'", "''")
|
||||
|
||||
@@ -13,11 +13,11 @@ import type {
|
||||
IndexBuilder,
|
||||
PgColumn,
|
||||
PgEnum,
|
||||
pgEnum,
|
||||
PgInsertOnConflictDoUpdateConfig,
|
||||
PgSchema,
|
||||
PgTableWithColumns,
|
||||
UniqueConstraintBuilder,
|
||||
pgEnum,
|
||||
} from 'drizzle-orm/pg-core'
|
||||
import type { PgTableFn } from 'drizzle-orm/pg-core/table'
|
||||
import type { Payload, PayloadRequest } from 'payload'
|
||||
|
||||
@@ -539,7 +539,9 @@ export const getTableColumnFromPath = ({
|
||||
field,
|
||||
getNotNullColumnByValue: (val) => {
|
||||
const matchedRelation = relationTo.find((relation) => relation === val)
|
||||
if (matchedRelation) return `${matchedRelation}ID`
|
||||
if (matchedRelation) {
|
||||
return `${matchedRelation}ID`
|
||||
}
|
||||
return undefined
|
||||
},
|
||||
table: aliasRelationshipTable,
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import {
|
||||
type Column,
|
||||
type SQL,
|
||||
type SQLWrapper,
|
||||
and,
|
||||
type Column,
|
||||
eq,
|
||||
gt,
|
||||
gte,
|
||||
@@ -15,6 +13,8 @@ import {
|
||||
ne,
|
||||
notInArray,
|
||||
or,
|
||||
type SQL,
|
||||
type SQLWrapper,
|
||||
} from 'drizzle-orm'
|
||||
|
||||
type OperatorKeys =
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { APIError, type Field, type TabAsField, createArrayFromCommaDelineated } from 'payload'
|
||||
import { APIError, createArrayFromCommaDelineated, type Field, type TabAsField } from 'payload'
|
||||
import { fieldAffectsData } from 'payload/shared'
|
||||
|
||||
import type { DrizzleAdapter } from '../types.js'
|
||||
@@ -21,7 +21,9 @@ export const sanitizeQueryValue = ({
|
||||
let operator = operatorArg
|
||||
let formattedValue = val
|
||||
|
||||
if (!fieldAffectsData(field)) return { operator, value: formattedValue }
|
||||
if (!fieldAffectsData(field)) {
|
||||
return { operator, value: formattedValue }
|
||||
}
|
||||
|
||||
if (
|
||||
(field.type === 'relationship' || field.type === 'upload') &&
|
||||
@@ -43,8 +45,12 @@ export const sanitizeQueryValue = ({
|
||||
|
||||
// Cast incoming values as proper searchable types
|
||||
if (field.type === 'checkbox' && typeof val === 'string') {
|
||||
if (val.toLowerCase() === 'true') formattedValue = true
|
||||
if (val.toLowerCase() === 'false') formattedValue = false
|
||||
if (val.toLowerCase() === 'true') {
|
||||
formattedValue = true
|
||||
}
|
||||
if (val.toLowerCase() === 'false') {
|
||||
formattedValue = false
|
||||
}
|
||||
}
|
||||
|
||||
if (['all', 'in', 'not_in'].includes(operator)) {
|
||||
@@ -71,7 +77,9 @@ export const sanitizeQueryValue = ({
|
||||
if (Number.isNaN(Date.parse(formattedValue))) {
|
||||
return { operator, value: undefined }
|
||||
}
|
||||
} else if (typeof val === 'number') formattedValue = new Date(val).toISOString()
|
||||
} else if (typeof val === 'number') {
|
||||
formattedValue = new Date(val).toISOString()
|
||||
}
|
||||
}
|
||||
|
||||
if (field.type === 'relationship' || field.type === 'upload') {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import type { CommitTransaction } from 'payload'
|
||||
|
||||
export const commitTransaction: CommitTransaction = async function commitTransaction(id) {
|
||||
if (id instanceof Promise) return
|
||||
if (id instanceof Promise) {
|
||||
return
|
||||
}
|
||||
|
||||
// if the session was deleted it has already been aborted
|
||||
if (!this.sessions[id]) {
|
||||
|
||||
@@ -142,7 +142,9 @@ export const traverseFields = <T extends Record<string, unknown>>({
|
||||
if (field.localized) {
|
||||
result[field.name] = fieldData.reduce((arrayResult, row) => {
|
||||
if (typeof row._locale === 'string') {
|
||||
if (!arrayResult[row._locale]) arrayResult[row._locale] = []
|
||||
if (!arrayResult[row._locale]) {
|
||||
arrayResult[row._locale] = []
|
||||
}
|
||||
const locale = row._locale
|
||||
const data = {}
|
||||
delete row._locale
|
||||
@@ -235,7 +237,9 @@ export const traverseFields = <T extends Record<string, unknown>>({
|
||||
delete row._uuid
|
||||
}
|
||||
if (typeof row._locale === 'string') {
|
||||
if (!result[field.name][row._locale]) result[field.name][row._locale] = []
|
||||
if (!result[field.name][row._locale]) {
|
||||
result[field.name][row._locale] = []
|
||||
}
|
||||
result[field.name][row._locale].push(row)
|
||||
delete row._locale
|
||||
}
|
||||
@@ -355,7 +359,9 @@ export const traverseFields = <T extends Record<string, unknown>>({
|
||||
|
||||
relationPathMatch.forEach((row) => {
|
||||
if (typeof row.locale === 'string') {
|
||||
if (!relationsByLocale[row.locale]) relationsByLocale[row.locale] = []
|
||||
if (!relationsByLocale[row.locale]) {
|
||||
relationsByLocale[row.locale] = []
|
||||
}
|
||||
relationsByLocale[row.locale].push(row)
|
||||
}
|
||||
})
|
||||
@@ -382,7 +388,9 @@ export const traverseFields = <T extends Record<string, unknown>>({
|
||||
|
||||
if (field.type === 'text' && field?.hasMany) {
|
||||
const textPathMatch = texts[`${sanitizedPath}${field.name}`]
|
||||
if (!textPathMatch) return result
|
||||
if (!textPathMatch) {
|
||||
return result
|
||||
}
|
||||
|
||||
if (field.localized) {
|
||||
result[field.name] = {}
|
||||
@@ -390,7 +398,9 @@ export const traverseFields = <T extends Record<string, unknown>>({
|
||||
|
||||
textPathMatch.forEach((row) => {
|
||||
if (typeof row.locale === 'string') {
|
||||
if (!textsByLocale[row.locale]) textsByLocale[row.locale] = []
|
||||
if (!textsByLocale[row.locale]) {
|
||||
textsByLocale[row.locale] = []
|
||||
}
|
||||
textsByLocale[row.locale].push(row)
|
||||
}
|
||||
})
|
||||
@@ -417,7 +427,9 @@ export const traverseFields = <T extends Record<string, unknown>>({
|
||||
|
||||
if (field.type === 'number' && field.hasMany) {
|
||||
const numberPathMatch = numbers[`${sanitizedPath}${field.name}`]
|
||||
if (!numberPathMatch) return result
|
||||
if (!numberPathMatch) {
|
||||
return result
|
||||
}
|
||||
|
||||
if (field.localized) {
|
||||
result[field.name] = {}
|
||||
@@ -425,7 +437,9 @@ export const traverseFields = <T extends Record<string, unknown>>({
|
||||
|
||||
numberPathMatch.forEach((row) => {
|
||||
if (typeof row.locale === 'string') {
|
||||
if (!numbersByLocale[row.locale]) numbersByLocale[row.locale] = []
|
||||
if (!numbersByLocale[row.locale]) {
|
||||
numbersByLocale[row.locale] = []
|
||||
}
|
||||
numbersByLocale[row.locale].push(row)
|
||||
}
|
||||
})
|
||||
@@ -455,7 +469,9 @@ export const traverseFields = <T extends Record<string, unknown>>({
|
||||
if (field.localized) {
|
||||
result[field.name] = fieldData.reduce((selectResult, row) => {
|
||||
if (typeof row.locale === 'string') {
|
||||
if (!selectResult[row.locale]) selectResult[row.locale] = []
|
||||
if (!selectResult[row.locale]) {
|
||||
selectResult[row.locale] = []
|
||||
}
|
||||
selectResult[row.locale].push(row.value)
|
||||
}
|
||||
|
||||
@@ -494,7 +510,9 @@ export const traverseFields = <T extends Record<string, unknown>>({
|
||||
const locale = table._locale as string
|
||||
const refKey = field.localized && locale ? locale : field.name
|
||||
|
||||
if (field.localized && locale) delete table._locale
|
||||
if (field.localized && locale) {
|
||||
delete table._locale
|
||||
}
|
||||
ref[refKey] = traverseFields<Record<string, unknown>>({
|
||||
adapter,
|
||||
blocks,
|
||||
|
||||
@@ -48,12 +48,18 @@ export const transformBlocks = ({
|
||||
withinArrayOrBlockLocale,
|
||||
}: Args) => {
|
||||
data.forEach((blockRow, i) => {
|
||||
if (typeof blockRow.blockType !== 'string') return
|
||||
if (typeof blockRow.blockType !== 'string') {
|
||||
return
|
||||
}
|
||||
const matchedBlock = field.blocks.find(({ slug }) => slug === blockRow.blockType)
|
||||
if (!matchedBlock) return
|
||||
if (!matchedBlock) {
|
||||
return
|
||||
}
|
||||
const blockType = toSnakeCase(blockRow.blockType)
|
||||
|
||||
if (!blocks[blockType]) blocks[blockType] = []
|
||||
if (!blocks[blockType]) {
|
||||
blocks[blockType] = []
|
||||
}
|
||||
|
||||
const newRow: BlockRowToInsert = {
|
||||
arrays: {},
|
||||
@@ -64,8 +70,12 @@ export const transformBlocks = ({
|
||||
},
|
||||
}
|
||||
|
||||
if (field.localized && locale) newRow.row._locale = locale
|
||||
if (withinArrayOrBlockLocale) newRow.row._locale = withinArrayOrBlockLocale
|
||||
if (field.localized && locale) {
|
||||
newRow.row._locale = locale
|
||||
}
|
||||
if (withinArrayOrBlockLocale) {
|
||||
newRow.row._locale = withinArrayOrBlockLocale
|
||||
}
|
||||
|
||||
const blockTableName = adapter.tableNameMap.get(`${baseTableName}_blocks_${blockType}`)
|
||||
|
||||
|
||||
@@ -15,14 +15,18 @@ export const transformRelationship = ({ baseRow, data, field, relationships }: A
|
||||
relations.forEach((relation, i) => {
|
||||
if (relation) {
|
||||
const relationRow = { ...baseRow }
|
||||
if ('hasMany' in field && field.hasMany) relationRow.order = i + 1
|
||||
if ('hasMany' in field && field.hasMany) {
|
||||
relationRow.order = i + 1
|
||||
}
|
||||
|
||||
if (Array.isArray(field.relationTo) && valueIsValueWithRelation(relation)) {
|
||||
relationRow[`${relation.relationTo}ID`] = relation.value
|
||||
relationships.push(relationRow)
|
||||
} else {
|
||||
relationRow[`${field.relationTo}ID`] = relation
|
||||
if (relation) relationships.push(relationRow)
|
||||
if (relation) {
|
||||
relationships.push(relationRow)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -101,7 +101,9 @@ export const traverseFields = ({
|
||||
if (field.type === 'array') {
|
||||
const arrayTableName = adapter.tableNameMap.get(`${parentTableName}_${columnName}`)
|
||||
|
||||
if (!arrays[arrayTableName]) arrays[arrayTableName] = []
|
||||
if (!arrays[arrayTableName]) {
|
||||
arrays[arrayTableName] = []
|
||||
}
|
||||
|
||||
if (field.localized) {
|
||||
if (typeof data[field.name] === 'object' && data[field.name] !== null) {
|
||||
@@ -502,7 +504,9 @@ export const traverseFields = ({
|
||||
|
||||
if (field.type === 'select' && field.hasMany) {
|
||||
const selectTableName = adapter.tableNameMap.get(`${parentTableName}_${columnName}`)
|
||||
if (!selects[selectTableName]) selects[selectTableName] = []
|
||||
if (!selects[selectTableName]) {
|
||||
selects[selectTableName] = []
|
||||
}
|
||||
|
||||
if (field.localized) {
|
||||
if (typeof data[field.name] === 'object' && data[field.name] !== null) {
|
||||
@@ -537,7 +541,9 @@ export const traverseFields = ({
|
||||
if (field.localized) {
|
||||
if (typeof fieldData === 'object' && fieldData !== null) {
|
||||
Object.entries(fieldData).forEach(([localeKey, localeData]) => {
|
||||
if (!locales[localeKey]) locales[localeKey] = {}
|
||||
if (!locales[localeKey]) {
|
||||
locales[localeKey] = {}
|
||||
}
|
||||
|
||||
valuesToTransform.push({
|
||||
localeKey,
|
||||
@@ -550,7 +556,9 @@ export const traverseFields = ({
|
||||
let ref = row
|
||||
|
||||
if (forcedLocale) {
|
||||
if (!locales[forcedLocale]) locales[forcedLocale] = {}
|
||||
if (!locales[forcedLocale]) {
|
||||
locales[forcedLocale] = {}
|
||||
}
|
||||
ref = locales[forcedLocale]
|
||||
}
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ export interface DrizzleAdapter extends BaseDatabaseAdapter {
|
||||
deleteWhere: DeleteWhere
|
||||
drizzle: LibSQLDatabase | PostgresDB
|
||||
dropDatabase: DropDatabase
|
||||
enums?: Record<string, unknown> | never
|
||||
enums?: never | Record<string, unknown>
|
||||
execute: Execute<unknown>
|
||||
features: {
|
||||
json?: boolean
|
||||
|
||||
@@ -42,8 +42,9 @@ export const deleteExistingRowsByPath = async ({
|
||||
if (localizedPathsToDelete.size > 0) {
|
||||
const whereConstraints = [eq(table[parentColumnName], parentID)]
|
||||
|
||||
if (pathColumnName)
|
||||
if (pathColumnName) {
|
||||
whereConstraints.push(inArray(table[pathColumnName], Array.from(localizedPathsToDelete)))
|
||||
}
|
||||
|
||||
await adapter.deleteWhere({
|
||||
db,
|
||||
@@ -55,8 +56,9 @@ export const deleteExistingRowsByPath = async ({
|
||||
if (pathsToDelete.size > 0) {
|
||||
const whereConstraints = [eq(table[parentColumnName], parentID)]
|
||||
|
||||
if (pathColumnName)
|
||||
if (pathColumnName) {
|
||||
whereConstraints.push(inArray(table[pathColumnName], Array.from(pathsToDelete)))
|
||||
}
|
||||
|
||||
await adapter.deleteWhere({
|
||||
db,
|
||||
|
||||
@@ -116,7 +116,9 @@ export const upsertRow = async <T extends Record<string, unknown> | TypeWithID>(
|
||||
if (typeof row.parent === 'undefined') {
|
||||
row.parent = insertedRow.id
|
||||
}
|
||||
if (!selectsToInsert[selectTableName]) selectsToInsert[selectTableName] = []
|
||||
if (!selectsToInsert[selectTableName]) {
|
||||
selectsToInsert[selectTableName] = []
|
||||
}
|
||||
selectsToInsert[selectTableName].push(row)
|
||||
})
|
||||
})
|
||||
@@ -127,7 +129,9 @@ export const upsertRow = async <T extends Record<string, unknown> | TypeWithID>(
|
||||
Object.keys(rowToInsert.blocks).forEach((blockName) => {
|
||||
rowToInsert.blocks[blockName].forEach((blockRow) => {
|
||||
blockRow.row._parentID = insertedRow.id
|
||||
if (!blocksToInsert[blockName]) blocksToInsert[blockName] = []
|
||||
if (!blocksToInsert[blockName]) {
|
||||
blocksToInsert[blockName] = []
|
||||
}
|
||||
if (blockRow.row.uuid) {
|
||||
delete blockRow.row.uuid
|
||||
}
|
||||
@@ -360,8 +364,9 @@ export const upsertRow = async <T extends Record<string, unknown> | TypeWithID>(
|
||||
if (error.constraint.includes(replacement)) {
|
||||
const replacedConstraint = error.constraint.replace(replacement, '')
|
||||
|
||||
if (replacedConstraint && adapter.fieldConstraints[tableName]?.[replacedConstraint])
|
||||
if (replacedConstraint && adapter.fieldConstraints[tableName]?.[replacedConstraint]) {
|
||||
fieldName = adapter.fieldConstraints[tableName][replacedConstraint]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -396,7 +401,9 @@ export const upsertRow = async <T extends Record<string, unknown> | TypeWithID>(
|
||||
}
|
||||
}
|
||||
|
||||
if (ignoreResult) return data as T
|
||||
if (ignoreResult) {
|
||||
return data as T
|
||||
}
|
||||
|
||||
// //////////////////////////////////
|
||||
// RETRIEVE NEWLY UPDATED ROW
|
||||
|
||||
@@ -11,7 +11,9 @@ export const createBlocksMap = (data: Record<string, unknown>): BlocksMap => {
|
||||
|
||||
rows.forEach((row) => {
|
||||
if ('_path' in row) {
|
||||
if (!(row._path in blocksMap)) blocksMap[row._path] = []
|
||||
if (!(row._path in blocksMap)) {
|
||||
blocksMap[row._path] = []
|
||||
}
|
||||
|
||||
row.blockType = blockType
|
||||
blocksMap[row._path].push(row)
|
||||
|
||||
@@ -11,7 +11,9 @@ export const createPathMap = (rows: unknown): Record<string, Record<string, unkn
|
||||
|
||||
delete formattedRow.path
|
||||
|
||||
if (!res[row.path]) res[row.path] = []
|
||||
if (!res[row.path]) {
|
||||
res[row.path] = []
|
||||
}
|
||||
res[row.path].push(row)
|
||||
|
||||
return res
|
||||
|
||||
@@ -5,10 +5,18 @@ import { fieldAffectsData, fieldHasSubFields } from 'payload/shared'
|
||||
export const hasLocalesTable = (fields: Field[]): boolean => {
|
||||
return fields.some((field) => {
|
||||
// arrays always get a separate table
|
||||
if (field.type === 'array') return false
|
||||
if (fieldAffectsData(field) && field.localized) return true
|
||||
if (fieldHasSubFields(field)) return hasLocalesTable(field.fields)
|
||||
if (field.type === 'tabs') return field.tabs.some((tab) => hasLocalesTable(tab.fields))
|
||||
if (field.type === 'array') {
|
||||
return false
|
||||
}
|
||||
if (fieldAffectsData(field) && field.localized) {
|
||||
return true
|
||||
}
|
||||
if (fieldHasSubFields(field)) {
|
||||
return hasLocalesTable(field.fields)
|
||||
}
|
||||
if (field.type === 'tabs') {
|
||||
return field.tabs.some((tab) => hasLocalesTable(tab.fields))
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ const typescriptRules = {
|
||||
},
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/no-empty-object-type': 'warn'
|
||||
'@typescript-eslint/no-empty-object-type': 'warn',
|
||||
}
|
||||
|
||||
/** @typedef {import('eslint').Linter.FlatConfig} */
|
||||
|
||||
@@ -101,6 +101,32 @@ export const translations = {
|
||||
tooShort: 'Trop court',
|
||||
},
|
||||
},
|
||||
it: {
|
||||
$schema: './translation-schema.json',
|
||||
'plugin-seo': {
|
||||
almostThere: 'Ci siamo quasi',
|
||||
autoGenerate: 'Generazione automatica',
|
||||
bestPractices: 'migliori pratiche',
|
||||
characterCount: '{{current}}/{{minLength}}-{{maxLength}} caratteri, ',
|
||||
charactersLeftOver: '{{characters}} rimasti',
|
||||
charactersToGo: '{{characters}} mancanti',
|
||||
charactersTooMany: '{{characters}} in più',
|
||||
checksPassing: '{{current}}/{{max}} controlli superati',
|
||||
good: 'Bene',
|
||||
imageAutoGenerationTip:
|
||||
"La generazione automatica recupererà l'immagine selezionata per l'hero",
|
||||
lengthTipDescription:
|
||||
'Dovrebbe essere compreso tra {{minLength}} e {{maxLength}} caratteri. Per assistenza nella scrittura di meta descrizioni di qualità, vedere ',
|
||||
lengthTipTitle:
|
||||
'Dovrebbe essere compreso tra {{minLength}} e {{maxLength}} caratteri. Per assistenza nella scrittura di meta titoli di qualità, vedere ',
|
||||
noImage: 'Nessuna Immagine',
|
||||
preview: 'Anteprima',
|
||||
previewDescription:
|
||||
'I risultati esatti possono variare in base al contenuto e alla pertinenza della ricerca.',
|
||||
tooLong: 'Troppo lungo',
|
||||
tooShort: 'Troppo corto',
|
||||
},
|
||||
},
|
||||
nb: {
|
||||
$schema: './translation-schema.json',
|
||||
'plugin-seo': {
|
||||
@@ -201,28 +227,6 @@ export const translations = {
|
||||
tooShort: 'Закороткий',
|
||||
},
|
||||
},
|
||||
it: {
|
||||
$schema: './translation-schema.json',
|
||||
'plugin-seo': {
|
||||
almostThere: 'Ci siamo quasi',
|
||||
autoGenerate: 'Generazione automatica',
|
||||
bestPractices: 'migliori pratiche',
|
||||
characterCount: '{{current}}/{{minLength}}-{{maxLength}} caratteri, ',
|
||||
charactersLeftOver: '{{characters}} rimasti',
|
||||
charactersToGo: '{{characters}} mancanti',
|
||||
charactersTooMany: '{{characters}} in più',
|
||||
checksPassing: '{{current}}/{{max}} controlli superati',
|
||||
good: 'Bene',
|
||||
imageAutoGenerationTip: 'La generazione automatica recupererà l\'immagine selezionata per l\'hero',
|
||||
lengthTipDescription: 'Dovrebbe essere compreso tra {{minLength}} e {{maxLength}} caratteri. Per assistenza nella scrittura di meta descrizioni di qualità, vedere ',
|
||||
lengthTipTitle: 'Dovrebbe essere compreso tra {{minLength}} e {{maxLength}} caratteri. Per assistenza nella scrittura di meta titoli di qualità, vedere ',
|
||||
noImage: 'Nessuna Immagine',
|
||||
preview: 'Anteprima',
|
||||
previewDescription: 'I risultati esatti possono variare in base al contenuto e alla pertinenza della ricerca.',
|
||||
tooLong: 'Troppo lungo',
|
||||
tooShort: 'Troppo corto'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type PluginSEOTranslations = typeof translations.en
|
||||
|
||||
@@ -20,24 +20,25 @@ import { default as default_18 } from '@/components/BeforeDashboard'
|
||||
import { default as default_19 } from '@/components/BeforeLogin'
|
||||
|
||||
export const importMap = {
|
||||
"@payloadcms/richtext-lexical/client#RichTextCell": RichTextCell_0,
|
||||
"@payloadcms/richtext-lexical/client#RichTextField": RichTextField_1,
|
||||
"@payloadcms/richtext-lexical/generateComponentMap#getGenerateComponentMap": getGenerateComponentMap_2,
|
||||
"@payloadcms/richtext-lexical/client#InlineToolbarFeatureClient": InlineToolbarFeatureClient_3,
|
||||
"@payloadcms/richtext-lexical/client#FixedToolbarFeatureClient": FixedToolbarFeatureClient_4,
|
||||
"@payloadcms/richtext-lexical/client#HeadingFeatureClient": HeadingFeatureClient_5,
|
||||
"@payloadcms/richtext-lexical/client#UnderlineFeatureClient": UnderlineFeatureClient_6,
|
||||
"@payloadcms/richtext-lexical/client#BoldFeatureClient": BoldFeatureClient_7,
|
||||
"@payloadcms/richtext-lexical/client#ItalicFeatureClient": ItalicFeatureClient_8,
|
||||
"@payloadcms/richtext-lexical/client#LinkFeatureClient": LinkFeatureClient_9,
|
||||
"@payloadcms/plugin-seo/client#OverviewComponent": OverviewComponent_10,
|
||||
"@payloadcms/plugin-seo/client#MetaTitleComponent": MetaTitleComponent_11,
|
||||
"@payloadcms/plugin-seo/client#MetaImageComponent": MetaImageComponent_12,
|
||||
"@payloadcms/plugin-seo/client#MetaDescriptionComponent": MetaDescriptionComponent_13,
|
||||
"@payloadcms/plugin-seo/client#PreviewComponent": PreviewComponent_14,
|
||||
"@/fields/slug/SlugComponent#SlugComponent": SlugComponent_15,
|
||||
"@payloadcms/richtext-lexical/client#HorizontalRuleFeatureClient": HorizontalRuleFeatureClient_16,
|
||||
"@payloadcms/richtext-lexical/client#BlocksFeatureClient": BlocksFeatureClient_17,
|
||||
"@/components/BeforeDashboard#default": default_18,
|
||||
"@/components/BeforeLogin#default": default_19
|
||||
'@payloadcms/richtext-lexical/client#RichTextCell': RichTextCell_0,
|
||||
'@payloadcms/richtext-lexical/client#RichTextField': RichTextField_1,
|
||||
'@payloadcms/richtext-lexical/generateComponentMap#getGenerateComponentMap':
|
||||
getGenerateComponentMap_2,
|
||||
'@payloadcms/richtext-lexical/client#InlineToolbarFeatureClient': InlineToolbarFeatureClient_3,
|
||||
'@payloadcms/richtext-lexical/client#FixedToolbarFeatureClient': FixedToolbarFeatureClient_4,
|
||||
'@payloadcms/richtext-lexical/client#HeadingFeatureClient': HeadingFeatureClient_5,
|
||||
'@payloadcms/richtext-lexical/client#UnderlineFeatureClient': UnderlineFeatureClient_6,
|
||||
'@payloadcms/richtext-lexical/client#BoldFeatureClient': BoldFeatureClient_7,
|
||||
'@payloadcms/richtext-lexical/client#ItalicFeatureClient': ItalicFeatureClient_8,
|
||||
'@payloadcms/richtext-lexical/client#LinkFeatureClient': LinkFeatureClient_9,
|
||||
'@payloadcms/plugin-seo/client#OverviewComponent': OverviewComponent_10,
|
||||
'@payloadcms/plugin-seo/client#MetaTitleComponent': MetaTitleComponent_11,
|
||||
'@payloadcms/plugin-seo/client#MetaImageComponent': MetaImageComponent_12,
|
||||
'@payloadcms/plugin-seo/client#MetaDescriptionComponent': MetaDescriptionComponent_13,
|
||||
'@payloadcms/plugin-seo/client#PreviewComponent': PreviewComponent_14,
|
||||
'@/fields/slug/SlugComponent#SlugComponent': SlugComponent_15,
|
||||
'@payloadcms/richtext-lexical/client#HorizontalRuleFeatureClient': HorizontalRuleFeatureClient_16,
|
||||
'@payloadcms/richtext-lexical/client#BlocksFeatureClient': BlocksFeatureClient_17,
|
||||
'@/components/BeforeDashboard#default': default_18,
|
||||
'@/components/BeforeLogin#default': default_19,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user