@beehexa/hexasync-template-validate 2611.8.2 → 2611.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/validate/agentTools.d.ts +2 -0
- package/dist/validate/agentTools.d.ts.map +1 -1
- package/dist/validate/agentTools.js +9 -1
- package/dist/validate/agentTools.js.map +1 -1
- package/dist/validate/answerAgentTool.d.ts +4 -2
- package/dist/validate/answerAgentTool.d.ts.map +1 -1
- package/dist/validate/answerAgentTool.js +42 -5
- package/dist/validate/answerAgentTool.js.map +1 -1
- package/dist/validate/boundedAgentTool.d.ts +1 -1
- package/dist/validate/boundedAgentTool.d.ts.map +1 -1
- package/dist/validate/boundedAgentTool.js +17 -1
- package/dist/validate/boundedAgentTool.js.map +1 -1
- package/dist/validate/buildValidationModel.d.ts +5 -2
- package/dist/validate/buildValidationModel.d.ts.map +1 -1
- package/dist/validate/buildValidationModel.js +3 -2
- package/dist/validate/buildValidationModel.js.map +1 -1
- package/dist/validate/context.d.ts +4 -0
- package/dist/validate/context.d.ts.map +1 -1
- package/dist/validate/context.js +1 -0
- package/dist/validate/context.js.map +1 -1
- package/dist/validate/contextFromGraph.d.ts +1 -0
- package/dist/validate/contextFromGraph.d.ts.map +1 -1
- package/dist/validate/contextFromGraph.js +1 -0
- package/dist/validate/contextFromGraph.js.map +1 -1
- package/dist/validate/frontendFailureReferences.d.ts +6 -0
- package/dist/validate/frontendFailureReferences.d.ts.map +1 -0
- package/dist/validate/frontendFailureReferences.js +456 -0
- package/dist/validate/frontendFailureReferences.js.map +1 -0
- package/dist/validate/frontendFlags.d.ts +14 -0
- package/dist/validate/frontendFlags.d.ts.map +1 -0
- package/dist/validate/frontendFlags.js +31 -0
- package/dist/validate/frontendFlags.js.map +1 -0
- package/dist/validate/frontendReferences.d.ts +21 -0
- package/dist/validate/frontendReferences.d.ts.map +1 -0
- package/dist/validate/frontendReferences.js +1021 -0
- package/dist/validate/frontendReferences.js.map +1 -0
- package/dist/validate/frontendTypeKnowledge.d.ts +9 -0
- package/dist/validate/frontendTypeKnowledge.d.ts.map +1 -0
- package/dist/validate/frontendTypeKnowledge.js +356 -0
- package/dist/validate/frontendTypeKnowledge.js.map +1 -0
- package/dist/validate/model.d.ts.map +1 -1
- package/dist/validate/model.js +2 -1
- package/dist/validate/model.js.map +1 -1
- package/dist/validate/registry.d.ts +7 -7
- package/dist/validate/registry.d.ts.map +1 -1
- package/dist/validate/registry.js +26 -5
- package/dist/validate/registry.js.map +1 -1
- package/dist/validate/retrieve.d.ts +1 -1
- package/dist/validate/rule.d.ts +9 -1
- package/dist/validate/rule.d.ts.map +1 -1
- package/dist/validate/ruleCatalog.d.ts.map +1 -1
- package/dist/validate/ruleCatalog.js +76 -0
- package/dist/validate/ruleCatalog.js.map +1 -1
- package/dist/validate/rules/dependencyIntegrity.d.ts.map +1 -1
- package/dist/validate/rules/dependencyIntegrity.js +5 -41
- package/dist/validate/rules/dependencyIntegrity.js.map +1 -1
- package/dist/validate/rules/groupedFrontend.d.ts +3 -0
- package/dist/validate/rules/groupedFrontend.d.ts.map +1 -0
- package/dist/validate/rules/groupedFrontend.js +788 -0
- package/dist/validate/rules/groupedFrontend.js.map +1 -0
- package/dist/validate/rules/recordsForm.d.ts +3 -0
- package/dist/validate/rules/recordsForm.d.ts.map +1 -0
- package/dist/validate/rules/recordsForm.js +160 -0
- package/dist/validate/rules/recordsForm.js.map +1 -0
- package/dist/validate/rules/taskTable.d.ts +24 -0
- package/dist/validate/rules/taskTable.d.ts.map +1 -0
- package/dist/validate/rules/taskTable.js +57 -0
- package/dist/validate/rules/taskTable.js.map +1 -0
- package/dist/validate/sourceLocator.d.ts +8 -2
- package/dist/validate/sourceLocator.d.ts.map +1 -1
- package/dist/validate/sourceLocator.js +72 -0
- package/dist/validate/sourceLocator.js.map +1 -1
- package/package.json +10 -6
|
@@ -0,0 +1,788 @@
|
|
|
1
|
+
import { FRONTEND_SELECTED_METADATA_FIELDS, FRONTEND_UNPROCESSED_RESULT_TYPES } from '@beehexa/hexasync-template-context';
|
|
2
|
+
import { normalizeFrontendStepFlags } from '../frontendFlags.js';
|
|
3
|
+
import { CONNECTOR_WORKFLOW_KEYS, locateFrontendWorkflows } from '@beehexa/hexasync-template-frontend-flow';
|
|
4
|
+
import { frontendOutputReferences } from '../frontendReferences.js';
|
|
5
|
+
import { expressionOutputReferenceCandidates } from '../frontendFailureReferences.js';
|
|
6
|
+
const own = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
7
|
+
const object = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
8
|
+
const text = (value) => typeof value === 'string' && value.length > 0;
|
|
9
|
+
const flowKey = (value) => text(value) && value.length <= 128 && /^[A-Z][A-Z0-9_]*$/.test(value);
|
|
10
|
+
const guidance = {
|
|
11
|
+
1: 'Use a key-only FrontendFlow envelope with title, action.label, string completionVersion and nonempty steps. Omission and [] are valid; null is not.',
|
|
12
|
+
2: 'Use only true, false, "true" or "false" for root/dryRun; omit an unset flag. Metadata expressions are not coerced.',
|
|
13
|
+
3: 'dependsOn must contain distinct existing keys in this group, without self-links or cycles. Array order does not imply a prerequisite.',
|
|
14
|
+
4: 'Use distinct flow-local step keys and exactly one root: true. Step syntax is type/root/metadata, not the worker dialect.',
|
|
15
|
+
5: 'Route only to a step in this flow, by its exact key. Correct the literal next/onCancelled/IF/SWITCH target; a prerequisite does not share steps. Only {{ }}/{% %} Liquid or a jsonata:: prefix is dynamic; liquid:: and ${…} render literally.',
|
|
16
|
+
6: 'RETURN is terminal: SUCCESS needs object/jsonata:: outputs, FAILED needs error {code,message} with nonempty strings, CANCELLED has neither. No next or onCancelled; grouped RETURN forbids top-level outputs, direct RETURN tolerates only absent, null or []. FAIL is terminal too: metadata is exactly {code,message} with a literal ^[A-Z][A-Z0-9_]*$ code and a nonblank message; next/onCancelled only absent or null, outputs only absent, null or [].',
|
|
17
|
+
7: 'PUBLISH_EVENT metadata is exactly {eventName:string,payload:object}. Map to a nonempty eventName at runtime; transport and identity are server-owned. A grouped event step cannot be a dry run. HTTP 202 means router acceptance only, not delivery; no automatic retry.',
|
|
18
|
+
8: 'Every grouped step must route to an explicit RETURN or FAIL — a missing, null or blank next/arm/default or a blank onCancelled is rejected even on an unreachable step. Runtime exhaustion is MISSING_RETURN, never success.',
|
|
19
|
+
9: 'Static validation cannot certify a dynamic route or loop terminates or succeeds. Runtime exhaustion remains MISSING_RETURN.',
|
|
20
|
+
10: 'Frontend outputs belong only to nonterminal steps in the enclosing workflow. Prerequisites and sibling workflows do not inject data; worker _outputs is a different namespace.',
|
|
21
|
+
11: 'Uncertain focus/root bindings, opaque or incomplete producer selectors, whole-namespace reads, namespace predicates and duplicate local keys cannot establish one output owner statically; RECORDS_FORM search.items sees only the search response, so an outputs read there names a response member (read workflow values in search.request, label or fill). Keep ownership uncertain; runtime mapping still checks it.',
|
|
22
|
+
13: 'An API or GATEWAY_API step can fail in a controlled way and then follows its plain next, so a literal next straight into a SUCCESS RETURN would report success. Route through an IF step or a next branch object ({if, then, else}) that classifies the result, or to a FAILED RETURN, a FAIL step or an intermediate step.',
|
|
23
|
+
14: 'A failed API or GATEWAY_API needs a possible recovery route: a failed arm, an output read in its own next, or a reachable step that can read its result. This static advice does not prove that a branch executes. At runtime the failure stays unread until an actual workflow expression uses that run\'s output; comments, literals, unused branches and response-only projections do not handle it. Classify outputs.<KEY>.errorCode or _response.statusCode where you recover, or end the run failed.',
|
|
24
|
+
};
|
|
25
|
+
/** Profiles.api publication and dashboard admission: a FAIL code is a fixed literal, never templated. */
|
|
26
|
+
const FAIL_CODE = /^[A-Z][A-Z0-9_]*$/;
|
|
27
|
+
function closed(value, allowed, path, rule, emit) {
|
|
28
|
+
for (const key of Object.keys(value)) {
|
|
29
|
+
if (!allowed.includes(key))
|
|
30
|
+
emit(rule, [...path, key], `Unexpected member ${key}.`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** Validate JSON-shaped data without evaluating mappings or interpreting nested metadata. */
|
|
34
|
+
function jsonValue(value) {
|
|
35
|
+
const pending = [{ value }];
|
|
36
|
+
const active = new Set();
|
|
37
|
+
const visited = new Set();
|
|
38
|
+
while (pending.length) {
|
|
39
|
+
const frame = pending.pop();
|
|
40
|
+
if ('leave' in frame) {
|
|
41
|
+
active.delete(frame.leave);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const item = frame.value;
|
|
45
|
+
if (item === null || typeof item === 'string' || typeof item === 'boolean')
|
|
46
|
+
continue;
|
|
47
|
+
if (typeof item === 'number' && Number.isFinite(item))
|
|
48
|
+
continue;
|
|
49
|
+
if (!Array.isArray(item) && !object(item))
|
|
50
|
+
return false;
|
|
51
|
+
if (!Array.isArray(item) && Object.getPrototypeOf(item) !== Object.prototype && Object.getPrototypeOf(item) !== null)
|
|
52
|
+
return false;
|
|
53
|
+
if (active.has(item))
|
|
54
|
+
return false;
|
|
55
|
+
if (visited.has(item))
|
|
56
|
+
continue;
|
|
57
|
+
visited.add(item);
|
|
58
|
+
active.add(item);
|
|
59
|
+
pending.push({ leave: item });
|
|
60
|
+
for (const child of Array.isArray(item) ? item : Object.values(item))
|
|
61
|
+
pending.push({ value: child });
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
function specialStep(step, path, emit, grouped) {
|
|
66
|
+
if (step.type !== 'RETURN' && step.type !== 'FAIL' && step.type !== 'PUBLISH_EVENT')
|
|
67
|
+
return;
|
|
68
|
+
const rule = step.type === 'PUBLISH_EVENT' ? 7 : 6;
|
|
69
|
+
closed(step, ['key', 'type', 'root', 'dryRun', 'name', 'description', 'arguments', 'metadata', 'outputs', 'msg', 'repeatableCount', 'repeatableDetailCount', 'status', 'next', 'onCancelled'], path, rule, emit);
|
|
70
|
+
if (step.type === 'RETURN') {
|
|
71
|
+
for (const key of ['next', 'onCancelled']) {
|
|
72
|
+
if (own(step, key))
|
|
73
|
+
emit(rule, [...path, key], `RETURN forbids ${key}, even when empty or null.`);
|
|
74
|
+
}
|
|
75
|
+
if (own(step, 'outputs')) {
|
|
76
|
+
if (grouped)
|
|
77
|
+
emit(rule, [...path, 'outputs'], 'Grouped RETURN forbids outputs, even when empty or null.');
|
|
78
|
+
else if (step.outputs !== null && !(Array.isArray(step.outputs) && step.outputs.length === 0))
|
|
79
|
+
emit(rule, [...path, 'outputs'], 'RETURN forbids output processors; outputs must be absent, null or [].');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (step.type === 'FAIL') {
|
|
83
|
+
// Same tolerance as profiles.api publication and dashboard admission: routes may be absent or null only,
|
|
84
|
+
// output processors absent, null or [] only.
|
|
85
|
+
for (const key of ['next', 'onCancelled']) {
|
|
86
|
+
if (own(step, key) && step[key] !== null)
|
|
87
|
+
emit(rule, [...path, key], `FAIL is terminal: ${key} must be absent or null.`);
|
|
88
|
+
}
|
|
89
|
+
if (own(step, 'outputs') && step.outputs !== null && !(Array.isArray(step.outputs) && step.outputs.length === 0))
|
|
90
|
+
emit(rule, [...path, 'outputs'], 'FAIL forbids output processors; outputs must be absent, null or [].');
|
|
91
|
+
}
|
|
92
|
+
if (!object(step.metadata)) {
|
|
93
|
+
emit(rule, [...path, 'metadata'], `${step.type} metadata must be an object.`);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const metadata = step.metadata;
|
|
97
|
+
const at = [...path, 'metadata'];
|
|
98
|
+
if (step.type === 'FAIL') {
|
|
99
|
+
closed(metadata, ['code', 'message'], at, rule, emit);
|
|
100
|
+
if (typeof metadata.code !== 'string' || !FAIL_CODE.test(metadata.code))
|
|
101
|
+
emit(rule, [...at, 'code'], 'FAIL code must be a literal string matching ^[A-Z][A-Z0-9_]*$; a templated code is not accepted.');
|
|
102
|
+
if (typeof metadata.message !== 'string' || metadata.message.trim() === '')
|
|
103
|
+
emit(rule, [...at, 'message'], 'FAIL message must be a nonblank string.');
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (step.type === 'PUBLISH_EVENT') {
|
|
107
|
+
closed(metadata, ['eventName', 'payload'], at, rule, emit);
|
|
108
|
+
if (!text(metadata.eventName) || metadata.eventName.trim().length === 0)
|
|
109
|
+
emit(rule, [...at, 'eventName'], 'PUBLISH_EVENT requires a nonempty string eventName; its mapped value is checked at runtime.');
|
|
110
|
+
if (!object(metadata.payload) || !jsonValue(metadata.payload))
|
|
111
|
+
emit(rule, [...at, 'payload'], 'PUBLISH_EVENT payload must be a JSON object using existing recursive mapping.');
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
closed(metadata, ['status', 'outputs', 'error'], at, rule, emit);
|
|
115
|
+
const status = metadata.status;
|
|
116
|
+
if (status !== 'SUCCESS' && status !== 'FAILED' && status !== 'CANCELLED')
|
|
117
|
+
emit(rule, [...at, 'status'], 'RETURN status must be exactly SUCCESS, FAILED or CANCELLED.');
|
|
118
|
+
if (status === 'SUCCESS') {
|
|
119
|
+
const outputs = metadata.outputs;
|
|
120
|
+
if (!(object(outputs) && jsonValue(outputs)) && !(typeof outputs === 'string' && outputs.startsWith('jsonata::') && outputs.slice(9).trim().length > 0))
|
|
121
|
+
emit(rule, [...at, 'outputs'], 'SUCCESS requires JSON-object outputs or a nonempty jsonata:: mapping whose result is checked at runtime.');
|
|
122
|
+
}
|
|
123
|
+
else if (own(metadata, 'outputs')) {
|
|
124
|
+
emit(rule, [...at, 'outputs'], 'Only SUCCESS may declare outputs.');
|
|
125
|
+
}
|
|
126
|
+
if (status === 'FAILED') {
|
|
127
|
+
if (!object(metadata.error)) {
|
|
128
|
+
emit(rule, [...at, 'error'], 'FAILED requires error {code,message}.');
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
closed(metadata.error, ['code', 'message'], [...at, 'error'], rule, emit);
|
|
132
|
+
// Dashboard grouped admission requires nonempty trimmed code and message strings.
|
|
133
|
+
for (const key of ['code', 'message']) {
|
|
134
|
+
const value = metadata.error[key];
|
|
135
|
+
if (typeof value !== 'string' || value.trim() === '')
|
|
136
|
+
emit(rule, [...at, 'error', key], `FAILED error.${key} must be a nonempty string.`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else if (own(metadata, 'error')) {
|
|
141
|
+
emit(rule, [...at, 'error'], 'Only FAILED may declare error.');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Mirrors the dashboard's grouped admission and `calculateNextProcessKey`: only a Liquid tag or an explicit
|
|
146
|
+
* `jsonata::` prefix makes a route dynamic. Any other text — `liquid::X`, `${X}`, ` X` — renders literally at runtime,
|
|
147
|
+
* so it is a literal key matched exactly.
|
|
148
|
+
*/
|
|
149
|
+
const dynamicRoute = (route) => route.includes('{{') || route.includes('{%') || route.startsWith('jsonata::');
|
|
150
|
+
/**
|
|
151
|
+
* Remote-action step types whose ordinary outcome includes a controlled failure — the dashboard's
|
|
152
|
+
* `FALLIBLE_STEP_TYPES` (`groupedWorkflowDefinition.ts`). PUBLISH_EVENT is not routed on failure at all; local
|
|
153
|
+
* transforms, storage, navigation, pass-through steps, WAIT, IF/SWITCH and terminals are not checked.
|
|
154
|
+
*/
|
|
155
|
+
const FALLIBLE_STEP_TYPES = { API: true, GATEWAY_API: true };
|
|
156
|
+
const outputProcessorTypes = {
|
|
157
|
+
jsonata: true, liquid: true, GET_LOCAL_STORAGE: true, SET_LOCAL_STORAGE: true,
|
|
158
|
+
};
|
|
159
|
+
function collectStrings(value, into, seen, metadataType = '', root = true, language, projection = false, transformedKeys = false, path) {
|
|
160
|
+
const selected = Object.hasOwn(FRONTEND_SELECTED_METADATA_FIELDS, metadataType)
|
|
161
|
+
? FRONTEND_SELECTED_METADATA_FIELDS[metadataType] : undefined;
|
|
162
|
+
if ((selected !== undefined || metadataType === 'RECORDS_FORM_SEARCH') && !object(value))
|
|
163
|
+
return;
|
|
164
|
+
if (['FORM_FIELD', 'FORM_VALIDATION'].includes(metadataType) && !Array.isArray(value) && !object(value))
|
|
165
|
+
return;
|
|
166
|
+
if (typeof value === 'string') {
|
|
167
|
+
const forcedLiquid = metadataType === 'OUTPUT_GET_LOCAL_STORAGE' || metadataType === 'OUTPUT_SET_LOCAL_STORAGE';
|
|
168
|
+
const expression = { text: value, language: language ?? (forcedLiquid || !value.startsWith('jsonata::') ? 'liquid' : 'jsonata') };
|
|
169
|
+
if (path !== undefined)
|
|
170
|
+
expression.path = path;
|
|
171
|
+
into.push(expression);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (value === null || typeof value !== 'object' || seen.has(value))
|
|
175
|
+
return;
|
|
176
|
+
const type = (root || projection) && object(value) && typeof value.type === 'string' ? value.type.toUpperCase() : '';
|
|
177
|
+
if (root && type === 'RETURN' && object(value) && object(value.metadata) && value.metadata.status === 'CANCELLED')
|
|
178
|
+
return;
|
|
179
|
+
seen.add(value);
|
|
180
|
+
for (const [key, item] of Object.entries(value)) {
|
|
181
|
+
if (root && type && !['metadata', 'arguments', 'outputs', 'next', 'onCancelled', 'name', 'description'].includes(key))
|
|
182
|
+
continue;
|
|
183
|
+
if (root && ['RETURN', 'FAIL'].includes(type) && key !== 'metadata' && key !== 'arguments')
|
|
184
|
+
continue;
|
|
185
|
+
if (selected && !selected.includes(key))
|
|
186
|
+
continue;
|
|
187
|
+
if (['IF', 'SWITCH', 'JSONATA', 'LIQUID', 'SINGLE_CHOICE_FORM', 'MULTIPLE_CHOICE_FORM'].includes(metadataType) &&
|
|
188
|
+
typeof item !== 'string')
|
|
189
|
+
continue;
|
|
190
|
+
if (metadataType === 'RETURN' && key !== (object(value) && value.status === 'FAILED' ? 'error' : 'outputs'))
|
|
191
|
+
continue;
|
|
192
|
+
if (metadataType === 'FAIL' && key !== 'code' && key !== 'message')
|
|
193
|
+
continue;
|
|
194
|
+
if (metadataType === 'FORM' && ((key === 'notice' && typeof item !== 'string') ||
|
|
195
|
+
(key === 'fields' && !Array.isArray(item))))
|
|
196
|
+
continue;
|
|
197
|
+
if (metadataType === 'FORM_VALIDATION' && !Array.isArray(value) &&
|
|
198
|
+
(!object(value) || value.type !== 'API' || !['metadata', 'isOk', 'message'].includes(key)))
|
|
199
|
+
continue;
|
|
200
|
+
if ((metadataType === 'SHOW_INFO' || metadataType === 'INTEGRATION_APP_MANAGEMENT') && typeof item !== 'string')
|
|
201
|
+
continue;
|
|
202
|
+
if (metadataType === 'RECORDS_FORM' && key === 'search' && path === undefined &&
|
|
203
|
+
(!object(value) || !object(value.allow) || value.allow.add !== true))
|
|
204
|
+
continue;
|
|
205
|
+
if (metadataType === 'RECORDS_FORM_SEARCH' && key === 'items') {
|
|
206
|
+
// A located scope finding may name response-owned data; it can never be a recovery witness.
|
|
207
|
+
if (path !== undefined && typeof item === 'string')
|
|
208
|
+
into.push({ text: item, language: 'jsonata', path: [...path, key], responseFocused: true });
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (metadataType === 'RECORDS_FORM_SEARCH' && !['request', 'label', 'fill'].includes(key))
|
|
212
|
+
continue;
|
|
213
|
+
if (root && key === 'outputs' && FRONTEND_UNPROCESSED_RESULT_TYPES[type] === true)
|
|
214
|
+
continue;
|
|
215
|
+
if (projection && !Array.isArray(value) && (key !== 'metadata' || !object(value) ||
|
|
216
|
+
typeof value.type !== 'string' || !Object.hasOwn(outputProcessorTypes, value.type)))
|
|
217
|
+
continue;
|
|
218
|
+
if (['OUTPUT_JSONATA', 'OUTPUT_LIQUID'].includes(metadataType) && key !== 'expression')
|
|
219
|
+
continue;
|
|
220
|
+
const fieldPath = path === undefined ? undefined : [...path, key];
|
|
221
|
+
if (transformedKeys && (key.startsWith('jsonata::') || key.includes('{{') || key.includes('{%'))) {
|
|
222
|
+
collectStrings(key, into, seen, '', false, undefined, false, false, fieldPath);
|
|
223
|
+
}
|
|
224
|
+
let fieldLanguage;
|
|
225
|
+
let fieldValue = item;
|
|
226
|
+
if (typeof item === 'string') {
|
|
227
|
+
if ((metadataType === 'IF' && key === 'condition') || (metadataType === 'SWITCH' && key === 'expression')) {
|
|
228
|
+
const trimmed = item.trim();
|
|
229
|
+
fieldLanguage = 'liquid';
|
|
230
|
+
if (trimmed.startsWith('${') && trimmed.endsWith('}')) {
|
|
231
|
+
fieldLanguage = 'liquid-jsonata';
|
|
232
|
+
fieldValue = trimmed.slice(2, -1);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
else if (key === 'expression' &&
|
|
236
|
+
['JSONATA', 'SINGLE_CHOICE_FORM', 'MULTIPLE_CHOICE_FORM'].includes(metadataType)) {
|
|
237
|
+
fieldLanguage = 'liquid-jsonata';
|
|
238
|
+
}
|
|
239
|
+
else if ((key === 'expression' && ['LIQUID', 'OUTPUT_LIQUID'].includes(metadataType)) ||
|
|
240
|
+
(metadataType === 'RECORDS_FORM_SEARCH' && key === 'label')) {
|
|
241
|
+
fieldLanguage = 'liquid';
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
// Only the step's own metadata fields use their handler grammar. Nested data and ordinary
|
|
245
|
+
// output processors use generic first-stage transforms; response-only second passes aren't root reads.
|
|
246
|
+
const childProjection = (projection && Array.isArray(value)) ||
|
|
247
|
+
(root && key === 'outputs' && Array.isArray(item) && type !== 'RETURN' && type !== 'FAIL');
|
|
248
|
+
const childMetadataType = (metadataType === 'FORM' && key === 'fields') ||
|
|
249
|
+
(metadataType === 'FORM_FIELD' && Array.isArray(value)) ? 'FORM_FIELD'
|
|
250
|
+
: (metadataType === 'FORM_FIELD' && key === 'validations') ||
|
|
251
|
+
(metadataType === 'FORM_VALIDATION' && Array.isArray(value)) ? 'FORM_VALIDATION'
|
|
252
|
+
: metadataType === 'RECORDS_FORM' && key === 'search' ? 'RECORDS_FORM_SEARCH'
|
|
253
|
+
: (root || projection) && key === 'metadata' ? `${projection ? 'OUTPUT_' : ''}${type}` : '';
|
|
254
|
+
const childKeys = metadataType === 'FORM_FIELD' && key === 'validations' ? false :
|
|
255
|
+
(metadataType === 'FORM_VALIDATION' && key === 'metadata') || transformedKeys || (root && key === 'arguments') ||
|
|
256
|
+
(metadataType === 'RECORDS_FORM' && key === 'initial') ||
|
|
257
|
+
(root && key === 'metadata' &&
|
|
258
|
+
!['IF', 'SWITCH', 'JSONATA', 'LIQUID', 'SINGLE_CHOICE_FORM', 'MULTIPLE_CHOICE_FORM', 'RETURN', 'FAIL', 'RECORDS_FORM'].includes(type)) ||
|
|
259
|
+
(['RETURN', 'FAIL'].includes(metadataType) && (key === 'outputs' || key === 'error'));
|
|
260
|
+
collectStrings(fieldValue, into, seen, childMetadataType, false, fieldLanguage, childProjection, childKeys, fieldPath);
|
|
261
|
+
}
|
|
262
|
+
// Active-path cycle detection must not suppress a shared value's different owning-field grammar.
|
|
263
|
+
seen.delete(value);
|
|
264
|
+
}
|
|
265
|
+
/** Every route target a step can take: `next` arms, `onCancelled`, IF then/else, SWITCH cases/default. */
|
|
266
|
+
function routeTargets(step) {
|
|
267
|
+
const into = [];
|
|
268
|
+
const visit = (route, seen) => {
|
|
269
|
+
if (typeof route === 'string') {
|
|
270
|
+
if (route)
|
|
271
|
+
into.push(route);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (!object(route) || seen.has(route))
|
|
275
|
+
return;
|
|
276
|
+
seen.add(route);
|
|
277
|
+
for (const arm of ['then', 'else', 'success', 'failed'])
|
|
278
|
+
visit(route[arm], seen);
|
|
279
|
+
};
|
|
280
|
+
visit(step.next, new Set());
|
|
281
|
+
visit(step.onCancelled, new Set());
|
|
282
|
+
const metadata = step.metadata;
|
|
283
|
+
if (!object(metadata))
|
|
284
|
+
return into;
|
|
285
|
+
if (step.type === 'IF') {
|
|
286
|
+
visit(metadata.then, new Set());
|
|
287
|
+
visit(metadata.else, new Set());
|
|
288
|
+
}
|
|
289
|
+
if (step.type === 'SWITCH') {
|
|
290
|
+
if (object(metadata.cases))
|
|
291
|
+
for (const target of Object.values(metadata.cases))
|
|
292
|
+
visit(target, new Set());
|
|
293
|
+
visit(metadata.default, new Set());
|
|
294
|
+
}
|
|
295
|
+
return into;
|
|
296
|
+
}
|
|
297
|
+
/** One candidate at a time, including rejected syntax; an empty candidate still permits cancellation. */
|
|
298
|
+
function* failureConsumerWitnesses(nodes, key) {
|
|
299
|
+
const node = nodes.get(key);
|
|
300
|
+
if (!node?.fallible)
|
|
301
|
+
return;
|
|
302
|
+
if (node.explicitFailed) {
|
|
303
|
+
yield true;
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
for (const { text, language } of node.ownNext) {
|
|
307
|
+
for (const candidate of expressionOutputReferenceCandidates(text, language))
|
|
308
|
+
yield candidate.has(key);
|
|
309
|
+
}
|
|
310
|
+
const visited = new Set(), pending = [...node.targets];
|
|
311
|
+
while (pending.length) {
|
|
312
|
+
const next = pending.pop();
|
|
313
|
+
if (visited.has(next))
|
|
314
|
+
continue;
|
|
315
|
+
const reader = nodes.get(next);
|
|
316
|
+
if (!reader)
|
|
317
|
+
continue;
|
|
318
|
+
visited.add(next);
|
|
319
|
+
for (const { text, language } of reader.readers) {
|
|
320
|
+
for (const candidate of expressionOutputReferenceCandidates(text, language))
|
|
321
|
+
yield candidate.has(key);
|
|
322
|
+
}
|
|
323
|
+
pending.push(...reader.targets);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Match the runtime's potential eligibility, never actual consumption. Snapshot primitive fields before
|
|
328
|
+
* yielding; complete structural choices can require exponential total work, so hosts may cancel the run.
|
|
329
|
+
*/
|
|
330
|
+
async function potentialRecoverySteps(steps, options) {
|
|
331
|
+
options.signal?.throwIfAborted();
|
|
332
|
+
const nodes = new Map();
|
|
333
|
+
for (const step of steps) {
|
|
334
|
+
if (!step || typeof step.key !== 'string' || nodes.has(step.key))
|
|
335
|
+
continue;
|
|
336
|
+
const ownNext = [], readers = [];
|
|
337
|
+
collectStrings(step.next, ownNext, new Set());
|
|
338
|
+
collectStrings(step, readers, new Set());
|
|
339
|
+
nodes.set(step.key, {
|
|
340
|
+
fallible: typeof step.type === 'string' && Object.hasOwn(FALLIBLE_STEP_TYPES, step.type),
|
|
341
|
+
ownNext, readers, targets: routeTargets(step),
|
|
342
|
+
explicitFailed: object(step.next) && own(step.next, 'failed'),
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
const keys = [...nodes.keys()];
|
|
346
|
+
for (const node of nodes.values())
|
|
347
|
+
if (node.targets.some(dynamicRoute))
|
|
348
|
+
node.targets = keys;
|
|
349
|
+
const consumed = new Set();
|
|
350
|
+
for (const [key, node] of nodes) {
|
|
351
|
+
if (!node.fallible)
|
|
352
|
+
continue;
|
|
353
|
+
const candidates = failureConsumerWitnesses(nodes, key);
|
|
354
|
+
try {
|
|
355
|
+
while (true) {
|
|
356
|
+
options.signal?.throwIfAborted();
|
|
357
|
+
const candidate = candidates.next();
|
|
358
|
+
options.signal?.throwIfAborted();
|
|
359
|
+
if (candidate.done)
|
|
360
|
+
break;
|
|
361
|
+
if (candidate.value) {
|
|
362
|
+
consumed.add(key);
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
366
|
+
setTimeout(resolve, 0);
|
|
367
|
+
await promise;
|
|
368
|
+
options.signal?.throwIfAborted();
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
finally {
|
|
372
|
+
candidates.return(undefined);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return consumed;
|
|
376
|
+
}
|
|
377
|
+
/** Inspect only routing fields; never walk user payloads looking for something that resembles a step. */
|
|
378
|
+
function routes(step, path, keys, emit) {
|
|
379
|
+
if (step.type === 'RETURN' || step.type === 'FAIL')
|
|
380
|
+
return { targets: [], exits: [], uncertain: [] };
|
|
381
|
+
const pending = [];
|
|
382
|
+
const exits = [];
|
|
383
|
+
const uncertain = [];
|
|
384
|
+
const targets = [];
|
|
385
|
+
const metadata = object(step.metadata) ? step.metadata : {};
|
|
386
|
+
if (step.type === 'IF' || step.type === 'SWITCH') {
|
|
387
|
+
if (own(step, 'next'))
|
|
388
|
+
emit(5, [...path, 'next'], `${step.type} routes through metadata and forbids next.`);
|
|
389
|
+
// Dashboard admission ignores an empty processor list here, so only a non-empty one is a defect.
|
|
390
|
+
if (own(step, 'outputs') && step.outputs !== null && !(Array.isArray(step.outputs) && step.outputs.length === 0))
|
|
391
|
+
emit(5, [...path, 'outputs'], `${step.type} routes through metadata and forbids output processors; outputs may only be absent, null or [].`);
|
|
392
|
+
closed(metadata, step.type === 'IF' ? ['condition', 'then', 'else'] : ['expression', 'cases', 'default'], [...path, 'metadata'], 5, emit);
|
|
393
|
+
const expression = step.type === 'IF' ? 'condition' : 'expression';
|
|
394
|
+
if (typeof metadata[expression] !== 'string')
|
|
395
|
+
emit(5, [...path, 'metadata', expression], `${step.type} requires a string ${expression}.`);
|
|
396
|
+
}
|
|
397
|
+
if (step.type === 'IF') {
|
|
398
|
+
for (const arm of ['then', 'else']) {
|
|
399
|
+
if (typeof metadata[arm] !== 'string')
|
|
400
|
+
emit(5, [...path, 'metadata', arm], `IF ${arm} must be a string route.`);
|
|
401
|
+
pending.push({ value: metadata[arm], path: [...path, 'metadata', arm] });
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
else if (step.type === 'SWITCH') {
|
|
405
|
+
if (object(metadata.cases)) {
|
|
406
|
+
if (Object.keys(metadata.cases).length === 0)
|
|
407
|
+
emit(5, [...path, 'metadata', 'cases'], 'SWITCH requires at least one case.');
|
|
408
|
+
for (const [key, value] of Object.entries(metadata.cases)) {
|
|
409
|
+
if (!key || typeof value !== 'string')
|
|
410
|
+
emit(5, [...path, 'metadata', 'cases', key], 'SWITCH cases require nonempty labels and string routes.');
|
|
411
|
+
pending.push({ value, path: [...path, 'metadata', 'cases', key] });
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
emit(5, [...path, 'metadata', 'cases'], 'SWITCH requires a cases object.');
|
|
416
|
+
}
|
|
417
|
+
if (own(metadata, 'default') && typeof metadata.default !== 'string')
|
|
418
|
+
emit(5, [...path, 'metadata', 'default'], 'SWITCH default must be a string route when declared.');
|
|
419
|
+
pending.push({ value: metadata.default, path: [...path, 'metadata', 'default'] });
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
pending.push({ value: step.next, path: [...path, 'next'] });
|
|
423
|
+
}
|
|
424
|
+
// A declared string onCancelled is a route (blank → certain exit, as admission treats it); null/absent declares none.
|
|
425
|
+
if (typeof step.onCancelled === 'string') {
|
|
426
|
+
pending.push({ value: step.onCancelled, path: [...path, 'onCancelled'] });
|
|
427
|
+
}
|
|
428
|
+
else if (step.onCancelled != null) {
|
|
429
|
+
emit(5, [...path, 'onCancelled'], 'onCancelled must be a string route when declared.');
|
|
430
|
+
}
|
|
431
|
+
const entered = new Set();
|
|
432
|
+
while (pending.length) {
|
|
433
|
+
const route = pending.pop();
|
|
434
|
+
if ('leave' in route) {
|
|
435
|
+
entered.delete(route.leave);
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
438
|
+
const value = route.value;
|
|
439
|
+
if (value == null || (typeof value === 'string' && value.trim() === '')) {
|
|
440
|
+
exits.push([...route.path]);
|
|
441
|
+
}
|
|
442
|
+
else if (typeof value === 'string') {
|
|
443
|
+
if (dynamicRoute(value)) {
|
|
444
|
+
uncertain.push([...route.path]);
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
const target = keys.get(value);
|
|
448
|
+
if (target === undefined)
|
|
449
|
+
emit(5, route.path, `Literal route ${JSON.stringify(value)} does not name a step in this flow.`);
|
|
450
|
+
else
|
|
451
|
+
targets.push(target);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
else if (object(value)) {
|
|
455
|
+
if (entered.has(value)) {
|
|
456
|
+
uncertain.push([...route.path]);
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
entered.add(value);
|
|
460
|
+
pending.push({ leave: value });
|
|
461
|
+
if (typeof value.if !== 'string')
|
|
462
|
+
emit(5, [...route.path, 'if'], 'A next branch object requires a string if expression.');
|
|
463
|
+
closed(value, ['if', 'then', 'else', 'success', 'failed'], route.path, 5, emit);
|
|
464
|
+
for (const [primary, alias] of [['then', 'success'], ['else', 'failed']]) {
|
|
465
|
+
const key = own(value, primary) ? primary : alias;
|
|
466
|
+
pending.push({ value: value[key], path: [...route.path, key] });
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
emit(5, route.path, 'Route must be a step key, next branch object, null or absent.');
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return { targets, exits, uncertain };
|
|
474
|
+
}
|
|
475
|
+
async function checkSteps(flow, path, emit, options) {
|
|
476
|
+
if (!Array.isArray(flow.steps) || flow.steps.length === 0)
|
|
477
|
+
return;
|
|
478
|
+
const keys = new Map();
|
|
479
|
+
const steps = [];
|
|
480
|
+
const roots = [];
|
|
481
|
+
for (const [index, raw] of flow.steps.entries()) {
|
|
482
|
+
const at = [...path, 'steps', String(index)];
|
|
483
|
+
if (!object(raw)) {
|
|
484
|
+
emit(4, at, 'Each grouped step must be an object.');
|
|
485
|
+
steps.push(undefined);
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
const normalized = normalizeFrontendStepFlags(raw);
|
|
489
|
+
const step = normalized.step;
|
|
490
|
+
steps.push(step);
|
|
491
|
+
for (const flag of normalized.invalidFlags)
|
|
492
|
+
emit(2, [...at, flag], `Invalid ${flag} literal.`);
|
|
493
|
+
if (step.root === true)
|
|
494
|
+
roots.push(index);
|
|
495
|
+
if (!text(step.key) || !/^[A-Z0-9_]+$/.test(step.key))
|
|
496
|
+
emit(4, [...at, 'key'], 'A grouped step requires a nonempty uppercase step key.');
|
|
497
|
+
else if (keys.has(step.key))
|
|
498
|
+
emit(4, [...at, 'key'], `Duplicate flow-local step key ${step.key}.`);
|
|
499
|
+
else
|
|
500
|
+
keys.set(step.key, index);
|
|
501
|
+
if (!text(step.type))
|
|
502
|
+
emit(4, [...at, 'type'], 'A grouped step requires frontend type.');
|
|
503
|
+
for (const workerKey of ['displayType', 'rootStep', 'data']) {
|
|
504
|
+
if (own(step, workerKey))
|
|
505
|
+
emit(4, [...at, workerKey], `Worker member ${workerKey} is not frontend syntax.`);
|
|
506
|
+
}
|
|
507
|
+
specialStep(step, at, emit, true);
|
|
508
|
+
// Dashboard grouped admission: a dry run is never router acceptance, so such a step could never succeed.
|
|
509
|
+
if (step.type === 'PUBLISH_EVENT' && step.dryRun === true)
|
|
510
|
+
emit(7, [...at, 'dryRun'], 'PUBLISH_EVENT cannot run as a dry run: a dry run is never router acceptance, so the step could never succeed.');
|
|
511
|
+
}
|
|
512
|
+
if (roots.length === 0)
|
|
513
|
+
emit(4, [...path, 'steps'], 'Grouped flow has no true root.');
|
|
514
|
+
if (roots.length > 1) {
|
|
515
|
+
for (const index of roots)
|
|
516
|
+
emit(4, [...path, 'steps', String(index), 'root'], 'Grouped flow has multiple true roots.');
|
|
517
|
+
}
|
|
518
|
+
if (!steps.some((step) => step?.type === 'RETURN' || step?.type === 'FAIL'))
|
|
519
|
+
emit(8, [...path, 'steps'], 'Grouped flow is missing RETURN or FAIL.');
|
|
520
|
+
// Mirrors the dashboard's grouped admission: a controlled API/GATEWAY_API failure follows its plain `next`, so a
|
|
521
|
+
// literal `next` straight into a SUCCESS RETURN would succeed the run. Classify the outcome first (IF or a next
|
|
522
|
+
// branch object). Templated routes, FAILED RETURNs, FAIL steps and intermediate steps stay allowed.
|
|
523
|
+
const straightToSuccess = new Set();
|
|
524
|
+
for (const [index, step] of steps.entries()) {
|
|
525
|
+
if (!step || typeof step.type !== 'string' || !Object.hasOwn(FALLIBLE_STEP_TYPES, step.type) || typeof step.next !== 'string')
|
|
526
|
+
continue;
|
|
527
|
+
const route = step.next;
|
|
528
|
+
if (!route.trim() || dynamicRoute(route))
|
|
529
|
+
continue;
|
|
530
|
+
const target = keys.has(route) ? steps[keys.get(route)] : undefined;
|
|
531
|
+
if (target?.type === 'RETURN' && object(target.metadata) && target.metadata.status === 'SUCCESS') {
|
|
532
|
+
straightToSuccess.add(index);
|
|
533
|
+
emit(13, [...path, 'steps', String(index), 'next'], `${step.type} step ${String(step.key)} must not lead straight to a SUCCESS RETURN (${route}); classify its outcome first.`);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
// The dashboard routes a grouped step's failure only when it is consumed; any other failure ends the run failed.
|
|
537
|
+
// A step already reported by FFE-13 is not reported twice.
|
|
538
|
+
const consumed = await potentialRecoverySteps(steps, options);
|
|
539
|
+
const firstIndex = new Map();
|
|
540
|
+
for (const [index, step] of steps.entries())
|
|
541
|
+
if (step && typeof step.key === 'string' && !firstIndex.has(step.key))
|
|
542
|
+
firstIndex.set(step.key, index);
|
|
543
|
+
for (const [key, index] of firstIndex) {
|
|
544
|
+
const step = steps[index];
|
|
545
|
+
if (typeof step.type !== 'string' || !Object.hasOwn(FALLIBLE_STEP_TYPES, step.type) || straightToSuccess.has(index) || consumed.has(key))
|
|
546
|
+
continue;
|
|
547
|
+
emit(14, [...path, 'steps', String(index)], `Failed step ${key}'s failure is not read by any reachable step, so the run will fail. A ${String(step.type)} failure is handled only where a step reachable from ${key} reads outputs.${key}; read it where you recover, or leave it unread only to end the run failed on purpose.`);
|
|
548
|
+
}
|
|
549
|
+
const graph = steps.map((step, index) => step ? routes(step, [...path, 'steps', String(index)], keys, emit) : undefined);
|
|
550
|
+
// A certain exit is rejected on every step, reachable or not — the dashboard's grouped admission and the canonical
|
|
551
|
+
// graph both refuse it, so certifying only the reachable ones would pass a declaration the runtime rejects.
|
|
552
|
+
for (const edges of graph)
|
|
553
|
+
for (const exit of edges?.exits ?? [])
|
|
554
|
+
emit(8, exit, 'Statically certain implicit exit without RETURN (MISSING_RETURN).');
|
|
555
|
+
// Only known reachable paths establish uncertainty; unknown routing never proves success or reachability.
|
|
556
|
+
const reached = new Set();
|
|
557
|
+
const pending = roots.length === 1 ? [...roots] : [];
|
|
558
|
+
while (pending.length) {
|
|
559
|
+
const index = pending.pop();
|
|
560
|
+
if (reached.has(index))
|
|
561
|
+
continue;
|
|
562
|
+
reached.add(index);
|
|
563
|
+
const edges = graph[index];
|
|
564
|
+
if (!edges)
|
|
565
|
+
continue;
|
|
566
|
+
for (const at of edges.uncertain)
|
|
567
|
+
emit(9, at, 'Dynamic or cyclic route is statically uncertain; termination and success are not certified.');
|
|
568
|
+
pending.push(...edges.targets);
|
|
569
|
+
}
|
|
570
|
+
// Kahn pruning finds reachable loops without recursive traversal of untrusted declarations.
|
|
571
|
+
const indegree = new Map([...reached].map((index) => [index, 0]));
|
|
572
|
+
for (const index of reached)
|
|
573
|
+
for (const target of graph[index]?.targets ?? [])
|
|
574
|
+
indegree.set(target, (indegree.get(target) ?? 0) + 1);
|
|
575
|
+
const ready = [...reached].filter((index) => indegree.get(index) === 0);
|
|
576
|
+
while (ready.length) {
|
|
577
|
+
const index = ready.pop();
|
|
578
|
+
indegree.delete(index);
|
|
579
|
+
for (const target of graph[index]?.targets ?? []) {
|
|
580
|
+
const count = (indegree.get(target) ?? 0) - 1;
|
|
581
|
+
indegree.set(target, count);
|
|
582
|
+
if (count === 0)
|
|
583
|
+
ready.push(target);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
if (indegree.size)
|
|
587
|
+
emit(9, [...path, 'steps'], 'Reachable step loop is statically uncertain; termination and success are not certified.');
|
|
588
|
+
}
|
|
589
|
+
function checkDependencies(flows, emit) {
|
|
590
|
+
const keys = new Map();
|
|
591
|
+
for (const [index, flow] of flows.entries()) {
|
|
592
|
+
if (!object(flow) || !text(flow.key))
|
|
593
|
+
continue;
|
|
594
|
+
if (keys.has(flow.key))
|
|
595
|
+
emit(3, [String(index), 'key'], `Duplicate flow key ${flow.key}.`);
|
|
596
|
+
else
|
|
597
|
+
keys.set(flow.key, index);
|
|
598
|
+
}
|
|
599
|
+
const edges = flows.map((flow, index) => {
|
|
600
|
+
const targets = [];
|
|
601
|
+
if (!object(flow) || !own(flow, 'dependsOn'))
|
|
602
|
+
return targets;
|
|
603
|
+
const at = [String(index), 'dependsOn'];
|
|
604
|
+
if (!Array.isArray(flow.dependsOn)) {
|
|
605
|
+
emit(3, at, 'dependsOn must be an array of local flow keys.');
|
|
606
|
+
return targets;
|
|
607
|
+
}
|
|
608
|
+
const seen = new Set();
|
|
609
|
+
for (const [dependencyIndex, dependency] of flow.dependsOn.entries()) {
|
|
610
|
+
const path = [...at, String(dependencyIndex)];
|
|
611
|
+
if (!flowKey(dependency)) {
|
|
612
|
+
emit(3, path, 'Dependency must match ^[A-Z][A-Z0-9_]*$ with at most 128 characters.');
|
|
613
|
+
continue;
|
|
614
|
+
}
|
|
615
|
+
if (seen.has(dependency))
|
|
616
|
+
emit(3, path, `Duplicate dependency ${dependency}.`);
|
|
617
|
+
seen.add(dependency);
|
|
618
|
+
const target = keys.get(dependency);
|
|
619
|
+
if (target === undefined)
|
|
620
|
+
emit(3, path, `Missing local dependency ${dependency}.`);
|
|
621
|
+
else if (dependency === flow.key)
|
|
622
|
+
emit(3, path, `Flow cannot depend on itself: ${dependency}.`);
|
|
623
|
+
else
|
|
624
|
+
targets.push(target);
|
|
625
|
+
}
|
|
626
|
+
return targets;
|
|
627
|
+
});
|
|
628
|
+
// Iterative DFS reports the offending edge, without conflating a dependant with a cycle member.
|
|
629
|
+
const state = new Map();
|
|
630
|
+
for (let start = 0; start < flows.length; start++) {
|
|
631
|
+
if (state.has(start))
|
|
632
|
+
continue;
|
|
633
|
+
const stack = [{ index: start, next: 0 }];
|
|
634
|
+
state.set(start, 1);
|
|
635
|
+
while (stack.length) {
|
|
636
|
+
const frame = stack[stack.length - 1];
|
|
637
|
+
const target = edges[frame.index][frame.next++];
|
|
638
|
+
if (target === undefined) {
|
|
639
|
+
state.set(frame.index, 2);
|
|
640
|
+
stack.pop();
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
if (state.get(target) === 1)
|
|
644
|
+
emit(3, [String(frame.index), 'dependsOn'], 'Cyclic local flow dependency; remove an edge in this cycle.');
|
|
645
|
+
else if (!state.has(target)) {
|
|
646
|
+
state.set(target, 1);
|
|
647
|
+
stack.push({ index: target, next: 0 });
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
/** Scope and possible recovery share one owning-field walk; literal configuration is never code. */
|
|
653
|
+
function checkOutputScope(steps, base, emit) {
|
|
654
|
+
const local = new Map();
|
|
655
|
+
for (const step of steps) {
|
|
656
|
+
if (!object(step) || !text(step.key) || step.type === 'RETURN' || step.type === 'FAIL')
|
|
657
|
+
continue;
|
|
658
|
+
local.set(step.key, (local.get(step.key) ?? 0) + 1);
|
|
659
|
+
}
|
|
660
|
+
for (const [index, step] of steps.entries()) {
|
|
661
|
+
if (!object(step))
|
|
662
|
+
continue;
|
|
663
|
+
const fields = [];
|
|
664
|
+
collectStrings(step, fields, new Set(), '', true, undefined, false, false, [...base, String(index)]);
|
|
665
|
+
for (const field of fields) {
|
|
666
|
+
// Passing a root path above makes every collected field located, including transformed keys.
|
|
667
|
+
const path = field.path;
|
|
668
|
+
const references = frontendOutputReferences(field.text, field.language);
|
|
669
|
+
if (field.responseFocused) {
|
|
670
|
+
if (references.length)
|
|
671
|
+
emit(11, path, 'search.items is evaluated against the search response, not this workflow: an outputs/_outputs read here names a response member, valid only if the response has one. Read workflow values in search.request, label or fill instead.');
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
674
|
+
for (const reference of references) {
|
|
675
|
+
if (reference.rootCertainty === 'uncertain')
|
|
676
|
+
emit(11, path, 'Output ownership is statically uncertain; lexical focus, root rebinding or opaque template output prevents establishing the workflow root.');
|
|
677
|
+
else if (reference.namespace === '_outputs')
|
|
678
|
+
emit(10, path, 'Worker _outputs is not a frontend output namespace.');
|
|
679
|
+
else if (reference.key === undefined || (local.get(reference.key) ?? 0) > 1)
|
|
680
|
+
emit(11, path, 'Output ownership is statically uncertain; a predicate, computed or incomplete producer selector, or duplicate local key cannot establish one producer.');
|
|
681
|
+
else if (!local.has(reference.key))
|
|
682
|
+
emit(10, path, `Output ${reference.key} is not produced by a nonterminal step in this workflow.`);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
export const groupedFrontendRule = {
|
|
688
|
+
id: 'FFE',
|
|
689
|
+
family: 'FFE',
|
|
690
|
+
async run(ctx, options = {}) {
|
|
691
|
+
const document = ctx.tokenForm;
|
|
692
|
+
if (!object(document))
|
|
693
|
+
return [];
|
|
694
|
+
const issues = [];
|
|
695
|
+
const group = document.getReadyFlows;
|
|
696
|
+
const emit = (rule, path, message) => {
|
|
697
|
+
const flow = Array.isArray(group) ? group[Number(path[0])] : undefined;
|
|
698
|
+
issues.push({
|
|
699
|
+
ruleId: `FFE-${rule}`, family: 'FFE', severity: rule === 9 ? 'low' : rule === 14 ? 'medium' : 'high',
|
|
700
|
+
parentKey: 'getReadyFlows', idOrKey: object(flow) && text(flow.key) ? flow.key : undefined,
|
|
701
|
+
componentPath: path,
|
|
702
|
+
message: `getReadyFlows${path.map((part) => `[${JSON.stringify(part)}]`).join('')}: ${message}`,
|
|
703
|
+
why: `${guidance[rule]} See hexasync://docs/frontend/FRONTEND-FLOWS.`,
|
|
704
|
+
});
|
|
705
|
+
};
|
|
706
|
+
if (own(document, 'getReadyFlows')) {
|
|
707
|
+
if (!Array.isArray(group))
|
|
708
|
+
emit(1, [], 'getReadyFlows must be an array; omit it or use [] for an empty group.');
|
|
709
|
+
else {
|
|
710
|
+
for (const [index, flow] of group.entries()) {
|
|
711
|
+
const at = [String(index)];
|
|
712
|
+
if (!object(flow)) {
|
|
713
|
+
emit(1, at, 'Each flow envelope must be an object.');
|
|
714
|
+
continue;
|
|
715
|
+
}
|
|
716
|
+
closed(flow, ['key', 'title', 'description', 'action', 'completionVersion', 'dependsOn', 'steps'], at, 1, emit);
|
|
717
|
+
if (!flowKey(flow.key))
|
|
718
|
+
emit(1, [...at, 'key'], 'Flow key must match ^[A-Z][A-Z0-9_]*$ with at most 128 characters.');
|
|
719
|
+
if (typeof flow.title !== 'string')
|
|
720
|
+
emit(1, [...at, 'title'], 'title must be a string.');
|
|
721
|
+
if (!text(flow.completionVersion))
|
|
722
|
+
emit(1, [...at, 'completionVersion'], 'completionVersion must be a nonempty string; numbers are not coerced.');
|
|
723
|
+
if (own(flow, 'description') && typeof flow.description !== 'string')
|
|
724
|
+
emit(1, [...at, 'description'], 'description must be a string.');
|
|
725
|
+
if (!object(flow.action))
|
|
726
|
+
emit(1, [...at, 'action'], 'action requires an object with label.');
|
|
727
|
+
else {
|
|
728
|
+
closed(flow.action, ['label', 'completedLabel'], [...at, 'action'], 1, emit);
|
|
729
|
+
if (typeof flow.action.label !== 'string')
|
|
730
|
+
emit(1, [...at, 'action', 'label'], 'action.label must be a string.');
|
|
731
|
+
if (own(flow.action, 'completedLabel') && typeof flow.action.completedLabel !== 'string')
|
|
732
|
+
emit(1, [...at, 'action', 'completedLabel'], 'action.completedLabel must be a string.');
|
|
733
|
+
}
|
|
734
|
+
if (!Array.isArray(flow.steps) || flow.steps.length === 0)
|
|
735
|
+
emit(1, [...at, 'steps'], 'steps must be a nonempty array.');
|
|
736
|
+
await checkSteps(flow, at, emit, options);
|
|
737
|
+
}
|
|
738
|
+
checkDependencies(group, emit);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
// Direct arrays share new step shapes, but never acquire grouped root/terminal semantics.
|
|
742
|
+
const direct = (steps, parentKey, idOrKey, base) => {
|
|
743
|
+
for (const [index, step] of steps.entries()) {
|
|
744
|
+
if (!object(step))
|
|
745
|
+
continue;
|
|
746
|
+
specialStep(step, [...base, String(index)], (rule, path, message) => issues.push({
|
|
747
|
+
ruleId: `FFE-${rule}`, family: 'FFE', severity: 'high', parentKey, idOrKey,
|
|
748
|
+
componentPath: path, message: `${parentKey ? `${parentKey}.` : ''}${path.join('.')}: ${message}`, why: `${guidance[rule]} See hexasync://docs/frontend/FRONTEND-FLOWS.`,
|
|
749
|
+
}), false);
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
const locations = locateFrontendWorkflows(document);
|
|
753
|
+
for (const location of locations) {
|
|
754
|
+
const parentKey = location.groupKey ?? (location.stepsPath[0] === 'connectors' || location.stepsPath[0] === 'connections' ? String(location.stepsPath[0]) : '');
|
|
755
|
+
const path = (parentKey ? location.stepsPath.slice(1) : location.stepsPath).map(String);
|
|
756
|
+
checkOutputScope(location.steps, path, (rule, componentPath, message) => issues.push({
|
|
757
|
+
ruleId: `FFE-${rule}`, family: 'FFE', severity: rule === 11 ? 'low' : 'high',
|
|
758
|
+
parentKey, idOrKey: location.flowKey ?? location.ownerKey, componentPath,
|
|
759
|
+
message: `${parentKey ? `${parentKey}.` : ''}${componentPath.join('.')}: ${message}`,
|
|
760
|
+
why: `${guidance[rule]} See hexasync://docs/frontend/FRONTEND-FLOWS.`,
|
|
761
|
+
}));
|
|
762
|
+
if (location.groupKey)
|
|
763
|
+
continue; // Invalid envelopes and grouped invariants are judged above.
|
|
764
|
+
const collection = location.stepsPath[0];
|
|
765
|
+
const nested = collection === 'connectors' || collection === 'connections';
|
|
766
|
+
direct(location.steps, nested ? collection : '', location.ownerKey, (nested ? location.stepsPath.slice(1) : location.stepsPath).map(String));
|
|
767
|
+
}
|
|
768
|
+
// Discovery requires addressable owners; malformed legacy envelopes still need findings.
|
|
769
|
+
for (const collection of ['connectors', 'connections']) {
|
|
770
|
+
const owners = document[collection];
|
|
771
|
+
if (!Array.isArray(owners))
|
|
772
|
+
continue;
|
|
773
|
+
for (const [index, owner] of owners.entries()) {
|
|
774
|
+
if (!object(owner))
|
|
775
|
+
continue;
|
|
776
|
+
for (const workflow of collection === 'connections' ? ['setupSteps'] : CONNECTOR_WORKFLOW_KEYS) {
|
|
777
|
+
if (locations.some((location) => location.stepsPath[0] === collection && location.stepsPath[1] === index && location.workflow === workflow))
|
|
778
|
+
continue;
|
|
779
|
+
const steps = owner[workflow];
|
|
780
|
+
if (Array.isArray(steps))
|
|
781
|
+
direct(steps, collection, undefined, [String(index), workflow]);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
return issues;
|
|
786
|
+
},
|
|
787
|
+
};
|
|
788
|
+
//# sourceMappingURL=groupedFrontend.js.map
|