Files
klz-cables.com/.pnpm-store/v10/files/e8/b8e2f98526b73ed9523aa2a824fb0fd3328f66b250fa6053928512dd9e9d3f3e8c8fe09b369c8b6785350a0131ce170f81078955be6b9d9a2f8cde9604928e
Marc Mintel 5397309103
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
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

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