chore(drizzle): fix lint errors in @payloadcms/drizzle (#12428)

This commit is contained in:
Sasha
2025-05-19 11:14:20 +03:00
committed by GitHub
parent 14252696ce
commit 38029cdd6e
25 changed files with 34 additions and 37 deletions

View File

@@ -4,7 +4,7 @@ import toSnakeCase from 'to-snake-case'
import type { DrizzleAdapter } from './types.js' import type { DrizzleAdapter } from './types.js'
import buildQuery from './queries/buildQuery.js' import { buildQuery } from './queries/buildQuery.js'
import { getTransaction } from './utilities/getTransaction.js' import { getTransaction } from './utilities/getTransaction.js'
export const count: Count = async function count( export const count: Count = async function count(

View File

@@ -5,7 +5,7 @@ import toSnakeCase from 'to-snake-case'
import type { DrizzleAdapter } from './types.js' import type { DrizzleAdapter } from './types.js'
import buildQuery from './queries/buildQuery.js' import { buildQuery } from './queries/buildQuery.js'
import { getTransaction } from './utilities/getTransaction.js' import { getTransaction } from './utilities/getTransaction.js'
export const countGlobalVersions: CountGlobalVersions = async function countGlobalVersions( export const countGlobalVersions: CountGlobalVersions = async function countGlobalVersions(

View File

@@ -5,7 +5,7 @@ import toSnakeCase from 'to-snake-case'
import type { DrizzleAdapter } from './types.js' import type { DrizzleAdapter } from './types.js'
import buildQuery from './queries/buildQuery.js' import { buildQuery } from './queries/buildQuery.js'
import { getTransaction } from './utilities/getTransaction.js' import { getTransaction } from './utilities/getTransaction.js'
export const countVersions: CountVersions = async function countVersions( export const countVersions: CountVersions = async function countVersions(

View File

@@ -23,10 +23,10 @@ export async function createGlobal<T extends Record<string, unknown>>(
data, data,
db, db,
fields: globalConfig.flattenedFields, fields: globalConfig.flattenedFields,
ignoreResult: returning === false,
operation: 'create', operation: 'create',
req, req,
tableName, tableName,
ignoreResult: returning === false,
}) })
if (returning === false) { if (returning === false) {

View File

@@ -17,11 +17,11 @@ export async function createGlobalVersion<T extends TypeWithID>(
globalSlug, globalSlug,
publishedLocale, publishedLocale,
req, req,
returning,
select, select,
snapshot, snapshot,
updatedAt, updatedAt,
versionData, versionData,
returning,
}: CreateGlobalVersionArgs, }: CreateGlobalVersionArgs,
) { ) {
const db = await getTransaction(this, req) const db = await getTransaction(this, req)
@@ -42,11 +42,11 @@ export async function createGlobalVersion<T extends TypeWithID>(
}, },
db, db,
fields: buildVersionGlobalFields(this.payload.config, global, true), fields: buildVersionGlobalFields(this.payload.config, global, true),
ignoreResult: returning === false ? 'idOnly' : false,
operation: 'create', operation: 'create',
req, req,
select, select,
tableName, tableName,
ignoreResult: returning === false ? 'idOnly' : false,
}) })
const table = this.tables[tableName] const table = this.tables[tableName]

View File

