chore(eslint): curly [skip-lint] (#7959)

Now enforcing curly brackets on all if statements. Includes auto-fixer.


```ts
//  Bad
if (foo) foo++;

//  Good
if (foo) {
  foo++;
}
```




Note: this did not lint the `drizzle` package or any `db-*` packages.
This will be done in the future.
This commit is contained in:
Elliot DeNolf
2024-08-29 10:15:36 -04:00
committed by GitHub
parent dd3d985091
commit 142616e6ad
267 changed files with 1681 additions and 611 deletions

View File

@@ -40,6 +40,7 @@ export const rootEslintConfig = [
{
ignores: [
...defaultESLintIgnores,
'packages/eslint-*/**',
'test/live-preview/next-app',
'packages/**/*.spec.ts',
'templates/**',

View File

@@ -167,7 +167,9 @@ async function installAndConfigurePayload(
}
const logDebug = (message: string) => {
if (debug) origDebug(message)
if (debug) {
origDebug(message)
}
}
if (!fs.existsSync(projectDir)) {

View File

@@ -4,13 +4,19 @@ import slugify from '@sindresorhus/slugify'
import type { CliArgs } from '../types.js'
export async function parseProjectName(args: CliArgs): Promise<string> {
if (args['--name']) return slugify(args['--name'])
if (args._[0]) return slugify(args._[0])
if (args['--name']) {
return slugify(args['--name'])
}
if (args._[0]) {
return slugify(args._[0])
}
const projectName = await p.text({
message: 'Project name?',
validate: (value) => {
if (!value) return 'Please enter a project name.'
if (!value) {
return 'Please enter a project name.'
}
},
})
if (p.isCancel(projectName)) {

View File

@@ -9,7 +9,9 @@ export async function parseTemplate(
if (args['--template']) {
const templateName = args['--template']
const template = validTemplates.find((t) => t.name === templateName)
if (!template) throw new Error('Invalid template given')
if (!template) {
throw new Error('Invalid template given')
}
return template
}

View File

@@ -54,7 +54,9 @@ export async function selectDb(args: CliArgs, projectName: string): Promise<DbDe
value: dbChoice.value,
})),
})
if (p.isCancel(dbType)) process.exit(0)
if (p.isCancel(dbType)) {
process.exit(0)
}
}
const dbChoice = dbChoiceRecord[dbType]
@@ -73,7 +75,9 @@ export async function selectDb(args: CliArgs, projectName: string): Promise<DbDe
initialValue: initialDbUri,
message: `Enter ${dbChoice.title.split(' ')[0]} connection string`, // strip beta from title
})
if (p.isCancel(dbUri)) process.exit(0)
if (p.isCancel(dbUri)) {
process.exit(0)
}
}
return {

View File

@@ -16,7 +16,9 @@ import { installPackages } from './install-packages.js'
export async function updatePayloadInProject(
appDetails: NextAppDetails,
): Promise<{ message: string; success: boolean }> {
if (!appDetails.nextConfigPath) return { message: 'No Next.js config found', success: false }
if (!appDetails.nextConfigPath) {
return { message: 'No Next.js config found', success: false }
}
const projectDir = path.dirname(appDetails.nextConfigPath)

View File

@@ -36,7 +36,9 @@ export async function writeEnvFile(args: {
.split('\n')
.filter((e) => e)
.map((line) => {
if (line.startsWith('#') || !line.includes('=')) return line
if (line.startsWith('#') || !line.includes('=')) {
return line
}
const split = line.split('=')
const key = split[0]

View File

@@ -47,7 +47,9 @@ async function buildEmail(emailConfig?: NodemailerAdapterArgs): Promise<{
}> {
if (!emailConfig) {
const transport = await createMockAccount(emailConfig)
if (!transport) throw new InvalidConfiguration('Unable to create Nodemailer test account.')
if (!transport) {
throw new InvalidConfiguration('Unable to create Nodemailer test account.')
}
return {
defaultFromAddress: 'info@payloadcms.com',

View File

@@ -14,6 +14,7 @@ import { deepMerge } from './deepMerge.js'
const baseRules = {
// This rule makes no sense when overriding class methods. This is used a lot in richtext-lexical.
'class-methods-use-this': 'off',
curly: ['warn', 'all'],
'arrow-body-style': 0,
'import-x/prefer-default-export': 'off',
'no-restricted-exports': ['warn', { restrictDefaultExports: { direct: true } }],

View File

@@ -6,8 +6,12 @@ import type { Context } from '../types.js'
export function resetPassword(collection: Collection): any {
async function resolver(_, args, context: Context) {
if (args.locale) context.req.locale = args.locale
if (args.fallbackLocale) context.req.fallbackLocale = args.fallbackLocale
if (args.locale) {
context.req.locale = args.locale
}
if (args.fallbackLocale) {
context.req.fallbackLocale = args.fallbackLocale
}
const options = {
api: 'GraphQL',

View File

@@ -6,8 +6,12 @@ import type { Context } from '../types.js'
export function verifyEmail(collection: Collection) {
async function resolver(_, args, context: Context) {
if (args.locale) context.req.locale = args.locale
if (args.fallbackLocale) context.req.fallbackLocale = args.fallbackLocale
if (args.locale) {
context.req.locale = args.locale
}
if (args.fallbackLocale) {
context.req.fallbackLocale = args.fallbackLocale
}
const options = {
api: 'GraphQL',

View File

@@ -28,7 +28,9 @@ export function getDeleteResolver<TSlug extends CollectionSlug>(
req = isolateObjectProperty(req, 'fallbackLocale')
req.locale = args.locale || locale
req.fallbackLocale = args.fallbackLocale || fallbackLocale
if (!req.query) req.query = {}
if (!req.query) {
req.query = {}
}
const draft: boolean =
args.draft ?? req.query?.draft === 'false'
@@ -36,7 +38,9 @@ export function getDeleteResolver<TSlug extends CollectionSlug>(
: req.query?.draft === 'true'
? true
: undefined
if (typeof draft === 'boolean') req.query.draft = String(draft)
if (typeof draft === 'boolean') {
req.query.draft = String(draft)
}
context.req = req

View File

@@ -31,7 +31,9 @@ export function findResolver(collection: Collection): Resolver {
req = isolateObjectProperty(req, ['locale', 'fallbackLocale', 'transactionID'])
req.locale = args.locale || locale
req.fallbackLocale = args.fallbackLocale || fallbackLocale
if (!req.query) req.query = {}
if (!req.query) {
req.query = {}
}
const draft: boolean =
args.draft ?? req.query?.draft === 'false'
@@ -39,7 +41,9 @@ export function findResolver(collection: Collection): Resolver {
: req.query?.draft === 'true'
? true
: undefined
if (typeof draft === 'boolean') req.query.draft = String(draft)
if (typeof draft === 'boolean') {
req.query.draft = String(draft)
}
context.req = req

View File

@@ -28,7 +28,9 @@ export function findByIDResolver<TSlug extends CollectionSlug>(
req = isolateObjectProperty(req, 'fallbackLocale')
req.locale = args.locale || locale
req.fallbackLocale = args.fallbackLocale || fallbackLocale
if (!req.query) req.query = {}
if (!req.query) {
req.query = {}
}
const draft: boolean =
args.draft ?? req.query?.draft === 'false'
@@ -36,7 +38,9 @@ export function findByIDResolver<TSlug extends CollectionSlug>(
: req.query?.draft === 'true'
? true
: undefined
if (typeof draft === 'boolean') req.query.draft = String(draft)
if (typeof draft === 'boolean') {
req.query.draft = String(draft)
}
context.req = req

View File

@@ -29,7 +29,9 @@ export function findVersionsResolver(collection: Collection): Resolver {
req = isolateObjectProperty(req, 'fallbackLocale')
req.locale = args.locale || locale
req.fallbackLocale = args.fallbackLocale || fallbackLocale
if (!req.query) req.query = {}
if (!req.query) {
req.query = {}
}
const draft: boolean =
args.draft ?? req.query?.draft === 'false'
@@ -37,7 +39,9 @@ export function findVersionsResolver(collection: Collection): Resolver {
: req.query?.draft === 'true'
? true
: undefined
if (typeof draft === 'boolean') req.query.draft = String(draft)
if (typeof draft === 'boolean') {
req.query.draft = String(draft)
}
context.req = req

View File

@@ -30,7 +30,9 @@ export function updateResolver<TSlug extends CollectionSlug>(
req = isolateObjectProperty(req, 'fallbackLocale')
req.locale = args.locale || locale
req.fallbackLocale = args.fallbackLocale || fallbackLocale
if (!req.query) req.query = {}
if (!req.query) {
req.query = {}
}
const draft: boolean =
args.draft ?? req.query?.draft === 'false'
@@ -38,7 +40,9 @@ export function updateResolver<TSlug extends CollectionSlug>(
: req.query?.draft === 'true'
? true
: undefined
if (typeof draft === 'boolean') req.query.draft = String(draft)
if (typeof draft === 'boolean') {
req.query.draft = String(draft)
}
context.req = req

View File

@@ -6,8 +6,12 @@ import type { Context } from '../types.js'
export function findOne(globalConfig: SanitizedGlobalConfig): Document {
return async function resolver(_, args, context: Context) {
if (args.locale) context.req.locale = args.locale
if (args.fallbackLocale) context.req.fallbackLocale = args.fallbackLocale
if (args.locale) {
context.req.locale = args.locale
}
if (args.fallbackLocale) {
context.req.fallbackLocale = args.fallbackLocale
}
const { slug } = globalConfig

View File

@@ -19,8 +19,12 @@ export type Resolver = (
export function findVersionByID(globalConfig: SanitizedGlobalConfig): Resolver {
return async function resolver(_, args, context: Context) {
if (args.locale) context.req.locale = args.locale
if (args.fallbackLocale) context.req.fallbackLocale = args.fallbackLocale
if (args.locale) {
context.req.locale = args.locale
}
if (args.fallbackLocale) {
context.req.fallbackLocale = args.fallbackLocale
}
const options = {
id: args.id,

View File

@@ -22,8 +22,12 @@ export function update<TSlug extends GlobalSlug>(
globalConfig: SanitizedGlobalConfig,
): Resolver<TSlug> {
return async function resolver(_, args, context: Context) {
if (args.locale) context.req.locale = args.locale
if (args.fallbackLocale) context.req.fallbackLocale = args.fallbackLocale
if (args.locale) {
context.req.locale = args.locale
}
if (args.fallbackLocale) {
context.req.fallbackLocale = args.fallbackLocale
}
const { slug } = globalConfig

View File

@@ -97,7 +97,9 @@ export function buildMutationInputType({
parentName: fullName,
})
if (!type) return inputObjectTypeConfig
if (!type) {
return inputObjectTypeConfig
}
type = new GraphQLList(withNullableType(field, type, forceNullable))
return {
@@ -120,7 +122,9 @@ export function buildMutationInputType({
collapsible: (inputObjectTypeConfig: InputObjectTypeConfig, field: CollapsibleField) =>
field.fields.reduce((acc, subField: CollapsibleField) => {
const addSubField = fieldToSchemaMap[subField.type]
if (addSubField) return addSubField(acc, subField)
if (addSubField) {
return addSubField(acc, subField)
}
return acc
}, inputObjectTypeConfig),
date: (inputObjectTypeConfig: InputObjectTypeConfig, field: DateField) => ({
@@ -142,9 +146,13 @@ export function buildMutationInputType({
parentName: fullName,
})
if (!type) return inputObjectTypeConfig
if (!type) {
return inputObjectTypeConfig
}
if (requiresAtLeastOneField) type = new GraphQLNonNull(type)
if (requiresAtLeastOneField) {
type = new GraphQLNonNull(type)
}
return {
...inputObjectTypeConfig,
[field.name]: { type },
@@ -227,7 +235,9 @@ export function buildMutationInputType({
row: (inputObjectTypeConfig: InputObjectTypeConfig, field: RowField) =>
field.fields.reduce((acc, subField: Field) => {
const addSubField = fieldToSchemaMap[subField.type]
if (addSubField) return addSubField(acc, subField)
if (addSubField) {
return addSubField(acc, subField)
}
return acc
}, inputObjectTypeConfig),
select: (inputObjectTypeConfig: InputObjectTypeConfig, field: SelectField) => {
@@ -274,9 +284,13 @@ export function buildMutationInputType({
parentName: fullName,
})
if (!type) return acc
if (!type) {
return acc
}
if (requiresAtLeastOneField) type = new GraphQLNonNull(type)
if (requiresAtLeastOneField) {
type = new GraphQLNonNull(type)
}
return {
...acc,
[tab.name]: { type },
@@ -287,7 +301,9 @@ export function buildMutationInputType({
...acc,
...tab.fields.reduce((subFieldSchema, subField) => {
const addSubField = fieldToSchemaMap[subField.type]
if (addSubField) return addSubField(subFieldSchema, subField)
if (addSubField) {
return addSubField(subFieldSchema, subField)
}
return subFieldSchema
}, acc),
}

View File

@@ -171,7 +171,9 @@ export function buildObjectType({
collapsible: (objectTypeConfig: ObjectTypeConfig, field: CollapsibleField) =>
field.fields.reduce((objectTypeConfigWithCollapsibleFields, subField) => {
const addSubField = fieldToSchemaMap[subField.type]
if (addSubField) return addSubField(objectTypeConfigWithCollapsibleFields, subField)
if (addSubField) {
return addSubField(objectTypeConfigWithCollapsibleFields, subField)
}
return objectTypeConfigWithCollapsibleFields
}, objectTypeConfig),
date: (objectTypeConfig: ObjectTypeConfig, field: DateField) => ({
@@ -459,7 +461,9 @@ export function buildObjectType({
},
async resolve(parent, args, context: Context) {
let depth = config.defaultDepth
if (typeof args.depth !== 'undefined') depth = args.depth
if (typeof args.depth !== 'undefined') {
depth = args.depth
}
if (!field?.editor) {
throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor
}
@@ -506,7 +510,9 @@ export function buildObjectType({
row: (objectTypeConfig: ObjectTypeConfig, field: RowField) =>
field.fields.reduce((objectTypeConfigWithRowFields, subField) => {
const addSubField = fieldToSchemaMap[subField.type]
if (addSubField) return addSubField(objectTypeConfigWithRowFields, subField)
if (addSubField) {
return addSubField(objectTypeConfigWithRowFields, subField)
}
return objectTypeConfigWithRowFields
}, objectTypeConfig),
select: (objectTypeConfig: ObjectTypeConfig, field: SelectField) => {
@@ -560,7 +566,9 @@ export function buildObjectType({
...tabSchema,
...tab.fields.reduce((subFieldSchema, subField) => {
const addSubField = fieldToSchemaMap[subField.type]
if (addSubField) return addSubField(subFieldSchema, subField)
if (addSubField) {
return addSubField(subFieldSchema, subField)
}
return subFieldSchema
}, tabSchema),
}

View File

@@ -148,7 +148,9 @@ export function buildPolicyType(args: BuildPolicyType): GraphQLObjectType {
let operations = []
if (graphQL === false) return null
if (graphQL === false) {
return null
}
if (type === 'collection') {
operations = ['create', 'read', 'update', 'delete']

View File

@@ -57,7 +57,9 @@ export function initCollections({ config, graphqlResult }: InitCollectionsGraphQ
config: { fields, graphQL = {} as SanitizedCollectionConfig['graphQL'], versions },
} = collection
if (!graphQL) return
if (!graphQL) {
return
}
let singularName
let pluralName

View File

@@ -36,7 +36,9 @@ export function initGlobals({ config, graphqlResult }: InitGlobalsGraphQLArgs):
const forceNullableObjectType = Boolean(versions?.drafts)
if (!graphqlResult.globals.graphQL) graphqlResult.globals.graphQL = {}
if (!graphqlResult.globals.graphQL) {
graphqlResult.globals.graphQL = {}
}
const updateMutationInputType = buildMutationInputType({
name: formattedName,

View File

@@ -263,7 +263,9 @@ export const withOperators = (
field: FieldAffectingData,
parentName: string,
): GraphQLInputObjectType => {
if (!defaults?.[field.type]) throw new Error(`Error: ${field.type} has no defaults configured.`)
if (!defaults?.[field.type]) {
throw new Error(`Error: ${field.type} has no defaults configured.`)
}
const name = `${combineParentName(parentName, field.name)}_operator`

View File

@@ -4,7 +4,10 @@ const fs = require('fs')
const ReactCompilerConfig = {
sources: (filename) => {
const isInNodeModules = filename.includes('node_modules')
if (isInNodeModules || ( !filename.endsWith('.tsx') && !filename.endsWith('.jsx') && !filename.endsWith('.js'))) {
if (
isInNodeModules ||
(!filename.endsWith('.tsx') && !filename.endsWith('.jsx') && !filename.endsWith('.js'))
) {
return false
}

View File

@@ -40,9 +40,13 @@ export const DocumentTabs: React.FC<{
// if no `order`, append the view to the end
// TODO: open `order` to the config and merge `defaultViews` with `customViews`
?.sort(([, a], [, b]) => {
if (a.order === undefined && b.order === undefined) return 0
else if (a.order === undefined) return 1
else if (b.order === undefined) return -1
if (a.order === undefined && b.order === undefined) {
return 0
} else if (a.order === undefined) {
return 1
} else if (b.order === undefined) {
return -1
}
return a.order - b.order
})
?.map(([name, tab], index) => {

View File

@@ -12,7 +12,7 @@ export const VersionsPill: React.FC = () => {
// documents that are version enabled _always_ have at least one version
const hasVersions = versions?.totalDocs > 0
if (hasVersions)
if (hasVersions) {
return (
<span
className={[`${baseClass}__count`, hasVersions ? `${baseClass}__count--has-count` : '']
@@ -22,4 +22,5 @@ export const VersionsPill: React.FC = () => {
{versions.totalDocs.toString()}
</span>
)
}
}

View File

@@ -25,8 +25,11 @@ const Component: React.FC<{
// }, [modalState, isActive, onCancel])
useEffect(() => {
if (isActive) openModal(modalSlug)
else closeModal(modalSlug)
if (isActive) {
openModal(modalSlug)
} else {
closeModal(modalSlug)
}
}, [isActive, openModal, closeModal])
return (

View File

@@ -145,7 +145,9 @@ export const usePreventLeave = ({
useEffect(() => {
if (hasAccepted && cancelledURL.current) {
if (onAccept) onAccept()
if (onAccept) {
onAccept()
}
router.push(cancelledURL.current)
}
}, [hasAccepted, onAccept, router])

View File

@@ -55,7 +55,9 @@ export const tempFileHandler: Handler = (options, fieldname, filename) => {
complete: () => {
completed = true
debugLog(options, `Upload ${fieldname}->${filename} completed, bytes:${fileSize}.`)
if (writeStream instanceof WriteStream) writeStream.end()
if (writeStream instanceof WriteStream) {
writeStream.end()
}
// Return empty buff since data was uploaded into a temp file.
return Buffer.concat([])
},

View File

@@ -1,7 +1,9 @@
import { isSafeFromPollution } from './utilities.js'
export const processNested = function (data) {
if (!data || data.length < 1) return Object.create(null)
if (!data || data.length < 1) {
return Object.create(null)
}
const d = Object.create(null),
keys = Object.keys(data)
@@ -23,7 +25,9 @@ export const processNested = function (data) {
if (index >= keyParts.length - 1) {
current[k] = value
} else {
if (!current[k]) current[k] = !keyParts[index + 1] ? [] : Object.create(null)
if (!current[k]) {
current[k] = !keyParts[index + 1] ? [] : Object.create(null)
}
current = current[k]
}
}

View File

@@ -15,7 +15,9 @@ export const createUploadTimer: CreateUploadTimer = (timeout = 0, callback = ()
const set = () => {
// Do not start a timer if zero timeout or it hasn't been set.
if (!timeout) return false
if (!timeout) {
return false
}
clear()
timer = setTimeout(callback, timeout)
return true

View File

@@ -18,7 +18,9 @@ let tempCounter = 0
*/
export const debugLog = (options: FetchAPIFileUploadOptions, msg: string) => {
const opts = options || {}
if (!opts.debug) return false
if (!opts.debug) {
return false
}
console.log(`Next-file-upload: ${msg}`) // eslint-disable-line
return true
}
@@ -84,7 +86,9 @@ export const isSafeFromPollution: IsSafeFromPollution = (base, key) => {
type BuildFields = (instance: any, field: string, value: any) => any
export const buildFields: BuildFields = (instance, field, value) => {
// Do nothing if value is not set.
if (value === null || value === undefined) return instance
if (value === null || value === undefined) {
return instance
}
instance = instance || Object.create(null)
if (!isSafeFromPollution(instance, field)) {
@@ -110,11 +114,15 @@ export const buildFields: BuildFields = (instance, field, value) => {
*/
type CheckAndMakeDir = (fileUploadOptions: FetchAPIFileUploadOptions, filePath: string) => boolean
export const checkAndMakeDir: CheckAndMakeDir = (fileUploadOptions, filePath) => {
if (!fileUploadOptions.createParentPath) return false
if (!fileUploadOptions.createParentPath) {
return false
}
// Check whether folder for the file exists.
const parentPath = path.dirname(filePath)
// Create folder if it doesn't exist.
if (!fs.existsSync(parentPath)) fs.mkdirSync(parentPath, { recursive: true })
if (!fs.existsSync(parentPath)) {
fs.mkdirSync(parentPath, { recursive: true })
}
// Checks folder again and return a results.
return fs.existsSync(parentPath)
}
@@ -134,7 +142,9 @@ const copyFile: CopyFile = (src, dst, callback) => {
// cbCalled flag and runCb helps to run cb only once.
let cbCalled = false
const runCb = (err?: Error) => {
if (cbCalled) return
if (cbCalled) {
return
}
cbCalled = true
callback(err)
}
@@ -247,14 +257,18 @@ export const parseFileNameExtension: ParseFileNameExtension = (preserveExtension
name: fileName,
extension: '',
}
if (!preserveExtension) return defaultResult
if (!preserveExtension) {
return defaultResult
}
// Define maximum extension length
const maxExtLength =
typeof preserveExtension === 'boolean' ? MAX_EXTENSION_LENGTH : preserveExtension
const nameParts = fileName.split('.')
if (nameParts.length < 2) return defaultResult
if (nameParts.length < 2) {
return defaultResult
}
let extension = nameParts.pop()
if (extension.length > maxExtLength && maxExtLength > 0) {
@@ -274,13 +288,17 @@ export const parseFileNameExtension: ParseFileNameExtension = (preserveExtension
type ParseFileName = (opts: FetchAPIFileUploadOptions, fileName: string) => string
export const parseFileName: ParseFileName = (opts, fileName) => {
// Check fileName argument
if (!fileName || typeof fileName !== 'string') return getTempFilename()
if (!fileName || typeof fileName !== 'string') {
return getTempFilename()
}
// Cut off file name if it's length more then 255.
let parsedName = fileName.length <= 255 ? fileName : fileName.substr(0, 255)
// Decode file name if uriDecodeFileNames option set true.
parsedName = uriDecodeFileName(opts, parsedName)
// Stop parsing file name if safeFileNames options hasn't been set.
if (!opts.safeFileNames) return parsedName
if (!opts.safeFileNames) {
return parsedName
}
// Set regular expression for the file name.
const nameRegex =
typeof opts.safeFileNames === 'object' && opts.safeFileNames instanceof RegExp
@@ -288,8 +306,9 @@ export const parseFileName: ParseFileName = (opts, fileName) => {
: SAFE_FILE_NAME_REGEX
// Parse file name extension.
const parsedFileName = parseFileNameExtension(opts.preserveExtension, parsedName)
if (parsedFileName.extension.length)
if (parsedFileName.extension.length) {
parsedFileName.extension = '.' + parsedFileName.extension.replace(nameRegex, '')
}
return parsedFileName.name.replace(nameRegex, '').concat(parsedFileName.extension)
}

View File

@@ -35,8 +35,12 @@ export const updateByID: CollectionRouteHandlerWithID = async ({
let message = req.t('general:updatedSuccessfully')
if (draft) message = req.t('version:draftSavedSuccessfully')
if (autosave) message = req.t('version:autosavedSuccessfully')
if (draft) {
message = req.t('version:draftSavedSuccessfully')
}
if (autosave) {
message = req.t('version:autosavedSuccessfully')
}
return Response.json(
{

View File

@@ -15,7 +15,9 @@ export async function checkFileAccess({
}): Promise<Response | TypeWithID> {
const { config } = collection
const disableEndpoints = endpointsAreDisabled({ endpoints: config.endpoints, request: req })
if (disableEndpoints) return disableEndpoints
if (disableEndpoints) {
return disableEndpoints
}
const accessResult = await executeAccess({ isReadingStaticFile: true, req }, config.access.read)

View File

@@ -33,7 +33,9 @@ export const getFile = async ({ collection, filename, req }: Args): Promise<Resp
req,
})
if (accessResult instanceof Response) return accessResult
if (accessResult instanceof Response) {
return accessResult
}
if (collection.config.upload.handlers?.length) {
let customResponse = null
@@ -47,7 +49,9 @@ export const getFile = async ({ collection, filename, req }: Args): Promise<Resp
})
}
if (customResponse instanceof Response) return customResponse
if (customResponse instanceof Response) {
return customResponse
}
}
const fileDir = collection.config.upload?.staticDir || collection.config.slug

View File

@@ -24,8 +24,12 @@ export const update: GlobalRouteHandler = async ({ globalConfig, req }) => {
let message = req.t('general:updatedSuccessfully')
if (draft) message = req.t('version:draftSavedSuccessfully')
if (autosave) message = req.t('version:autosavedSuccessfully')
if (draft) {
message = req.t('version:draftSavedSuccessfully')
}
if (autosave) {
message = req.t('version:autosavedSuccessfully')
}
return Response.json(
{

View File

@@ -246,7 +246,9 @@ export const GET =
request,
})
if (disableEndpoints) return disableEndpoints
if (disableEndpoints) {
return disableEndpoints
}
collection = req.payload.collections?.[slug1]
@@ -256,7 +258,9 @@ export const GET =
endpoints: collection.config.endpoints,
request,
})
if (disableEndpoints) return disableEndpoints
if (disableEndpoints) {
return disableEndpoints
}
const customEndpointResponse = await handleCustomEndpoints({
endpoints: collection.config.endpoints,
@@ -327,7 +331,9 @@ export const GET =
endpoints: globalConfig.endpoints,
request,
})
if (disableEndpoints) return disableEndpoints
if (disableEndpoints) {
return disableEndpoints
}
const customEndpointResponse = await handleCustomEndpoints({
endpoints: globalConfig.endpoints,
@@ -403,7 +409,9 @@ export const GET =
req,
})
if (customEndpointResponse) return customEndpointResponse
if (customEndpointResponse) {
return customEndpointResponse
}
return RouteNotFoundResponse({
slug,
@@ -445,7 +453,9 @@ export const POST =
request,
})
if (disableEndpoints) return disableEndpoints
if (disableEndpoints) {
return disableEndpoints
}
if (collection) {
req.routeParams.collection = slug1
@@ -453,7 +463,9 @@ export const POST =
endpoints: collection.config.endpoints,
request,
})
if (disableEndpoints) return disableEndpoints
if (disableEndpoints) {
return disableEndpoints
}
const customEndpointResponse = await handleCustomEndpoints({
endpoints: collection.config.endpoints,
@@ -516,7 +528,9 @@ export const POST =
endpoints: globalConfig.endpoints,
request,
})
if (disableEndpoints) return disableEndpoints
if (disableEndpoints) {
return disableEndpoints
}
const customEndpointResponse = await handleCustomEndpoints({
endpoints: globalConfig.endpoints,
@@ -585,7 +599,9 @@ export const POST =
req,
})
if (customEndpointResponse) return customEndpointResponse
if (customEndpointResponse) {
return customEndpointResponse
}
return RouteNotFoundResponse({
slug,
@@ -620,7 +636,9 @@ export const DELETE =
endpoints: req.payload.config.endpoints,
request,
})
if (disableEndpoints) return disableEndpoints
if (disableEndpoints) {
return disableEndpoints
}
if (collection) {
req.routeParams.collection = slug1
@@ -629,7 +647,9 @@ export const DELETE =
endpoints: collection.config.endpoints,
request,
})
if (disableEndpoints) return disableEndpoints
if (disableEndpoints) {
return disableEndpoints
}
const customEndpointResponse = await handleCustomEndpoints({
endpoints: collection.config.endpoints,
@@ -679,7 +699,9 @@ export const DELETE =
req,
})
if (customEndpointResponse) return customEndpointResponse
if (customEndpointResponse) {
return customEndpointResponse
}
return RouteNotFoundResponse({
slug,
@@ -714,7 +736,9 @@ export const PATCH =
endpoints: req.payload.config.endpoints,
request,
})
if (disableEndpoints) return disableEndpoints
if (disableEndpoints) {
return disableEndpoints
}
if (collection) {
req.routeParams.collection = slug1
@@ -723,7 +747,9 @@ export const PATCH =
endpoints: collection.config.endpoints,
request,
})
if (disableEndpoints) return disableEndpoints
if (disableEndpoints) {
return disableEndpoints
}
const customEndpointResponse = await handleCustomEndpoints({
endpoints: collection.config.endpoints,
@@ -774,7 +800,9 @@ export const PATCH =
req,
})
if (customEndpointResponse) return customEndpointResponse
if (customEndpointResponse) {
return customEndpointResponse
}
return RouteNotFoundResponse({
slug,

View File

@@ -14,10 +14,14 @@ export const sanitizeCollectionID = ({ id, collectionSlug, payload }: Args): num
let shouldSanitize = Boolean(payload.db.defaultIDType === 'number')
// UNLESS the customIDType for this collection is text.... then we leave it
if (shouldSanitize && collection.customIDType === 'text') shouldSanitize = false
if (shouldSanitize && collection.customIDType === 'text') {
shouldSanitize = false
}
// If we still should sanitize, parse float
if (shouldSanitize) sanitizedID = parseFloat(sanitizedID)
if (shouldSanitize) {
sanitizedID = parseFloat(sanitizedID)
}
return sanitizedID
}

View File

@@ -15,7 +15,6 @@
}
&--nav-open {
.template-default {
&__nav-overlay {
transition: opacity var(--nav-trans-time) linear;

View File

@@ -31,8 +31,12 @@ export function addLocalesToRequestFromData(req: PayloadRequest): void {
localization: config.localization,
})
if (locale) req.locale = locale
if (fallbackLocale) req.fallbackLocale = fallbackLocale
if (locale) {
req.locale = locale
}
if (fallbackLocale) {
req.fallbackLocale = fallbackLocale
}
}
}

View File

@@ -69,8 +69,12 @@ export const createPayloadRequest = async ({
fallbackLocale = locales.fallbackLocale
// Override if query params are present, in order to respect HTTP method override
if (query.locale) locale = query.locale
if (query?.['fallback-locale']) fallbackLocale = query['fallback-locale']
if (query.locale) {
locale = query.locale
}
if (query?.['fallback-locale']) {
fallbackLocale = query['fallback-locale']
}
}
const customRequest: CustomPayloadRequestProperties = {
@@ -110,7 +114,9 @@ export const createPayloadRequest = async ({
req.user = user
if (responseHeaders) req.responseHeaders = responseHeaders
if (responseHeaders) {
req.responseHeaders = responseHeaders
}
return req
}

View File

@@ -23,7 +23,9 @@ export const handleAuthRedirect = ({
} = config
if (!isAdminAuthRoute({ adminRoute, config, route })) {
if (searchParams && 'redirect' in searchParams) delete searchParams.redirect
if (searchParams && 'redirect' in searchParams) {
delete searchParams.redirect
}
const redirectRoute = encodeURIComponent(
route + Object.keys(searchParams ?? {}).length

View File

@@ -117,7 +117,9 @@ export const initPage = async ({
locale = findLocaleFromCode(localization, localeCode)
if (!locale) locale = findLocaleFromCode(localization, defaultLocaleCode)
if (!locale) {
locale = findLocaleFromCode(localization, defaultLocaleCode)
}
req.locale = locale.code
}

View File

@@ -1,5 +1,7 @@
export const timestamp = (label: string) => {
if (!process.env.PAYLOAD_TIME) process.env.PAYLOAD_TIME = String(new Date().getTime())
if (!process.env.PAYLOAD_TIME) {
process.env.PAYLOAD_TIME = String(new Date().getTime())
}
const now = new Date()
console.log(`[${now.getTime() - Number(process.env.PAYLOAD_TIME)}ms] ${label}`)
}

View File

@@ -1,6 +1,11 @@
import type { AdminViewProps } from 'payload'
import { DocumentInfoProvider, EditDepthProvider, HydrateAuthProvider, RenderComponent } from '@payloadcms/ui'
import {
DocumentInfoProvider,
EditDepthProvider,
HydrateAuthProvider,
RenderComponent,
} from '@payloadcms/ui'
import { getCreateMappedComponent } from '@payloadcms/ui/shared'
import { notFound } from 'next/navigation.js'
import React from 'react'
@@ -92,7 +97,6 @@ export const Account: React.FC<AdminViewProps> = async ({
isEditing
>
<EditDepthProvider depth={1}>
<DocumentHeader
collectionConfig={collectionConfig}
hideTabs

View File

@@ -91,7 +91,9 @@ export const SetDocumentStepNav: React.FC<{
})
}
if (drawerDepth <= 1) setStepNav(nav)
if (drawerDepth <= 1) {
setStepNav(nav)
}
}
}, [
setStepNav,

View File

@@ -95,8 +95,12 @@ export const DefaultEditView: React.FC = () => {
const classes = [baseClass, id && `${baseClass}--is-editing`]
if (globalSlug) classes.push(`global-edit--${globalSlug}`)
if (collectionSlug) classes.push(`collection-edit--${collectionSlug}`)
if (globalSlug) {
classes.push(`global-edit--${globalSlug}`)
}
if (collectionSlug) {
classes.push(`collection-edit--${collectionSlug}`)
}
const [schemaPath, setSchemaPath] = React.useState(() => {
if (operation === 'create' && auth && !auth.disableLocalStrategy) {

View File

@@ -146,7 +146,9 @@ export const LivePreviewProvider: React.FC<LivePreviewProviderProps> = ({
(type: 'iframe' | 'popup') => {
setAppIsReady(false)
setPreviewWindowType(type)
if (type === 'popup') openPopupWindow()
if (type === 'popup') {
openPopupWindow()
}
},
[openPopupWindow],
)

View File

@@ -54,8 +54,11 @@ export const DeviceContainer: React.FC<{
if (deviceIsLargerThanFrame) {
if (zoom > 1) {
const differenceFromDeviceToFrame = measuredDeviceSize.width - outerFrameSize.width
if (differenceFromDeviceToFrame < 0) x = `${differenceFromDeviceToFrame / 2}px`
else x = '0'
if (differenceFromDeviceToFrame < 0) {
x = `${differenceFromDeviceToFrame / 2}px`
} else {
x = '0'
}
} else {
x = '0'
}

View File

@@ -24,7 +24,9 @@ export const PreviewFrameSizeInput: React.FC<{
(e: React.ChangeEvent<HTMLInputElement>) => {
let newValue = Number(e.target.value)
if (newValue < 0) newValue = 0
if (newValue < 0) {
newValue = 0
}
setInternalState(newValue)
setBreakpoint('custom')
@@ -46,8 +48,11 @@ export const PreviewFrameSizeInput: React.FC<{
// so we need to take the measurements provided by `actualDeviceSize` and sync internal state
useEffect(() => {
if (breakpoint === 'responsive' && measuredDeviceSize) {
if (axis === 'x') setInternalState(Number(measuredDeviceSize.width.toFixed(0)) * zoom)
else setInternalState(Number(measuredDeviceSize.height.toFixed(0)) * zoom)
if (axis === 'x') {
setInternalState(Number(measuredDeviceSize.width.toFixed(0)) * zoom)
} else {
setInternalState(Number(measuredDeviceSize.height.toFixed(0)) * zoom)
}
}
if (breakpoint !== 'responsive' && size) {

View File

@@ -40,8 +40,12 @@ export const LoginForm: React.FC<{
const canLoginWithUsername = authOptions.loginWithUsername
const [loginType] = React.useState<LoginFieldProps['type']>(() => {
if (canLoginWithEmail && canLoginWithUsername) return 'emailOrUsername'
if (canLoginWithUsername) return 'username'
if (canLoginWithEmail && canLoginWithUsername) {
return 'emailOrUsername'
}
if (canLoginWithUsername) {
return 'username'
}
return 'email'
})

View File

@@ -25,6 +25,10 @@ export const isPathMatchingRoute = ({
const match = regex.exec(currentRoute)
const viewRoute = match?.[0] || viewPath
if (exact) return currentRoute === viewRoute
if (!exact) return viewRoute.startsWith(currentRoute)
if (exact) {
return currentRoute === viewRoute
}
if (!exact) {
return viewRoute.startsWith(currentRoute)
}
}

View File

@@ -43,7 +43,9 @@ export const Verify: React.FC<AdminViewProps> = async ({
return redirect(formatAdminURL({ adminRoute, path: '/login' }))
} catch (e) {
// already verified
if (e?.status === 202) redirect(formatAdminURL({ adminRoute, path: '/login' }))
if (e?.status === 202) {
redirect(formatAdminURL({ adminRoute, path: '/login' }))
}
textToRender = req.t('authentication:unableToVerify')
}

View File

@@ -43,7 +43,9 @@ const Iterable: React.FC<DiffComponentProps> = ({
let fields: ClientField[] = []
if (field.type === 'array' && 'fields' in field) fields = field.fields
if (field.type === 'array' && 'fields' in field) {
fields = field.fields
}
if (field.type === 'blocks') {
fields = [

View File

@@ -55,7 +55,9 @@ const Select: React.FC<DiffComponentProps<SelectFieldClient>> = ({
}) => {
let placeholder = ''
if (version === comparison) placeholder = `[${i18n.t('general:noValue')}]`
if (version === comparison) {
placeholder = `[${i18n.t('general:noValue')}]`
}
const options = 'options' in field && field.options

View File

@@ -24,14 +24,20 @@ const Text: React.FC<DiffComponentProps<TextFieldClient>> = ({
}) => {
let placeholder = ''
if (version === comparison) placeholder = `[${i18n.t('general:noValue')}]`
if (version === comparison) {
placeholder = `[${i18n.t('general:noValue')}]`
}
let versionToRender = version
let comparisonToRender = comparison
if (isRichText) {
if (typeof version === 'object') versionToRender = JSON.stringify(version, null, 2)
if (typeof comparison === 'object') comparisonToRender = JSON.stringify(comparison, null, 2)
if (typeof version === 'object') {
versionToRender = JSON.stringify(version, null, 2)
}
if (typeof comparison === 'object') {
comparisonToRender = JSON.stringify(comparison, null, 2)
}
}
return (

View File

@@ -29,7 +29,9 @@ const RenderFieldsToDiff: React.FC<Props> = ({
return (
<div className={baseClass}>
{fields?.map((field, i) => {
if ('name' in field && field.name === 'id') return null
if ('name' in field && field.name === 'id') {
return null
}
const Component = diffComponents[field.type]
@@ -53,7 +55,9 @@ const RenderFieldsToDiff: React.FC<Props> = ({
const subFieldPermissions = fieldPermissions?.[fieldName]?.fields
if (hasPermission === false) return null
if (hasPermission === false) {
return null
}
const baseCellProps: FieldDiffProps = {
comparison: comparisonValue,

View File

@@ -48,7 +48,9 @@ export const SelectComparison: React.FC<Props> = (props) => {
const getResults = useCallback(
async ({ lastLoadedPage: lastLoadedPageArg }) => {
if (loadedAllOptionsRef.current) return
if (loadedAllOptionsRef.current) {
return
}
const query: {
[key: string]: unknown
where: Where

View File

@@ -14,7 +14,9 @@ export const SelectLocales: React.FC<Props> = ({ onChange, options, value }) =>
const format = (items) => {
return items.map((item) => {
if (typeof item.label === 'string') return item
if (typeof item.label === 'string') {
return item
}
if (typeof item.label !== 'string' && item.label[code]) {
return {
label: item.label[code],

View File

@@ -32,17 +32,19 @@ export const CreatedAtCell: React.FC<CreatedAtCellProps> = ({
let to: string
if (collectionSlug)
if (collectionSlug) {
to = formatAdminURL({
adminRoute,
path: `/collections/${collectionSlug}/${docID}/versions/${versionID}`,
})
}
if (globalSlug)
if (globalSlug) {
to = formatAdminURL({
adminRoute,
path: `/globals/${globalSlug}/versions/${versionID}`,
})
}
return (
<Link href={to}>

View File

@@ -23,7 +23,9 @@ const executeAccess = async (
})
if (!result) {
if (!disableErrors) throw new Forbidden(req.t)
if (!disableErrors) {
throw new Forbidden(req.t)
}
}
return result
@@ -33,7 +35,9 @@ const executeAccess = async (
return true
}
if (!disableErrors) throw new Forbidden(req.t)
if (!disableErrors) {
throw new Forbidden(req.t)
}
return false
}

View File

@@ -32,7 +32,9 @@ export const getBaseAuthFields = (authConfig: IncomingAuthType): Field[] => {
}
authFields.push(emailField)
if (usernameField) authFields.push(usernameField)
if (usernameField) {
authFields.push(usernameField)
}
authFields.push(...baseAuthFields)

View File

@@ -1,5 +1,7 @@
const isLocked = (date: number): boolean => {
if (!date) return false
if (!date) {
return false
}
return date > Date.now()
}
export default isLocked

View File

@@ -39,7 +39,9 @@ export const auth = async (args: Required<AuthArgs>): Promise<AuthResult> => {
req,
})
if (shouldCommit) await commitTransaction(req)
if (shouldCommit) {
await commitTransaction(req)
}
return {
permissions,

View File

@@ -128,7 +128,9 @@ export const forgotPasswordOperation = async <TSlug extends CollectionSlug>(
// We don't want to indicate specifically that an email was not found,
// as doing so could lead to the exposure of registered emails.
// Therefore, we prefer to fail silently.
if (!user) return null
if (!user) {
return null
}
user.resetPasswordToken = token
user.resetPasswordExpiration = new Date(expiration || Date.now() + 3600000).toISOString() // 1 hour
@@ -197,7 +199,9 @@ export const forgotPasswordOperation = async <TSlug extends CollectionSlug>(
result: token,
})
if (shouldCommit) await commitTransaction(req)
if (shouldCommit) {
await commitTransaction(req)
}
return token
} catch (error: unknown) {

View File

@@ -202,7 +202,9 @@ export const loginOperation = async <TSlug extends CollectionSlug>(
})
}
if (shouldCommit) await commitTransaction(req)
if (shouldCommit) {
await commitTransaction(req)
}
throw new AuthenticationError(req.t)
}
@@ -332,7 +334,9 @@ export const loginOperation = async <TSlug extends CollectionSlug>(
// Return results
// /////////////////////////////////////
if (shouldCommit) await commitTransaction(req)
if (shouldCommit) {
await commitTransaction(req)
}
return result
} catch (error: unknown) {

View File

@@ -18,9 +18,12 @@ export const logoutOperation = async (incomingArgs: Arguments): Promise<boolean>
req,
} = incomingArgs
if (!user) throw new APIError('No User', httpStatus.BAD_REQUEST)
if (user.collection !== collectionConfig.slug)
if (!user) {
throw new APIError('No User', httpStatus.BAD_REQUEST)
}
if (user.collection !== collectionConfig.slug) {
throw new APIError('Incorrect collection', httpStatus.FORBIDDEN)
}
await collectionConfig.hooks.afterLogout.reduce(async (priorHook, hook) => {
await priorHook

View File

@@ -69,8 +69,12 @@ export const meOperation = async (args: Arguments): Promise<MeOperationResult> =
if (currentToken) {
const decoded = jwt.decode(currentToken) as jwt.JwtPayload
if (decoded) result.exp = decoded.exp
if (!collection.config.auth.removeTokenFromResponses) result.token = currentToken
if (decoded) {
result.exp = decoded.exp
}
if (!collection.config.auth.removeTokenFromResponses) {
result.token = currentToken
}
}
}
}

View File

@@ -62,7 +62,9 @@ export const refreshOperation = async (incomingArgs: Arguments): Promise<Result>
},
} = args
if (!args.req.user) throw new Forbidden(args.req.t)
if (!args.req.user) {
throw new Forbidden(args.req.t)
}
const parsedURL = url.parse(args.req.url)
const isGraphQL = parsedURL.pathname === config.routes.graphQL
@@ -143,7 +145,9 @@ export const refreshOperation = async (incomingArgs: Arguments): Promise<Result>
// Return results
// /////////////////////////////////////
if (shouldCommit) await commitTransaction(req)
if (shouldCommit) {
await commitTransaction(req)
}
return result
} catch (error: unknown) {

View File

@@ -58,7 +58,9 @@ export const registerFirstUserOperation = async <TSlug extends CollectionSlug>(
req,
})
if (doc) throw new Forbidden(req.t)
if (doc) {
throw new Forbidden(req.t)
}
// /////////////////////////////////////
// Register first user
@@ -93,7 +95,9 @@ export const registerFirstUserOperation = async <TSlug extends CollectionSlug>(
req,
})
if (shouldCommit) await commitTransaction(req)
if (shouldCommit) {
await commitTransaction(req)
}
return {
exp,

View File

@@ -64,7 +64,9 @@ export const resetPasswordOperation = async (args: Arguments): Promise<Result> =
},
})
if (!user) throw new APIError('Token is either invalid or has expired.', httpStatus.FORBIDDEN)
if (!user) {
throw new APIError('Token is either invalid or has expired.', httpStatus.FORBIDDEN)
}
// TODO: replace this method
const { hash, salt } = await generatePasswordSaltHash({
@@ -108,7 +110,9 @@ export const resetPasswordOperation = async (args: Arguments): Promise<Result> =
overrideAccess,
req,
})
if (shouldCommit) await commitTransaction(req)
if (shouldCommit) {
await commitTransaction(req)
}
const result = {
token,

View File

@@ -102,7 +102,9 @@ export const unlockOperation = async <TSlug extends CollectionSlug>(
result = null
}
if (shouldCommit) await commitTransaction(req)
if (shouldCommit) {
await commitTransaction(req)
}
return result
} catch (error: unknown) {

View File

@@ -31,9 +31,12 @@ export const verifyEmailOperation = async (args: Args): Promise<boolean> => {
},
})
if (!user) throw new APIError('Verification token is invalid.', httpStatus.FORBIDDEN)
if (user && user._verified === true)
if (!user) {
throw new APIError('Verification token is invalid.', httpStatus.FORBIDDEN)
}
if (user && user._verified === true) {
throw new APIError('This account has already been activated.', httpStatus.ACCEPTED)
}
await req.payload.db.updateOne({
id: user.id,
@@ -46,7 +49,9 @@ export const verifyEmailOperation = async (args: Args): Promise<boolean> => {
req,
})
if (shouldCommit) await commitTransaction(req)
if (shouldCommit) {
await commitTransaction(req)
}
return true
} catch (error: unknown) {

View File

@@ -17,7 +17,9 @@ export const authenticateLocalStrategy = async ({ doc, password }: Args): Promis
if (typeof salt === 'string' && typeof hash === 'string') {
const res = await new Promise<Doc | null>((resolve, reject) => {
crypto.pbkdf2(password, salt, 25000, 512, 'sha256', (e, hashBuffer) => {
if (e) reject(null)
if (e) {
reject(null)
}
if (scmp(hashBuffer, Buffer.from(hash, 'hex'))) {
resolve(doc)

View File

@@ -78,7 +78,9 @@ export const registerLocalStrategy = async ({
const { hash, salt } = await generatePasswordSaltHash({ collection, password, req })
const sanitizedDoc = { ...doc }
if (sanitizedDoc.password) delete sanitizedDoc.password
if (sanitizedDoc.password) {
delete sanitizedDoc.password
}
return payload.db.create({
collection: collection.slug,

View File

@@ -15,7 +15,9 @@ export const resetLoginAttempts = async ({
payload,
req,
}: Args): Promise<void> => {
if (!('lockUntil' in doc && typeof doc.lockUntil === 'string') || doc.loginAttempts === 0) return
if (!('lockUntil' in doc && typeof doc.lockUntil === 'string') || doc.loginAttempts === 0) {
return
}
await payload.update({
id: doc.id,
collection: collection.slug,

View File

@@ -15,7 +15,9 @@ export async function generateTypes(
const shouldLog = options?.log ?? true
if (shouldLog) logger.info('Compiling TS types for Collections and Globals...')
if (shouldLog) {
logger.info('Compiling TS types for Collections and Globals...')
}
const jsonSchema = configToJSONSchema(config, config.db.defaultIDType)
@@ -54,5 +56,7 @@ export async function generateTypes(
}
fs.writeFileSync(outputFile, compiled)
if (shouldLog) logger.info(`Types written to ${outputFile}`)
if (shouldLog) {
logger.info(`Types written to ${outputFile}`)
}
}

View File

@@ -51,7 +51,9 @@ export const bin = async () => {
const configPath = findConfig()
const configPromise = await import(pathToFileURL(configPath).toString())
let config = await configPromise
if (config.default) config = await config.default
if (config.default) {
config = await config.default
}
const userBinScript = Array.isArray(config.bin)
? config.bin.find(({ key }) => key === script)

View File

@@ -50,8 +50,12 @@ export const sanitizeCollection = async (
let hasCreatedAt = null
sanitized.fields.some((field) => {
if (fieldAffectsData(field)) {
if (field.name === 'updatedAt') hasUpdatedAt = true
if (field.name === 'createdAt') hasCreatedAt = true
if (field.name === 'updatedAt') {
hasUpdatedAt = true
}
if (field.name === 'createdAt') {
hasCreatedAt = true
}
}
return hasCreatedAt && hasUpdatedAt
})
@@ -84,7 +88,9 @@ export const sanitizeCollection = async (
sanitized.labels = sanitized.labels || formatLabels(sanitized.slug)
if (sanitized.versions) {
if (sanitized.versions === true) sanitized.versions = { drafts: false }
if (sanitized.versions === true) {
sanitized.versions = { drafts: false }
}
if (sanitized.timestamps === false) {
throw new TimestampsRequired(collection)
@@ -113,7 +119,9 @@ export const sanitizeCollection = async (
}
if (sanitized.upload) {
if (sanitized.upload === true) sanitized.upload = {}
if (sanitized.upload === true) {
sanitized.upload = {}
}
// sanitize fields for reserved names
sanitizeUploadFields(sanitized.fields, sanitized)

View File

@@ -75,7 +75,9 @@ const batchAndLoadDocs =
let sanitizedID: number | string = id
if (idType === 'number') sanitizedID = parseFloat(id)
if (idType === 'number') {
sanitizedID = parseFloat(id)
}
if (isValidID(sanitizedID, idType)) {
return {

View File

@@ -364,7 +364,9 @@ export const createOperation = async <TSlug extends CollectionSlug>(
// Return results
// /////////////////////////////////////
if (shouldCommit) await commitTransaction(req)
if (shouldCommit) {
await commitTransaction(req)
}
return result
} catch (error: unknown) {

View File

@@ -261,7 +261,9 @@ export const deleteOperation = async <TSlug extends CollectionSlug>(
result,
})
if (shouldCommit) await commitTransaction(req)
if (shouldCommit) {
await commitTransaction(req)
}
return result
} catch (error: unknown) {

View File

@@ -102,8 +102,12 @@ export const deleteByIDOperation = async <TSlug extends CollectionSlug>(
where: combineQueries({ id: { equals: id } }, accessResults),
})
if (!docToDelete && !hasWhereAccess) throw new NotFound(req.t)
if (!docToDelete && hasWhereAccess) throw new Forbidden(req.t)
if (!docToDelete && !hasWhereAccess) {
throw new NotFound(req.t)
}
if (!docToDelete && hasWhereAccess) {
throw new Forbidden(req.t)
}
await deleteAssociatedFiles({
collectionConfig,
@@ -213,7 +217,9 @@ export const deleteByIDOperation = async <TSlug extends CollectionSlug>(
// 8. Return results
// /////////////////////////////////////
if (shouldCommit) await commitTransaction(req)
if (shouldCommit) {
await commitTransaction(req)
}
return result
} catch (error: unknown) {

View File

@@ -101,8 +101,12 @@ export const duplicateOperation = async <TSlug extends CollectionSlug>(
req,
})
if (!docWithLocales && !hasWherePolicy) throw new NotFound(req.t)
if (!docWithLocales && hasWherePolicy) throw new Forbidden(req.t)
if (!docWithLocales && !hasWherePolicy) {
throw new NotFound(req.t)
}
if (!docWithLocales && hasWherePolicy) {
throw new Forbidden(req.t)
}
// remove the createdAt timestamp and id to rely on the db to set the default it
delete docWithLocales.createdAt
@@ -324,7 +328,9 @@ export const duplicateOperation = async <TSlug extends CollectionSlug>(
// Return results
// /////////////////////////////////////
if (shouldCommit) await commitTransaction(req)
if (shouldCommit) {
await commitTransaction(req)
}
return result
} catch (error: unknown) {

View File

@@ -68,7 +68,9 @@ export const findByIDOperation = async <TSlug extends CollectionSlug>(
: true
// If errors are disabled, and access returns false, return null
if (accessResult === false) return null
if (accessResult === false) {
return null
}
const findOneArgs: FindOneArgs = {
collection: collectionConfig.slug,
@@ -83,7 +85,9 @@ export const findByIDOperation = async <TSlug extends CollectionSlug>(
// Find by ID
// /////////////////////////////////////
if (!findOneArgs.where.and[0].id) throw new NotFound(t)
if (!findOneArgs.where.and[0].id) {
throw new NotFound(t)
}
let result: DataFromCollectionSlug<TSlug> = await req.payload.db.findOne(findOneArgs)

View File

@@ -50,7 +50,9 @@ export const findVersionByIDOperation = async <TData extends TypeWithID = any>(
: true
// If errors are disabled, and access returns false, return null
if (accessResults === false) return null
if (accessResults === false) {
return null
}
const hasWhereAccess = typeof accessResults === 'object'
@@ -73,8 +75,12 @@ export const findVersionByIDOperation = async <TData extends TypeWithID = any>(
if (!result) {
if (!disableErrors) {
if (!hasWhereAccess) throw new NotFound(req.t)
if (hasWhereAccess) throw new Forbidden(req.t)
if (!hasWhereAccess) {
throw new NotFound(req.t)
}
if (hasWhereAccess) {
throw new Forbidden(req.t)
}
}
return null

View File

@@ -87,8 +87,12 @@ export const restoreVersionOperation = async <TData extends TypeWithID = any>(
const doc = await req.payload.db.findOne(findOneArgs)
if (!doc && !hasWherePolicy) throw new NotFound(req.t)
if (!doc && hasWherePolicy) throw new Forbidden(req.t)
if (!doc && !hasWherePolicy) {
throw new NotFound(req.t)
}
if (!doc && hasWherePolicy) {
throw new Forbidden(req.t)
}
// /////////////////////////////////////
// fetch previousDoc

View File

@@ -428,7 +428,9 @@ export const updateOperation = async <TSlug extends CollectionSlug>(
result,
})
if (shouldCommit) await commitTransaction(req)
if (shouldCommit) {
await commitTransaction(req)
}
return result
} catch (error: unknown) {

View File

@@ -127,8 +127,12 @@ export const updateByIDOperation = async <TSlug extends CollectionSlug>(
req,
})
if (!docWithLocales && !hasWherePolicy) throw new NotFound(req.t)
if (!docWithLocales && hasWherePolicy) throw new Forbidden(req.t)
if (!docWithLocales && !hasWherePolicy) {
throw new NotFound(req.t)
}
if (!docWithLocales && hasWherePolicy) {
throw new Forbidden(req.t)
}
const originalDoc = await afterRead({
collection: collectionConfig,
@@ -404,7 +408,9 @@ export const updateByIDOperation = async <TSlug extends CollectionSlug>(
// Return results
// /////////////////////////////////////
if (shouldCommit) await commitTransaction(req)
if (shouldCommit) {
await commitTransaction(req)
}
return result
} catch (error: unknown) {

View File

@@ -71,7 +71,9 @@ export const findConfig = (): string => {
: [configPath, srcPath, rootPath]
for (const searchPath of searchPaths) {
if (!searchPath) continue
if (!searchPath) {
continue
}
const configPath = findUpSync(
(dir) => {
@@ -106,13 +108,17 @@ export const findConfig = (): string => {
cwd: path.resolve(process.cwd(), 'dist'),
})
if (distConfigPath) return distConfigPath
if (distConfigPath) {
return distConfigPath
}
} else {
const srcConfigPath = findUpSync(['payload.config.js', 'payload.config.ts'], {
cwd: path.resolve(process.cwd(), 'src'),
})
if (srcConfigPath) return srcConfigPath
if (srcConfigPath) {
return srcConfigPath
}
}
throw new Error(

View File

@@ -173,13 +173,17 @@ export const sanitizeConfig = async (incomingConfig: Config): Promise<SanitizedC
}
// Get deduped list of upload adapters
if (!config.upload) config.upload = { adapters: [] }
if (!config.upload) {
config.upload = { adapters: [] }
}
config.upload.adapters = Array.from(
new Set(config.collections.map((c) => c.upload?.adapter).filter(Boolean)),
)
// Pass through the email config as is so adapters don't break
if (incomingConfig.email) config.email = incomingConfig.email
if (incomingConfig.email) {
config.email = incomingConfig.email
}
/*
Execute richText sanitization

View File

@@ -3,14 +3,20 @@ import type { Where } from '../types/index.js'
import { hasWhereAccessResult } from '../auth/index.js'
export const combineQueries = (where: Where, access: Where | boolean): Where => {
if (!where && !access) return {}
if (!where && !access) {
return {}
}
const result: Where = {
and: [],
}
if (where) result.and.push(where)
if (hasWhereAccessResult(access)) result.and.push(access)
if (where) {
result.and.push(where)
}
if (hasWhereAccessResult(access)) {
result.and.push(access)
}
return result
}

View File

@@ -154,7 +154,9 @@ export async function getLocalizedPaths({
lastIncompletePath.fields = flattenFields(lastIncompletePath.field.fields, false)
}
if (i + 1 === pathSegments.length) lastIncompletePath.complete = true
if (i + 1 === pathSegments.length) {
lastIncompletePath.complete = true
}
lastIncompletePath.path = currentPath
}
}

View File

@@ -41,7 +41,9 @@ export const readMigrationFiles = async ({
typeof require === 'function'
? await eval(`require('${filePath.replaceAll('\\', '/')}')`)
: await eval(`import('${pathToFileURL(filePath).href}')`)
if ('default' in migration) migration = migration.default
if ('default' in migration) {
migration = migration.default
}
const result: Migration = {
name: path.basename(filePath).split('.')?.[0],

View File

@@ -53,7 +53,9 @@ export const sanitizeFields = async ({
richTextSanitizationPromises,
validRelationships,
}: Args): Promise<Field[]> => {
if (!fields) return []
if (!fields) {
return []
}
for (let i = 0; i < fields.length; i++) {
const field = fields[i]
@@ -62,7 +64,9 @@ export const sanitizeFields = async ({
continue
}
if (!field.type) throw new MissingFieldType(field)
if (!field.type) {
throw new MissingFieldType(field)
}
// assert that field names do not contain forbidden characters
if (fieldAffectsData(field) && field.name.includes('.')) {
@@ -160,8 +164,12 @@ export const sanitizeFields = async ({
}
}
if (!field.hooks) field.hooks = {}
if (!field.access) field.access = {}
if (!field.hooks) {
field.hooks = {}
}
if (!field.access) {
field.access = {}
}
setDefaultBeforeDuplicate(field)
}

View File

@@ -58,7 +58,9 @@ export async function afterRead<T extends JsonObject>(args: Args<T>): Promise<T>
incomingDepth || incomingDepth === 0
? parseInt(String(incomingDepth), 10)
: req.payload.config.defaultDepth
if (depth > req.payload.config.maxDepth) depth = req.payload.config.maxDepth
if (depth > req.payload.config.maxDepth) {
depth = req.payload.config.maxDepth
}
const currentDepth = incomingCurrentDepth || 1

View File

@@ -313,7 +313,9 @@ export const promise = async ({
switch (field.type) {
case 'group': {
let groupDoc = siblingDoc[field.name] as JsonObject
if (typeof siblingDoc[field.name] !== 'object') groupDoc = {}
if (typeof siblingDoc[field.name] !== 'object') {
groupDoc = {}
}
traverseFields({
collection,
@@ -524,7 +526,9 @@ export const promise = async ({
let tabDoc = siblingDoc
if (tabHasName(field)) {
tabDoc = siblingDoc[field.name] as JsonObject
if (typeof siblingDoc[field.name] !== 'object') tabDoc = {}
if (typeof siblingDoc[field.name] !== 'object') {
tabDoc = {}
}
}
traverseFields({

View File

@@ -10,13 +10,17 @@ export const getExistingRowDoc = (incomingRow: JsonObject, existingRows?: unknow
if (incomingRow.id && Array.isArray(existingRows)) {
const matchedExistingRow = existingRows.find((existingRow) => {
if (typeof existingRow === 'object' && 'id' in existingRow) {
if (existingRow.id === incomingRow.id) return existingRow
if (existingRow.id === incomingRow.id) {
return existingRow
}
}
return false
})
if (matchedExistingRow) return matchedExistingRow
if (matchedExistingRow) {
return matchedExistingRow
}
}
return {}

Some files were not shown because too many files have changed in this diff Show More