Skip to content

Commit

Permalink
fix: queues types with strict: true (#9281)
Browse files Browse the repository at this point in the history
Fixes types for workflows / jobs `input` and `output` when using
`strict: true` or `strictNullChecks: true` by ensuring that all
properties in generates types are requried
  • Loading branch information
r1tsuu authored Nov 18, 2024
1 parent ec95ce8 commit e40141b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
4 changes: 2 additions & 2 deletions packages/payload/src/queues/config/generateJobsJSONSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function generateJobsJSONSchemas(
required: ['input', 'output'],
},
},
required: jobsConfig.tasks.map((task) => task.slug),
required: [...jobsConfig.tasks.map((task) => task.slug), 'inline'],
}
}

Expand Down Expand Up @@ -161,7 +161,7 @@ export function generateJobsJSONSchemas(
return [workflow.slug, toReturn]
}),
),
required: jobsConfig.tasks.map((task) => task.slug),
required: jobsConfig.workflows.map((workflow) => workflow.slug),
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions packages/payload/src/utilities/configToJSONSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,13 @@ export function fieldsToJSONSchema(
}
case 'code':
case 'date':

case 'email':

case 'textarea': {
fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }
break
}

case 'collapsible':

case 'row': {
const childSchema = fieldsToJSONSchema(
collectionIDFieldTypes,
Expand Down Expand Up @@ -431,7 +428,6 @@ export function fieldsToJSONSchema(
}

case 'relationship':

case 'upload': {
if (Array.isArray(field.relationTo)) {
if (field.hasMany) {
Expand Down Expand Up @@ -746,7 +742,6 @@ export function fieldsToSelectJSONSchema({ fields }: { fields: Field[] }): JSONS
break
}
case 'collapsible':

case 'row':
schema.properties = {
...schema.properties,
Expand Down Expand Up @@ -1044,6 +1039,7 @@ export function configToJSONSchema(
'globals',
'auth',
'db',
'jobs',
],
title: 'Config',
}
Expand All @@ -1057,7 +1053,7 @@ export function configToJSONSchema(
type: 'object',
additionalProperties: false,
properties: jobsSchemas.properties,
required: ['tasks'],
required: ['tasks', 'workflows'],
}
}

Expand Down
24 changes: 12 additions & 12 deletions test/queues/payload-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@ export interface Config {
user: User & {
collection: 'users';
};
jobs?: {
jobs: {
tasks: {
UpdatePost: MyUpdatePostType;
UpdatePostStep2: TaskUpdatePostStep2;
CreateSimple: TaskCreateSimple;
CreateSimpleWithDuplicateMessage: TaskCreateSimpleWithDuplicateMessage;
ExternalTask: TaskExternalTask;
inline?: {
inline: {
input: unknown;
output: unknown;
};
};
workflows?: {
updatePost?: MyUpdatePostWorkflowType;
updatePostJSONWorkflow?: WorkflowUpdatePostJSONWorkflow;
retriesTest?: WorkflowRetriesTest;
retriesRollbackTest?: WorkflowRetriesRollbackTest;
retriesWorkflowLevelTest?: WorkflowRetriesWorkflowLevelTest;
inlineTaskTest?: WorkflowInlineTaskTest;
externalWorkflow?: WorkflowExternalWorkflow;
retriesBackoffTest?: WorkflowRetriesBackoffTest;
workflows: {
updatePost: MyUpdatePostWorkflowType;
updatePostJSONWorkflow: WorkflowUpdatePostJSONWorkflow;
retriesTest: WorkflowRetriesTest;
retriesRollbackTest: WorkflowRetriesRollbackTest;
retriesWorkflowLevelTest: WorkflowRetriesWorkflowLevelTest;
inlineTaskTest: WorkflowInlineTaskTest;
externalWorkflow: WorkflowExternalWorkflow;
retriesBackoffTest: WorkflowRetriesBackoffTest;
};
};
}
Expand Down Expand Up @@ -235,7 +235,7 @@ export interface PayloadJob {
| 'ExternalTask'
)
| null;
queue?: 'default' | null;
queue?: string | null;
waitUntil?: string | null;
processing?: boolean | null;
updatedAt: string;
Expand Down

0 comments on commit e40141b

Please sign in to comment.