fix(plugin-import-export): incorrect config extension of jobs (#12730)
### What? In a project that has `jobs` configured and the import/export plugin will error on start: `payload-jobs validation failed: taskSlug: createCollectionExport is not a valid enum value for path taskSlug.` ### Why? The plugin was not properly extending the jobs configuration. ### How? Properly extend existing config.jobs to add the `createCollectionExport` task. Fixes #
This commit is contained in:
@@ -10,7 +10,7 @@ import { getCustomFieldFunctions } from './getCustomFieldFunctions.js'
|
||||
import { getFilename } from './getFilename.js'
|
||||
import { getSelect } from './getSelect.js'
|
||||
|
||||
type Export = {
|
||||
export type Export = {
|
||||
collectionSlug: string
|
||||
/**
|
||||
* If true, enables debug logging
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import type { Config, TaskHandler, User } from 'payload'
|
||||
import type { Config, TaskConfig, User } from 'payload'
|
||||
|
||||
import type { CreateExportArgs } from './createExport.js'
|
||||
import type { CreateExportArgs, Export } from './createExport.js'
|
||||
|
||||
import { createExport } from './createExport.js'
|
||||
import { getFields } from './getFields.js'
|
||||
|
||||
export const getCreateCollectionExportTask = (config: Config): TaskHandler<any, string> => {
|
||||
export const getCreateCollectionExportTask = (
|
||||
config: Config,
|
||||
): TaskConfig<{
|
||||
input: Export
|
||||
output: object
|
||||
}> => {
|
||||
const inputSchema = getFields(config).concat(
|
||||
{
|
||||
name: 'user',
|
||||
@@ -22,7 +27,6 @@ export const getCreateCollectionExportTask = (config: Config): TaskHandler<any,
|
||||
)
|
||||
|
||||
return {
|
||||
// @ts-expect-error plugin tasks cannot have predefined type slug
|
||||
slug: 'createCollectionExport',
|
||||
handler: async ({ input, req }: CreateExportArgs) => {
|
||||
let user: undefined | User
|
||||
@@ -41,15 +45,9 @@ export const getCreateCollectionExportTask = (config: Config): TaskHandler<any,
|
||||
await createExport({ input, req, user })
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {},
|
||||
}
|
||||
},
|
||||
inputSchema,
|
||||
outputSchema: [
|
||||
{
|
||||
name: 'success',
|
||||
type: 'checkbox',
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,11 +28,7 @@ export const importExportPlugin =
|
||||
)
|
||||
|
||||
// inject the createExport job into the config
|
||||
config.jobs =
|
||||
config.jobs ||
|
||||
({
|
||||
tasks: [getCreateCollectionExportTask(config)],
|
||||
} as unknown as JobsConfig) // cannot type jobs config inside of plugins
|
||||
;((config.jobs ??= {}).tasks ??= []).push(getCreateCollectionExportTask(config))
|
||||
|
||||
let collectionsToUpdate = config.collections
|
||||
|
||||
|
||||
Reference in New Issue
Block a user