fix: queues types with strict: true (#9281)

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
This commit is contained in:
Sasha
2024-11-18 21:49:08 +02:00
committed by GitHub
parent ec95ce8758
commit e40141b559
3 changed files with 16 additions and 20 deletions

View File

@@ -105,7 +105,7 @@ export function generateJobsJSONSchemas(
required: ['input', 'output'], required: ['input', 'output'],
}, },
}, },
required: jobsConfig.tasks.map((task) => task.slug), required: [...jobsConfig.tasks.map((task) => task.slug), 'inline'],
} }
} }
@@ -161,7 +161,7 @@ export function generateJobsJSONSchemas(
return [workflow.slug, toReturn] return [workflow.slug, toReturn]
}), }),
), ),
required: jobsConfig.tasks.map((task) => task.slug), required: jobsConfig.workflows.map((workflow) => workflow.slug),
} }
} }
} }

View File

@@ -314,16 +314,13 @@ export function fieldsToJSONSchema(
} }
case 'code': case 'code':
case 'date': case 'date':
case 'email': case 'email':
case 'textarea': { case 'textarea': {
fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) } fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }
break break
} }
case 'collapsible': case 'collapsible':
case 'row': { case 'row': {
const childSchema = fieldsToJSONSchema( const childSchema = fieldsToJSONSchema(
collectionIDFieldTypes, collectionIDFieldTypes,
@@ -431,7 +428,6 @@ export function fieldsToJSONSchema(
} }
case 'relationship': case 'relationship':
case 'upload': { case 'upload': {
if (Array.isArray(field.relationTo)) { if (Array.isArray(field.relationTo)) {
if (field.hasMany) { if (field.hasMany) {
@@ -746,7 +742,6 @@ export function fieldsToSelectJSONSchema({ fields }: { fields: Field[] }): JSONS
break break
} }
case 'collapsible': case 'collapsible':
case 'row': case 'row':
schema.properties = { schema.properties = {
...schema.properties, ...schema.properties,
@@ -1044,6 +1039,7 @@ export function configToJSONSchema(
'globals', 'globals',
'auth', 'auth',
'db', 'db',
'jobs',
], ],
title: 'Config', title: 'Config',
} }
@@ -1057,7 +1053,7 @@ export function configToJSONSchema(
type: 'object', type: 'object',
additionalProperties: false, additionalProperties: false,
properties: jobsSchemas.properties, properties: jobsSchemas.properties,
required: ['tasks'], required: ['tasks', 'workflows'],
} }
} }

View File

@@ -38,27 +38,27 @@ export interface Config {
user: User & { user: User & {
collection: 'users'; collection: 'users';
}; };
jobs?: { jobs: {
tasks: { tasks: {
UpdatePost: MyUpdatePostType; UpdatePost: MyUpdatePostType;
UpdatePostStep2: TaskUpdatePostStep2; UpdatePostStep2: TaskUpdatePostStep2;
CreateSimple: TaskCreateSimple; CreateSimple: TaskCreateSimple;
CreateSimpleWithDuplicateMessage: TaskCreateSimpleWithDuplicateMessage; CreateSimpleWithDuplicateMessage: TaskCreateSimpleWithDuplicateMessage;
ExternalTask: TaskExternalTask; ExternalTask: TaskExternalTask;
inline?: { inline: {
input: unknown; input: unknown;
output: unknown; output: unknown;
}; };
}; };
workflows?: { workflows: {
updatePost?: MyUpdatePostWorkflowType; updatePost: MyUpdatePostWorkflowType;
updatePostJSONWorkflow?: WorkflowUpdatePostJSONWorkflow; updatePostJSONWorkflow: WorkflowUpdatePostJSONWorkflow;
retriesTest?: WorkflowRetriesTest; retriesTest: WorkflowRetriesTest;
retriesRollbackTest?: WorkflowRetriesRollbackTest; retriesRollbackTest: WorkflowRetriesRollbackTest;
retriesWorkflowLevelTest?: WorkflowRetriesWorkflowLevelTest; retriesWorkflowLevelTest: WorkflowRetriesWorkflowLevelTest;
inlineTaskTest?: WorkflowInlineTaskTest; inlineTaskTest: WorkflowInlineTaskTest;
externalWorkflow?: WorkflowExternalWorkflow; externalWorkflow: WorkflowExternalWorkflow;
retriesBackoffTest?: WorkflowRetriesBackoffTest; retriesBackoffTest: WorkflowRetriesBackoffTest;
}; };
}; };
} }
@@ -235,7 +235,7 @@ export interface PayloadJob {
| 'ExternalTask' | 'ExternalTask'
) )
| null; | null;
queue?: 'default' | null; queue?: string | null;
waitUntil?: string | null; waitUntil?: string | null;
processing?: boolean | null; processing?: boolean | null;
updatedAt: string; updatedAt: string;