Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
135 lines
5.8 KiB
Plaintext
135 lines
5.8 KiB
Plaintext
import { fieldsToJSONSchema } from '../../utilities/configToJSONSchema.js';
|
|
import { flattenAllFields } from '../../utilities/flattenAllFields.js';
|
|
export function generateJobsJSONSchemas(config, jobsConfig, interfaceNameDefinitions, /**
|
|
* Used for relationship fields, to determine whether to use a string or number type for the ID.
|
|
* While there is a default ID field type set by the db adapter, they can differ on a collection-level
|
|
* if they have custom ID fields.
|
|
*/ collectionIDFieldTypes, i18n) {
|
|
const properties = {
|
|
tasks: {},
|
|
workflows: {}
|
|
};
|
|
const definitions = new Map();
|
|
if (jobsConfig?.tasks?.length) {
|
|
for (const task of jobsConfig.tasks){
|
|
const fullTaskJsonSchema = {
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
properties: {
|
|
input: {},
|
|
output: {}
|
|
},
|
|
required: []
|
|
};
|
|
if (task?.inputSchema?.length) {
|
|
const inputJsonSchema = fieldsToJSONSchema(collectionIDFieldTypes, flattenAllFields({
|
|
fields: task.inputSchema
|
|
}), interfaceNameDefinitions, config, i18n);
|
|
const fullInputJsonSchema = {
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
properties: inputJsonSchema.properties,
|
|
required: inputJsonSchema.required
|
|
};
|
|
fullTaskJsonSchema.properties.input = fullInputJsonSchema;
|
|
fullTaskJsonSchema.required.push('input');
|
|
}
|
|
if (task?.outputSchema?.length) {
|
|
const outputJsonSchema = fieldsToJSONSchema(collectionIDFieldTypes, flattenAllFields({
|
|
fields: task.outputSchema
|
|
}), interfaceNameDefinitions, config, i18n);
|
|
const fullOutputJsonSchema = {
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
properties: outputJsonSchema.properties,
|
|
required: outputJsonSchema.required
|
|
};
|
|
fullTaskJsonSchema.properties.output = fullOutputJsonSchema;
|
|
fullTaskJsonSchema.required.push('output');
|
|
}
|
|
const normalizedTaskSlug = task.slug[0].toUpperCase() + task.slug.slice(1);
|
|
definitions.set(task.interfaceName ?? `Task${normalizedTaskSlug}`, fullTaskJsonSchema);
|
|
}
|
|
// Now add properties.tasks definition that references the types in definitions keyed by task slug:
|
|
properties.tasks = {
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
properties: {
|
|
...Object.fromEntries((jobsConfig.tasks ?? []).map((task)=>{
|
|
const normalizedTaskSlug = task.slug[0].toUpperCase() + task.slug.slice(1);
|
|
const toReturn = {
|
|
$ref: task.interfaceName ? `#/definitions/${task.interfaceName}` : `#/definitions/Task${normalizedTaskSlug}`
|
|
};
|
|
return [
|
|
task.slug,
|
|
toReturn
|
|
];
|
|
})),
|
|
inline: {
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
properties: {
|
|
input: {},
|
|
output: {}
|
|
},
|
|
required: [
|
|
'input',
|
|
'output'
|
|
]
|
|
}
|
|
},
|
|
required: [
|
|
...(jobsConfig.tasks ?? []).map((task)=>task.slug),
|
|
'inline'
|
|
]
|
|
};
|
|
}
|
|
if (jobsConfig?.workflows?.length) {
|
|
for (const workflow of jobsConfig.workflows){
|
|
const fullWorkflowJsonSchema = {
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
properties: {
|
|
input: {}
|
|
},
|
|
required: []
|
|
};
|
|
if (workflow?.inputSchema?.length) {
|
|
const inputJsonSchema = fieldsToJSONSchema(collectionIDFieldTypes, flattenAllFields({
|
|
fields: workflow.inputSchema
|
|
}), interfaceNameDefinitions, config, i18n);
|
|
const fullInputJsonSchema = {
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
properties: inputJsonSchema.properties,
|
|
required: inputJsonSchema.required
|
|
};
|
|
fullWorkflowJsonSchema.properties.input = fullInputJsonSchema;
|
|
fullWorkflowJsonSchema.required.push('input');
|
|
}
|
|
const normalizedWorkflowSlug = workflow.slug[0].toUpperCase() + workflow.slug.slice(1);
|
|
definitions.set(workflow.interfaceName ?? `Workflow${normalizedWorkflowSlug}`, fullWorkflowJsonSchema);
|
|
properties.workflows = {
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
properties: Object.fromEntries(jobsConfig.workflows.map((workflow)=>{
|
|
const normalizedWorkflowSlug = workflow.slug[0].toUpperCase() + workflow.slug.slice(1);
|
|
const toReturn = {
|
|
$ref: workflow.interfaceName ? `#/definitions/${workflow.interfaceName}` : `#/definitions/Workflow${normalizedWorkflowSlug}`
|
|
};
|
|
return [
|
|
workflow.slug,
|
|
toReturn
|
|
];
|
|
})),
|
|
required: jobsConfig.workflows.map((workflow)=>workflow.slug)
|
|
};
|
|
}
|
|
}
|
|
return {
|
|
definitions,
|
|
properties
|
|
};
|
|
}
|
|
|
|
//# sourceMappingURL=generateJobsJSONSchemas.js.map |