sf-flow-coverage 0.1.0 → 0.3.0

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +52 -13
  3. package/lib/commands/flowcov/gate.d.ts +1 -0
  4. package/lib/commands/flowcov/gate.js +12 -1
  5. package/lib/commands/flowcov/gate.js.map +1 -1
  6. package/lib/core/apexTemplate.d.ts +10 -2
  7. package/lib/core/apexTemplate.js +327 -54
  8. package/lib/core/apexTemplate.js.map +1 -1
  9. package/lib/core/filterFormula.d.ts +10 -0
  10. package/lib/core/filterFormula.js +153 -0
  11. package/lib/core/filterFormula.js.map +1 -0
  12. package/lib/core/flowFingerprint.d.ts +27 -0
  13. package/lib/core/flowFingerprint.js +128 -0
  14. package/lib/core/flowFingerprint.js.map +1 -0
  15. package/lib/core/flowGraph.d.ts +94 -0
  16. package/lib/core/flowGraph.js +288 -0
  17. package/lib/core/flowGraph.js.map +1 -0
  18. package/lib/core/flowValues.d.ts +14 -0
  19. package/lib/core/flowValues.js +43 -0
  20. package/lib/core/flowValues.js.map +1 -0
  21. package/lib/core/flowXml.d.ts +1 -1
  22. package/lib/core/flowXml.js +6 -39
  23. package/lib/core/flowXml.js.map +1 -1
  24. package/lib/core/gate.d.ts +12 -1
  25. package/lib/core/gate.js +60 -6
  26. package/lib/core/gate.js.map +1 -1
  27. package/lib/core/git.d.ts +7 -2
  28. package/lib/core/git.js +104 -58
  29. package/lib/core/git.js.map +1 -1
  30. package/lib/core/orgCoverageSource.d.ts +6 -0
  31. package/lib/core/orgCoverageSource.js +43 -8
  32. package/lib/core/orgCoverageSource.js.map +1 -1
  33. package/lib/core/requiredFields.d.ts +39 -2
  34. package/lib/core/requiredFields.js +131 -6
  35. package/lib/core/requiredFields.js.map +1 -1
  36. package/lib/core/scaffold.js +32 -5
  37. package/lib/core/scaffold.js.map +1 -1
  38. package/lib/core/types.d.ts +29 -1
  39. package/messages/flowcov.gate.md +17 -1
  40. package/messages/flowcov.readiness.md +2 -2
  41. package/messages/flowcov.scaffold.md +3 -1
  42. package/oclif.manifest.json +20 -5
  43. package/package.json +10 -9
