| 12345678910111213141516171819202122232425262728293031 |
- /**
- * 工作流结点严格格式:除各 type 专有字段外,仅允许下列可选流程字段。
- */
- const FLOW_OPTIONAL_KEYS = new Set([
- 'condition',
- 'delay',
- 'times',
- 'timeout',
- 'retry',
- 'data',
- 'model',
- ])
- /**
- * @param {object} action
- * @param {string[]} baseKeys - 允许的专有字段(须含 type)
- * @param {string} path - 如 execute[0]
- */
- function assertStrictKeys (action, baseKeys, path) {
- if (!action || typeof action !== 'object') return
- const allowed = new Set(baseKeys)
- FLOW_OPTIONAL_KEYS.forEach((k) => allowed.add(k))
- const extra = Object.keys(action).filter((k) => !allowed.has(k))
- if (extra.length > 0) {
- throw new Error(
- `${path}: 不允许的字段: ${extra.sort().join(', ')}。允许: ${[...allowed].sort().join(', ')}`,
- )
- }
- }
- module.exports = { FLOW_OPTIONAL_KEYS, assertStrictKeys }
|