master-zapier-plan-draft/vendor/zapier-platform/packages/schema/lib/functional-constraints/deepNestedFields.js
George Lambert b4150c8250 Milestone 0: import zappier billing, Verae middleware, and Zapier research
Compose-ready workspace: packages/zappier (rate card, portal, Stripe),
packages/verae-zapier-middleware (timestamp + NATS), packages/verae-zapier
(CLI app), vendor/zapier-platform, and research/zapier vendor corpus.

Gate 0 structure checks pass. Product code and research are not yet wired.
2026-09-09 02:37:36 -04:00

68 lines
1.7 KiB
JavaScript

'use strict';
const _ = require('lodash');
const jsonschema = require('jsonschema');
const collectErrors = (inputFields, path) => {
const errors = [];
_.each(inputFields, (inputField, index) => {
if (inputField.children) {
if (inputField.children.length === 0) {
errors.push(
new jsonschema.ValidationError(
'must not be empty.',
inputField,
'/PlainFieldSchema',
`instance.${path}.inputFields[${index}].children`,
'empty',
'inputFields',
),
);
} else {
const hasDeeplyNestedChildren = _.some(
inputField.children,
(child) => child.children,
);
if (hasDeeplyNestedChildren) {
errors.push(
new jsonschema.ValidationError(
'must not contain deeply nested child fields. One level max.',
inputField,
'/PlainFieldSchema',
`instance.${path}.inputFields[${index}]`,
'deepNesting',
'inputFields',
),
);
}
}
}
});
return errors;
};
const validateFieldNesting = (definition) => {
let errors = [];
_.each(['triggers', 'searches', 'creates'], (typeOf) => {
if (definition[typeOf]) {
_.each(definition[typeOf], (actionDef) => {
if (actionDef.operation && actionDef.operation.inputFields) {
errors = errors.concat(
collectErrors(
actionDef.operation.inputFields,
`${typeOf}.${actionDef.key}`,
),
);
}
});
}
});
return errors;
};
module.exports = validateFieldNesting;