@@ -0,0 +1,153 @@
1
+ import { escapeApexString } from './flowXml.js';
2
+ /**
3
+ * Reads simple entry-criteria formulas as filters: a single condition, or `AND(...)` of terms
4
+ * (nested `AND`s flatten). Each term the reader understands becomes a filter with the same
5
+ * operators the Flow builder's filter conditions use; each term it doesn't (an `OR` inside the
6
+ * `AND`, a cross-object field, a function call) becomes a filter with no field, so it stays a
7
+ * TODO on its own. Returns undefined when the whole formula is another shape (`OR(...)`,
8
+ * `IF(...)`, `a && b`), which leaves it as one TODO.
9
+ */
10
+ export function parseFilterFormula(formula) {
11
+ const terms = andTerms(formula.trim());
12
+ if (!terms)
13
+ return undefined;
14
+ return terms.map((term) => ({ ...(parseTerm(term) ?? { field: '', operator: '' }), formulaTerm: term }));
15
+ }
16
+ const FIELD = String.raw `\{!\$Record\.([A-Za-z][A-Za-z0-9_]*)\}`;
17
+ const STRING = String.raw `"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'`;
18
+ const NUMBER = String.raw `-?\d+(?:\.\d+)?`;
19
+ const PICKLIST = new RegExp(String.raw `^ISPICKVAL\(\s*${FIELD}\s*,\s*(?:${STRING})\s*\)$`, 'i');
20
+ const BLANK = new RegExp(String.raw `^(NOT\(\s*)?(?:ISBLANK|ISNULL)\(\s*${FIELD}\s*\)(\s*\))?$`, 'i');
21
+ const CHANGED = new RegExp(String.raw `^(NOT\(\s*)?ISCHANGED\(\s*${FIELD}\s*\)(\s*\))?$`, 'i');
22
+ const CHECKBOX = new RegExp(String.raw `^(NOT\(\s*)?${FIELD}(\s*\))?$`, 'i');
23
+ const COMPARISON = new RegExp(String.raw `^${FIELD}\s*(==|=|!=|<>|>=|<=|>|<)\s*(?:${STRING}|(${NUMBER})|(TRUE|FALSE))$`, 'i');
24
+ const OPERATORS = {
25
+ '=': 'EqualTo',
26
+ '==': 'EqualTo',
27
+ '!=': 'NotEqualTo',
28
+ '<>': 'NotEqualTo',
29
+ '>': 'GreaterThan',
30
+ '<': 'LessThan',
31
+ '>=': 'GreaterThanOrEqualTo',
32
+ '<=': 'LessThanOrEqualTo',
33
+ };
34
+ /** `NOT(` and its closing `)` must come together. */
35
+ const negated = (open, close) => !!open === !!close ? !!open : undefined;
36
+ const unescapeFormula = (value) => value.replace(/\\(.)/g, '$1');
37
+ const stringFilter = (field, operator, value) => ({
38
+ field,
39
+ operator,
40
+ apexValue: `'${escapeApexString(value)}'`,
41
+ rawValue: value,
42
+ });
43
+ const booleanFilter = (field, operator, value) => ({
44
+ field,
45
+ operator,
46
+ apexValue: String(value),
47
+ rawValue: String(value),
48
+ });
49
+ function parseTerm(term) {
50
+ let match = PICKLIST.exec(term);
51
+ if (match)
52
+ return stringFilter(match[1], 'EqualTo', unescapeFormula(match[2] ?? match[3]));
53
+ match = BLANK.exec(term);
54
+ if (match) {
55
+ const not = negated(match[1], match[3]);
56
+ return not === undefined ? undefined : booleanFilter(match[2], 'IsNull', !not);
57
+ }
58
+ match = CHANGED.exec(term);
59
+ if (match) {
60
+ const not = negated(match[1], match[3]);
61
+ return not === undefined ? undefined : booleanFilter(match[2], 'IsChanged', !not);
62
+ }
63
+ match = CHECKBOX.exec(term);
64
+ if (match) {
65
+ const not = negated(match[1], match[3]);
66
+ return not === undefined ? undefined : booleanFilter(match[2], 'EqualTo', !not);
67
+ }
68
+ match = COMPARISON.exec(term);
69
+ if (match) {
70
+ const [, field, symbol, double, single, number, bool] = match;
71
+ const operator = OPERATORS[symbol];
72
+ if (double !== undefined || single !== undefined)
73
+ return stringFilter(field, operator, unescapeFormula(double ?? single));
74
+ if (number !== undefined)
75
+ return { field, operator, apexValue: number, rawValue: number };
76
+ return booleanFilter(field, operator, bool.toUpperCase() === 'TRUE');
77
+ }
78
+ return undefined;
79
+ }
80
+ /**
81
+ * The terms of `AND(...)`, flattening nested `AND`s. Each argument of an `AND` is a term on its
82
+ * own, whatever it contains. A whole formula that isn't an `AND` is one term only when it's a
83
+ * simple condition; undefined otherwise.
84
+ */
85
+ function andTerms(expression, topLevel = true) {
86
+ const inner = callArguments(expression, 'AND');
87
+ if (inner === undefined) {
88
+ if (topLevel)
89
+ return isSimpleCondition(expression) ? [expression] : undefined;
90
+ return expression === '' ? undefined : [expression];
91
+ }
92
+ const terms = [];
93
+ for (const arg of inner) {
94
+ const nested = andTerms(arg, false);
95
+ if (!nested)
96
+ return undefined;
97
+ terms.push(...nested);
98
+ }
99
+ return terms;
100
+ }
101
+ /** Not empty, not a malformed `AND`, and no `OR`/`IF`/`CASE`/`&&`/`||` at the top. */
102
+ function isSimpleCondition(expression) {
103
+ if (expression === '')
104
+ return false;
105
+ if (/^(AND|OR|IF|CASE)\s*\(/i.test(expression))
106
+ return false;
107
+ return !/&&|\|\|/.test(stripLiterals(expression));
108
+ }
109
+ /** Replaces string literals with empty ones, so operators inside them don't count. */
110
+ const stripLiterals = (expression) => expression.replace(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g, '""');
111
+ /**
112
+ * The top-level comma-separated arguments of `NAME(...)` when the whole expression is that one
113
+ * call, else undefined. Respects quotes, braces, and nested parentheses.
114
+ */
115
+ function callArguments(expression, name) {
116
+ const open = new RegExp(`^${name}\\s*\\(`, 'i').exec(expression);
117
+ if (!open)
118
+ return undefined;
119
+ const args = [];
120
+ let depth = 0;
121
+ let start = open[0].length;
122
+ let quote;
123
+ for (let i = start; i < expression.length; i++) {
124
+ const char = expression[i];
125
+ if (quote) {
126
+ if (char === '\\')
127
+ i++;
128
+ else if (char === quote)
129
+ quote = undefined;
130
+ continue;
131
+ }
132
+ if (char === '"' || char === "'")
133
+ quote = char;
134
+ else if (char === '(' || char === '{')
135
+ depth++;
136
+ else if (char === ')' || char === '}') {
137
+ if (depth === 0) {
138
+ // The call must end the expression: `AND(a, b) || c` is not an AND of terms.
139
+ if (char === '}' || expression.slice(i + 1).trim() !== '')
140
+ return undefined;
141
+ args.push(expression.slice(start, i).trim());
142
+ return args;
143
+ }
144
+ depth--;
145
+ }
146
+ else if (char === ',' && depth === 0) {
147
+ args.push(expression.slice(start, i).trim());
148
+ start = i + 1;
149
+ }
150
+ }
151
+ return undefined;
152
+ }
153
+ //# sourceMappingURL=filterFormula.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filterFormula.js","sourceRoot":"","sources":["../../src/core/filterFormula.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGhD;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACvC,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAC3G,CAAC;AAED,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAA,wCAAwC,CAAC;AACjE,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAA,yCAAyC,CAAC;AACnE,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAA,iBAAiB,CAAC;AAE3C,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAA,kBAAkB,KAAK,aAAa,MAAM,SAAS,EAAE,GAAG,CAAC,CAAC;AAChG,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAA,sCAAsC,KAAK,gBAAgB,EAAE,GAAG,CAAC,CAAC;AACrG,MAAM,OAAO,GAA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AM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,IAAI,KAAK,IAAI;gBAAE,CAAC,EAAE,CAAC;iBAClB,IAAI,IAAI,KAAK,KAAK;gBAAE,KAAK,GAAG,SAAS,CAAC;YAC3C,SAAS;QACX,CAAC;QACD,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG;YAAE,KAAK,GAAG,IAAI,CAAC;aAC1C,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG;YAAE,KAAK,EAAE,CAAC;aAC1C,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACtC,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;gBAChB,6EAA6E;gBAC7E,IAAI,IAAI,KAAK,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE;oBAAE,OAAO,SAAS,CAAC;gBAC5E,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;gBAC7C,OAAO,IAAI,CAAC;YACd,CAAC;YACD,KAAK,EAAE,CAAC;QACV,CAAC;aAAM,IAAI,IAAI,KAAK,GAAG,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;YAC7C,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The parts of a Flow that identify a version well enough to tell whether the org runs the
3
+ * version in source. Built the same way from the source XML and from the Tooling API's
4
+ * `Flow.Metadata` JSON, which differ in defaults, value types, and element order, so only
5
+ * fields both sides report reliably are kept.
6
+ */
7
+ export type FlowFingerprint = {
8
+ processType?: string;
9
+ triggerType?: string;
10
+ recordTriggerType?: string;
11
+ object?: string;
12
+ /** Start filters as `field operator value`, sorted. */
13
+ filters: string[];
14
+ /** Start filter formula with whitespace collapsed. */
15
+ filterFormula?: string;
16
+ /** Elements and resources as `type:name`, sorted. */
17
+ elements: string[];
18
+ };
19
+ /** Fingerprints a Flow metadata file. Throws when the content is not a Flow. */
20
+ export declare function fingerprintFromXml(xml: string): FlowFingerprint;
21
+ /** Fingerprints the `Metadata` field of a Tooling API `Flow` record. */
22
+ export declare function fingerprintFromMetadata(metadata: unknown): FlowFingerprint;
23
+ /**
24
+ * Describes how the source fingerprint differs from the org's, one phrase per difference.
25
+ * Returns an empty array when they match.
26
+ */
27
+ export declare function compareFingerprints(source: FlowFingerprint, org: FlowFingerprint): string[];
@@ -0,0 +1,128 @@
1
+ import { XMLParser } from 'fast-xml-parser';
2
+ /** Element and resource lists whose entries carry a `name`. */
3
+ const ELEMENT_TYPES = [
4
+ 'actionCalls',
5
+ 'apexPluginCalls',
6
+ 'assignments',
7
+ 'choices',
8
+ 'collectionProcessors',
9
+ 'constants',
10
+ 'customErrors',
11
+ 'decisions',
12
+ 'dynamicChoiceSets',
13
+ 'formulas',
14
+ 'loops',
15
+ 'orchestratedStages',
16
+ 'recordCreates',
17
+ 'recordDeletes',
18
+ 'recordLookups',
19
+ 'recordRollbacks',
20
+ 'recordUpdates',
21
+ 'screens',
22
+ 'steps',
23
+ 'subflows',
24
+ 'textTemplates',
25
+ 'transforms',
26
+ 'variables',
27
+ 'waits',
28
+ ];
29
+ const FILTER_VALUE_KEYS = [
30
+ 'stringValue',
31
+ 'booleanValue',
32
+ 'numberValue',
33
+ 'dateValue',
34
+ 'dateTimeValue',
35
+ 'elementReference',
36
+ ];
37
+ const parser = new XMLParser({
38
+ ignoreAttributes: true,
39
+ parseTagValue: false,
40
+ trimValues: true,
41
+ isArray: (_name, jpath) => String(jpath) === 'Flow.start.filters' || ELEMENT_TYPES.some((type) => String(jpath) === `Flow.${type}`),
42
+ });
43
+ const asRecord = (value) => value && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
44
+ const asRecords = (value) => Array.isArray(value) ? value.map(asRecord).filter((v) => !!v) : [];
45
+ /** XML gives strings and the JSON gives typed values; both become trimmed strings, empty as undefined. */
46
+ function scalar(value) {
47
+ if (typeof value === 'string')
48
+ return value.trim() || undefined;
49
+ if (typeof value === 'number' || typeof value === 'boolean')
50
+ return String(value);
51
+ return undefined;
52
+ }
53
+ function filterValue(value) {
54
+ const record = asRecord(value);
55
+ if (!record)
56
+ return '';
57
+ for (const key of FILTER_VALUE_KEYS) {
58
+ const text = scalar(record[key]);
59
+ if (text === undefined)
60
+ continue;
61
+ // 5 and 5.0 are the same number; the JSON drops the trailing zero.
62
+ if (key === 'numberValue' && !Number.isNaN(Number(text)))
63
+ return String(Number(text));
64
+ return text;
65
+ }
66
+ return '';
67
+ }
68
+ function fingerprint(flow) {
69
+ const start = asRecord(flow.start) ?? {};
70
+ const filters = asRecords(start.filters)
71
+ .map((f) => [scalar(f.field) ?? '', scalar(f.operator) ?? '', filterValue(f.value)].join(' ').trim())
72
+ .sort();
73
+ const elements = ELEMENT_TYPES.flatMap((type) => asRecords(flow[type])
74
+ .map((element) => scalar(element.name))
75
+ .filter((name) => !!name)
76
+ .map((name) => `${type}:${name}`)).sort();
77
+ return {
78
+ processType: scalar(flow.processType),
79
+ triggerType: scalar(start.triggerType),
80
+ recordTriggerType: scalar(start.recordTriggerType),
81
+ object: scalar(start.object),
82
+ filters,
83
+ filterFormula: scalar(start.filterFormula)?.replace(/\s+/g, ' '),
84
+ elements,
85
+ };
86
+ }
87
+ /** Fingerprints a Flow metadata file. Throws when the content is not a Flow. */
88
+ export function fingerprintFromXml(xml) {
89
+ const flow = asRecord(asRecord(parser.parse(xml))?.Flow);
90
+ if (!flow)
91
+ throw new Error('Not a Flow metadata file (no <Flow> root element).');
92
+ return fingerprint(flow);
93
+ }
94
+ /** Fingerprints the `Metadata` field of a Tooling API `Flow` record. */
95
+ export function fingerprintFromMetadata(metadata) {
96
+ return fingerprint(asRecord(metadata) ?? {});
97
+ }
98
+ const MAX_LISTED = 5;
99
+ function list(items) {
100
+ const shown = items.slice(0, MAX_LISTED).join(', ');
101
+ return items.length > MAX_LISTED ? `${shown} and ${items.length - MAX_LISTED} more` : shown;
102
+ }
103
+ const show = (value) => value ?? 'none';
104
+ /**
105
+ * Describes how the source fingerprint differs from the org's, one phrase per difference.
106
+ * Returns an empty array when they match.
107
+ */
108
+ export function compareFingerprints(source, org) {
109
+ const differences = [];
110
+ for (const field of ['processType', 'triggerType', 'recordTriggerType', 'object']) {
111
+ if (source[field] !== org[field]) {
112
+ differences.push(`${field} is ${show(source[field])} in source but ${show(org[field])} in the org`);
113
+ }
114
+ }
115
+ if (source.filters.join('\n') !== org.filters.join('\n') || source.filterFormula !== org.filterFormula) {
116
+ differences.push('start entry criteria differ');
117
+ }
118
+ const orgElements = new Set(org.elements);
119
+ const sourceElements = new Set(source.elements);
120
+ const onlyInSource = [...sourceElements].filter((e) => !orgElements.has(e));
121
+ const onlyInOrg = [...orgElements].filter((e) => !sourceElements.has(e));
122
+ if (onlyInSource.length > 0)
123
+ differences.push(`only in source: ${list(onlyInSource)}`);
124
+ if (onlyInOrg.length > 0)
125
+ differences.push(`only in the org: ${list(onlyInOrg)}`);
126
+ return differences;
127
+ }
128
+ //# sourceMappingURL=flowFingerprint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flowFingerprint.js","sourceRoot":"","sources":["../../src/core/flowFingerprint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAuB5C,+DAA+D;AAC/D,MAAM,aAAa,GAAG;IACpB,aAAa;IACb,iBAAiB;IACjB,aAAa;IACb,SAAS;IACT,sBAAsB;IACtB,WAAW;IACX,cAAc;IACd,W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,CAAC,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5E,MAAM,SAAS,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACzE,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC;QAAE,WAAW,CAAC,IAAI,CAAC,mBAAmB,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IACvF,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC;QAAE,WAAW,CAAC,IAAI,CAAC,oBAAoB,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IAClF,OAAO,WAAW,CAAC;AACrB,CAAC"}
@@ -0,0 +1,94 @@
1
+ import { type FlowValue, type XmlRecord } from './flowValues.js';
2
+ /**
3
+ * The parts of a Flow's elements that decide what a test can assert: which `$Record` fields
4
+ * each element writes, how decisions branch, and where custom errors stop the save.
5
+ */
6
+ export type FlowGraph = {
7
+ /** The element the start element connects to. */
8
+ start?: string;
9
+ nodes: Record<string, FlowNode>;
10
+ };
11
+ /** A write to a field of the triggering record. */
12
+ export type FieldWrite = {
13
+ field: string;
14
+ value: FlowValue;
15
+ /** The element that writes it. */
16
+ element: string;
17
+ };
18
+ export type FlowCondition = {
19
+ left: string;
20
+ operator: string;
21
+ right: FlowValue;
22
+ };
23
+ export type DecisionRule = {
24
+ name: string;
25
+ label: string;
26
+ /** `and`, `or`, or custom logic such as `1 AND (2 OR 3)`. */
27
+ logic?: string;
28
+ conditions: FlowCondition[];
29
+ next?: string;
30
+ };
31
+ export type FlowNode = {
32
+ kind: 'write';
33
+ name: string;
34
+ writes: FieldWrite[];
35
+ nexts: string[];
36
+ } | {
37
+ kind: 'decision';
38
+ name: string;
39
+ label: string;
40
+ rules: DecisionRule[];
41
+ defaultNext?: string;
42
+ defaultLabel: string;
43
+ nexts: string[];
44
+ } | {
45
+ kind: 'customError';
46
+ name: string;
47
+ message?: string;
48
+ nexts: string[];
49
+ }
50
+ /** Loops, waits, screens: a walk can't tell what happens past them. */
51
+ | {
52
+ kind: 'stop';
53
+ name: string;
54
+ nexts: string[];
55
+ } | {
56
+ kind: 'other';
57
+ name: string;
58
+ nexts: string[];
59
+ };
60
+ /** XML paths the parser must read as lists even when they hold one element. */
61
+ export declare const GRAPH_ARRAY_PATHS: string[];
62
+ /** Reads the element graph from a parsed `<Flow>` record. */
63
+ export declare function parseFlowGraph(flow: XmlRecord): FlowGraph;
64
+ /**
65
+ * What the test knows about the triggering record's fields when the Flow runs: an Apex literal,
66
+ * `null` for a field known to be empty, and no entry for a field it can't know.
67
+ */
68
+ export type FieldState = Map<string, string | null>;
69
+ /** Effects on one outcome of a decision the walk couldn't decide. */
70
+ export type UndecidedOutcome = {
71
+ label: string;
72
+ writes: FieldWrite[];
73
+ /** True when a custom error can stop the save on this outcome. */
74
+ customError: boolean;
75
+ };
76
+ export type FlowWalk = {
77
+ /** Writes certain to happen, in order. */
78
+ writes: FieldWrite[];
79
+ /** A custom error certain to stop the save. */
80
+ customError?: {
81
+ element: string;
82
+ message?: string;
83
+ };
84
+ /** Where the walk stopped, and what each way on can do. */
85
+ undecided?: {
86
+ element: string;
87
+ outcomes: UndecidedOutcome[];
88
+ };
89
+ };
90
+ /**
91
+ * Follows the Flow from its start for a record in the given state, through every decision the
92
+ * state decides, and reports what is certain to happen.
93
+ */
94
+ export declare function walkFlow(graph: FlowGraph, initial: FieldState): FlowWalk;