@@ -18,11 +18,11 @@ export async function createVersion<T extends TypeWithID>(
parent, parent,
publishedLocale, publishedLocale,
req, req,
returning,
select, select,
snapshot, snapshot,
updatedAt, updatedAt,
versionData, versionData,
returning,
}: CreateVersionArgs<T>, }: CreateVersionArgs<T>,
) { ) {
const db = await getTransaction(this, req) const db = await getTransaction(this, req)

View File

@@ -6,7 +6,7 @@ import toSnakeCase from 'to-snake-case'
import type { DrizzleAdapter } from './types.js' import type { DrizzleAdapter } from './types.js'
import { buildFindManyArgs } from './find/buildFindManyArgs.js' import { buildFindManyArgs } from './find/buildFindManyArgs.js'
import buildQuery from './queries/buildQuery.js' import { buildQuery } from './queries/buildQuery.js'
import { selectDistinct } from './queries/selectDistinct.js' import { selectDistinct } from './queries/selectDistinct.js'
import { transform } from './transform/read/index.js' import { transform } from './transform/read/index.js'
import { getTransaction } from './utilities/getTransaction.js' import { getTransaction } from './utilities/getTransaction.js'

View File

@@ -4,7 +4,7 @@ import { inArray } from 'drizzle-orm'
import type { DrizzleAdapter } from '../types.js' import type { DrizzleAdapter } from '../types.js'
import buildQuery from '../queries/buildQuery.js' import { buildQuery } from '../queries/buildQuery.js'
import { selectDistinct } from '../queries/selectDistinct.js' import { selectDistinct } from '../queries/selectDistinct.js'
import { transform } from '../transform/read/index.js' import { transform } from '../transform/read/index.js'
import { getNameFromDrizzleTable } from '../utilities/getNameFromDrizzleTable.js' import { getNameFromDrizzleTable } from '../utilities/getNameFromDrizzleTable.js'

View File

@@ -19,7 +19,7 @@ import toSnakeCase from 'to-snake-case'
import type { BuildQueryJoinAliases, DrizzleAdapter } from '../types.js' import type { BuildQueryJoinAliases, DrizzleAdapter } from '../types.js'
import type { Result } from './buildFindManyArgs.js' import type { Result } from './buildFindManyArgs.js'
import buildQuery from '../queries/buildQuery.js' import { buildQuery } from '../queries/buildQuery.js'
import { getTableAlias } from '../queries/getTableAlias.js' import { getTableAlias } from '../queries/getTableAlias.js'
import { operatorMap } from '../queries/operatorMap.js' import { operatorMap } from '../queries/operatorMap.js'
import { getArrayRelationName } from '../utilities/getArrayRelationName.js' import { getArrayRelationName } from '../utilities/getArrayRelationName.js'

View File

@@ -23,7 +23,7 @@ export { migrateFresh } from './migrateFresh.js'
export { migrateRefresh } from './migrateRefresh.js' export { migrateRefresh } from './migrateRefresh.js'
export { migrateReset } from './migrateReset.js' export { migrateReset } from './migrateReset.js'
export { migrateStatus } from './migrateStatus.js' export { migrateStatus } from './migrateStatus.js'
export { default as buildQuery } from './queries/buildQuery.js' export { buildQuery } from './queries/buildQuery.js'
export { operatorMap } from './queries/operatorMap.js' export { operatorMap } from './queries/operatorMap.js'
export type { Operators } from './queries/operatorMap.js' export type { Operators } from './queries/operatorMap.js'
export { parseParams } from './queries/parseParams.js' export { parseParams } from './queries/parseParams.js'

View File

@@ -1,4 +1,4 @@
import type { FlattenedBlock, FlattenedField } from 'payload' import type { FlattenedField } from 'payload'
type Args = { type Args = {
doc: Record<string, unknown> doc: Record<string, unknown>
@@ -54,7 +54,7 @@ export const traverseFields = ({ doc, fields, locale, path, rows }: Args) => {
// Can ignore string blocks, as those were added in v3 and don't need to be migrated // Can ignore string blocks, as those were added in v3 and don't need to be migrated
const matchedBlock = field.blocks.find( const matchedBlock = field.blocks.find(
(block) => typeof block !== 'string' && block.slug === row.blockType, (block) => typeof block !== 'string' && block.slug === row.blockType,
) as FlattenedBlock | undefined )
if (matchedBlock) { if (matchedBlock) {
return traverseFields({ return traverseFields({
@@ -75,7 +75,7 @@ export const traverseFields = ({ doc, fields, locale, path, rows }: Args) => {
// Can ignore string blocks, as those were added in v3 and don't need to be migrated // Can ignore string blocks, as those were added in v3 and don't need to be migrated
const matchedBlock = field.blocks.find( const matchedBlock = field.blocks.find(
(block) => typeof block !== 'string' && block.slug === row.blockType, (block) => typeof block !== 'string' && block.slug === row.blockType,
) as FlattenedBlock | undefined )
if (matchedBlock) { if (matchedBlock) {
return traverseFields({ return traverseFields({

View File

@@ -1,7 +1,7 @@
import type { SQL, Table } from 'drizzle-orm' import type { SQL, Table } from 'drizzle-orm'
import type { FlattenedField, Sort } from 'payload' import type { FlattenedField, Sort } from 'payload'
import { asc, desc, or } from 'drizzle-orm' import { asc, desc } from 'drizzle-orm'
import type { DrizzleAdapter, GenericColumn } from '../types.js' import type { DrizzleAdapter, GenericColumn } from '../types.js'
import type { BuildQueryJoinAliases, BuildQueryResult } from './buildQuery.js' import type { BuildQueryJoinAliases, BuildQueryResult } from './buildQuery.js'
@@ -92,7 +92,7 @@ export const buildOrderBy = ({
selectFields[sortTableColumnName] = sortTable[sortTableColumnName] selectFields[sortTableColumnName] = sortTable[sortTableColumnName]
} }
} catch (err) { } catch (_) {
// continue // continue
} }
} }

View File

@@ -37,7 +37,8 @@ export type BuildQueryResult = {
selectFields: Record<string, GenericColumn> selectFields: Record<string, GenericColumn>
where: SQL where: SQL
} }
const buildQuery = function buildQuery({
export const buildQuery = function buildQuery({
adapter, adapter,
aliasTable, aliasTable,
fields, fields,
@@ -92,5 +93,3 @@ const buildQuery = function buildQuery({
where, where,
} }
} }
export default buildQuery

View File

@@ -280,7 +280,7 @@ export const getTableColumnFromPath = ({
tableName: newTableName, tableName: newTableName,
value, value,
}) })
} catch (error) { } catch (_) {
// this is fine, not every block will have the field // this is fine, not every block will have the field
} }
if (!result) { if (!result) {

View File

@@ -15,7 +15,6 @@ import {
notInArray, notInArray,
or, or,
type SQL, type SQL,
type SQLWrapper,
} from 'drizzle-orm' } from 'drizzle-orm'
type OperatorKeys = type OperatorKeys =
@@ -35,7 +34,7 @@ type OperatorKeys =
| 'not_like' | 'not_like'
| 'or' | 'or'
export type Operators = Record<OperatorKeys, (column: Column, value: SQLWrapper | unknown) => SQL> export type Operators = Record<OperatorKeys, (column: Column, value: unknown) => SQL>
export const operatorMap: Operators = { export const operatorMap: Operators = {
and, and,

View File

@@ -1,5 +1,4 @@
import type { QueryPromise, SQL } from 'drizzle-orm' import type { QueryPromise, SQL } from 'drizzle-orm'
import type { PgSelect } from 'drizzle-orm/pg-core'
import type { SQLiteColumn, SQLiteSelect } from 'drizzle-orm/sqlite-core' import type { SQLiteColumn, SQLiteSelect } from 'drizzle-orm/sqlite-core'
import type { import type {

View File

@@ -12,7 +12,7 @@ export const commitTransaction: CommitTransaction = async function commitTransac
try { try {
await this.sessions[id].resolve() await this.sessions[id].resolve()
} catch (err: unknown) { } catch (_) {
await this.sessions[id].reject() await this.sessions[id].reject()
} }

View File

@@ -22,7 +22,7 @@ export const transformRelationship = ({ baseRow, data, field, relationships }: A
if (Array.isArray(field.relationTo) && valueIsValueWithRelation(relation)) { if (Array.isArray(field.relationTo) && valueIsValueWithRelation(relation)) {
relationRow[`${relation.relationTo}ID`] = relation.value relationRow[`${relation.relationTo}ID`] = relation.value
relationships.push(relationRow) relationships.push(relationRow)
} else { } else if (typeof field.relationTo === 'string') {
relationRow[`${field.relationTo}ID`] = relation relationRow[`${field.relationTo}ID`] = relation
if (relation) { if (relation) {
relationships.push(relationRow) relationships.push(relationRow)

View File

@@ -9,7 +9,7 @@ import { getTransaction } from './utilities/getTransaction.js'
export async function updateGlobal<T extends Record<string, unknown>>( export async function updateGlobal<T extends Record<string, unknown>>(
this: DrizzleAdapter, this: DrizzleAdapter,
{ slug, data, req, select, returning }: UpdateGlobalArgs, { slug, data, req, returning, select }: UpdateGlobalArgs,
): Promise<T> { ): Promise<T> {
const db = await getTransaction(this, req) const db = await getTransaction(this, req)
const globalConfig = this.payload.globals.config.find((config) => config.slug === slug) const globalConfig = this.payload.globals.config.find((config) => config.slug === slug)
@@ -23,10 +23,10 @@ export async function updateGlobal<T extends Record<string, unknown>>(
data, data,
db, db,
fields: globalConfig.flattenedFields, fields: globalConfig.flattenedFields,
ignoreResult: returning === false,
req, req,
select, select,
tableName, tableName,
ignoreResult: returning === false,
}) })
if (returning === false) { if (returning === false) {

View File

@@ -10,7 +10,7 @@ import toSnakeCase from 'to-snake-case'
import type { DrizzleAdapter } from './types.js' import type { DrizzleAdapter } from './types.js'
import buildQuery from './queries/buildQuery.js' import { buildQuery } from './queries/buildQuery.js'
import { upsertRow } from './upsertRow/index.js' import { upsertRow } from './upsertRow/index.js'
import { getTransaction } from './utilities/getTransaction.js' import { getTransaction } from './utilities/getTransaction.js'
@@ -21,10 +21,10 @@ export async function updateGlobalVersion<T extends TypeWithID>(
global, global,
locale, locale,
req, req,
returning,
select, select,
versionData, versionData,
where: whereArg, where: whereArg,
returning,
}: UpdateGlobalVersionArgs<T>, }: UpdateGlobalVersionArgs<T>,
) { ) {
const db = await getTransaction(this, req) const db = await getTransaction(this, req)
@@ -53,12 +53,12 @@ export async function updateGlobalVersion<T extends TypeWithID>(
data: versionData, data: versionData,
db, db,
fields, fields,
ignoreResult: returning === false,
operation: 'update', operation: 'update',
req, req,
select, select,
tableName, tableName,
where, where,
ignoreResult: returning === false,
}) })
if (returning === false) { if (returning === false) {

View File

@@ -5,7 +5,7 @@ import toSnakeCase from 'to-snake-case'
import type { DrizzleAdapter } from './types.js' import type { DrizzleAdapter } from './types.js'
import buildQuery from './queries/buildQuery.js' import { buildQuery } from './queries/buildQuery.js'
import { selectDistinct } from './queries/selectDistinct.js' import { selectDistinct } from './queries/selectDistinct.js'
import { upsertRow } from './upsertRow/index.js' import { upsertRow } from './upsertRow/index.js'
import { getTransaction } from './utilities/getTransaction.js' import { getTransaction } from './utilities/getTransaction.js'

View File

@@ -5,7 +5,7 @@ import toSnakeCase from 'to-snake-case'
import type { DrizzleAdapter } from './types.js' import type { DrizzleAdapter } from './types.js'
import buildQuery from './queries/buildQuery.js' import { buildQuery } from './queries/buildQuery.js'
import { selectDistinct } from './queries/selectDistinct.js' import { selectDistinct } from './queries/selectDistinct.js'
import { upsertRow } from './upsertRow/index.js' import { upsertRow } from './upsertRow/index.js'
import { getTransaction } from './utilities/getTransaction.js' import { getTransaction } from './utilities/getTransaction.js'

View File

@@ -10,7 +10,7 @@ import toSnakeCase from 'to-snake-case'
import type { DrizzleAdapter } from './types.js' import type { DrizzleAdapter } from './types.js'
import buildQuery from './queries/buildQuery.js' import { buildQuery } from './queries/buildQuery.js'
import { upsertRow } from './upsertRow/index.js' import { upsertRow } from './upsertRow/index.js'
import { getTransaction } from './utilities/getTransaction.js' import { getTransaction } from './utilities/getTransaction.js'
@@ -21,10 +21,10 @@ export async function updateVersion<T extends TypeWithID>(
collection, collection,
locale, locale,
req, req,
returning,
select, select,
versionData, versionData,
where: whereArg, where: whereArg,
returning,
}: UpdateVersionArgs<T>, }: UpdateVersionArgs<T>,
) { ) {
const db = await getTransaction(this, req) const db = await getTransaction(this, req)
@@ -50,13 +50,13 @@ export async function updateVersion<T extends TypeWithID>(
data: versionData, data: versionData,
db, db,
fields, fields,
ignoreResult: returning === false,
joinQuery: false, joinQuery: false,
operation: 'update', operation: 'update',
req, req,
select, select,
tableName, tableName,
where, where,
ignoreResult: returning === false,
}) })
if (returning === false) { if (returning === false) {

View File

@@ -46,7 +46,7 @@ export const insertArrays = async ({
// Add any sub arrays that need to be created // Add any sub arrays that need to be created
// We will call this recursively below // We will call this recursively below
arrayRows.forEach((arrayRow, i) => { arrayRows.forEach((arrayRow) => {
if (Object.keys(arrayRow.arrays).length > 0) { if (Object.keys(arrayRow.arrays).length > 0) {
rowsByTable[tableName].arrays.push(arrayRow.arrays) rowsByTable[tableName].arrays.push(arrayRow.arrays)
} }

View File

@@ -12,7 +12,7 @@ type BaseArgs = {
* When true, skips reading the data back from the database and returns the input data * When true, skips reading the data back from the database and returns the input data
* @default false * @default false
*/ */
ignoreResult?: boolean | 'idOnly' ignoreResult?: 'idOnly' | boolean
joinQuery?: JoinQuery joinQuery?: JoinQuery
path?: string path?: string
req?: Partial<PayloadRequest> req?: Partial<PayloadRequest>