@uipath/apollo-wind 2.93.0 → 2.94.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.
Files changed (132) hide show
  1. package/dist/components/forms/field-renderer.cjs +1 -1
  2. package/dist/components/forms/field-renderer.js +1 -1
  3. package/dist/components/forms/field-rules-strings.cjs +40 -0
  4. package/dist/components/forms/field-rules-strings.d.ts +17 -0
  5. package/dist/components/forms/field-rules-strings.js +6 -0
  6. package/dist/components/forms/field-rules.cjs +526 -0
  7. package/dist/components/forms/field-rules.d.ts +97 -0
  8. package/dist/components/forms/field-rules.js +468 -0
  9. package/dist/components/forms/form-designer.cjs +208 -592
  10. package/dist/components/forms/form-designer.js +210 -594
  11. package/dist/components/forms/form-schema.d.ts +5 -0
  12. package/dist/components/forms/index.cjs +43 -3
  13. package/dist/components/forms/index.d.ts +4 -0
  14. package/dist/components/forms/index.js +5 -1
  15. package/dist/components/forms/metadata-form.cjs +1 -1
  16. package/dist/components/forms/metadata-form.js +1 -1
  17. package/dist/components/forms/rules-engine-dialect.cjs +644 -0
  18. package/dist/components/forms/rules-engine-dialect.d.ts +90 -0
  19. package/dist/components/forms/rules-engine-dialect.js +537 -0
  20. package/dist/components/forms/rules-engine.cjs +99 -10
  21. package/dist/components/forms/rules-engine.d.ts +5 -0
  22. package/dist/components/forms/rules-engine.js +99 -10
  23. package/dist/components/forms/use-field-rules.cjs +122 -0
  24. package/dist/components/forms/use-field-rules.d.ts +31 -0
  25. package/dist/components/forms/use-field-rules.js +88 -0
  26. package/dist/components/ui/command.cjs +1 -1
  27. package/dist/components/ui/command.js +1 -1
  28. package/dist/components/ui/conditions-editor/condition-row.cjs +458 -0
  29. package/dist/components/ui/conditions-editor/condition-row.d.ts +23 -0
  30. package/dist/components/ui/conditions-editor/condition-row.js +421 -0
  31. package/dist/components/ui/conditions-editor/conditions-editor.cjs +363 -0
  32. package/dist/components/ui/conditions-editor/conditions-editor.d.ts +67 -0
  33. package/dist/components/ui/conditions-editor/conditions-editor.js +329 -0
  34. package/dist/components/ui/conditions-editor/context.cjs +45 -0
  35. package/dist/components/ui/conditions-editor/context.d.ts +54 -0
  36. package/dist/components/ui/conditions-editor/context.js +8 -0
  37. package/dist/components/ui/conditions-editor/index.cjs +55 -0
  38. package/dist/components/ui/conditions-editor/index.d.ts +6 -0
  39. package/dist/components/ui/conditions-editor/index.js +6 -0
  40. package/dist/components/ui/conditions-editor/model.cjs +126 -0
  41. package/dist/components/ui/conditions-editor/model.d.ts +39 -0
  42. package/dist/components/ui/conditions-editor/model.js +71 -0
  43. package/dist/components/ui/conditions-editor/status.cjs +198 -0
  44. package/dist/components/ui/conditions-editor/status.d.ts +44 -0
  45. package/dist/components/ui/conditions-editor/status.js +131 -0
  46. package/dist/components/ui/conditions-editor/strings.cjs +86 -0
  47. package/dist/components/ui/conditions-editor/strings.d.ts +62 -0
  48. package/dist/components/ui/conditions-editor/strings.js +52 -0
  49. package/dist/components/ui/conditions-editor/vocabulary.cjs +163 -0
  50. package/dist/components/ui/conditions-editor/vocabulary.d.ts +51 -0
  51. package/dist/components/ui/conditions-editor/vocabulary.js +129 -0
  52. package/dist/components/ui/context-menu.cjs +1 -1
  53. package/dist/components/ui/context-menu.js +1 -1
  54. package/dist/components/ui/dropdown-menu.cjs +1 -1
  55. package/dist/components/ui/dropdown-menu.js +1 -1
  56. package/dist/components/ui/field-actions/index.cjs +9 -2
  57. package/dist/components/ui/field-actions/index.d.ts +1 -0
  58. package/dist/components/ui/field-actions/index.js +2 -1
  59. package/dist/components/ui/field-actions/insert-variable-action.cjs +3 -1
  60. package/dist/components/ui/field-actions/insert-variable-action.d.ts +4 -1
  61. package/dist/components/ui/field-actions/insert-variable-action.js +3 -1
  62. package/dist/components/ui/field-actions/rules-action.cjs +244 -0
  63. package/dist/components/ui/field-actions/rules-action.d.ts +42 -0
  64. package/dist/components/ui/field-actions/rules-action.js +207 -0
  65. package/dist/components/ui/index.cjs +285 -246
  66. package/dist/components/ui/index.d.ts +3 -0
  67. package/dist/components/ui/index.js +3 -0
  68. package/dist/components/ui/quick-form-field/components/field-header.cjs +137 -167
  69. package/dist/components/ui/quick-form-field/components/field-header.d.ts +1 -1
  70. package/dist/components/ui/quick-form-field/components/field-header.js +138 -168
  71. package/dist/components/ui/quick-form-field/components/header-actions.cjs +187 -0
  72. package/dist/components/ui/quick-form-field/components/header-actions.d.ts +59 -0
  73. package/dist/components/ui/quick-form-field/components/header-actions.js +138 -0
  74. package/dist/components/ui/quick-form-field/components/header-context.cjs +59 -0
  75. package/dist/components/ui/quick-form-field/components/header-context.d.ts +33 -0
  76. package/dist/components/ui/quick-form-field/components/header-context.js +16 -0
  77. package/dist/components/ui/quick-form-field/index.cjs +18 -4
  78. package/dist/components/ui/quick-form-field/index.d.ts +2 -0
  79. package/dist/components/ui/quick-form-field/index.js +3 -1
  80. package/dist/components/ui/quick-form-field/quick-form-field.cjs +1 -1
  81. package/dist/components/ui/quick-form-field/quick-form-field.d.ts +6 -6
  82. package/dist/components/ui/quick-form-field/quick-form-field.js +1 -1
  83. package/dist/components/ui/quick-form-field/types.d.ts +42 -11
  84. package/dist/components/ui/row-groups/add-row-button.cjs +54 -0
  85. package/dist/components/ui/row-groups/add-row-button.d.ts +10 -0
  86. package/dist/components/ui/row-groups/add-row-button.js +20 -0
  87. package/dist/components/ui/row-groups/after-press.cjs +73 -0
  88. package/dist/components/ui/row-groups/after-press.d.ts +7 -0
  89. package/dist/components/ui/row-groups/after-press.js +36 -0
  90. package/dist/components/ui/row-groups/collapsible-row-group.cjs +83 -0
  91. package/dist/components/ui/row-groups/collapsible-row-group.d.ts +13 -0
  92. package/dist/components/ui/row-groups/collapsible-row-group.js +49 -0
  93. package/dist/components/ui/row-groups/empty-rows.cjs +42 -0
  94. package/dist/components/ui/row-groups/empty-rows.d.ts +7 -0
  95. package/dist/components/ui/row-groups/empty-rows.js +8 -0
  96. package/dist/components/ui/row-groups/group-mode-toggle.cjs +80 -0
  97. package/dist/components/ui/row-groups/group-mode-toggle.d.ts +26 -0
  98. package/dist/components/ui/row-groups/group-mode-toggle.js +40 -0
  99. package/dist/components/ui/row-groups/index.cjs +62 -0
  100. package/dist/components/ui/row-groups/index.d.ts +6 -0
  101. package/dist/components/ui/row-groups/index.js +7 -0
  102. package/dist/components/ui/row-groups/row-delete-button.cjs +54 -0
  103. package/dist/components/ui/row-groups/row-delete-button.d.ts +18 -0
  104. package/dist/components/ui/row-groups/row-delete-button.js +20 -0
  105. package/dist/components/ui/row-groups/use-row-focus.cjs +82 -0
  106. package/dist/components/ui/row-groups/use-row-focus.d.ts +17 -0
  107. package/dist/components/ui/row-groups/use-row-focus.js +48 -0
  108. package/dist/components/ui/rules-editor/context.cjs +45 -0
  109. package/dist/components/ui/rules-editor/context.d.ts +52 -0
  110. package/dist/components/ui/rules-editor/context.js +8 -0
  111. package/dist/components/ui/rules-editor/index.cjs +56 -0
  112. package/dist/components/ui/rules-editor/index.d.ts +4 -0
  113. package/dist/components/ui/rules-editor/index.js +4 -0
  114. package/dist/components/ui/rules-editor/model.cjs +205 -0
  115. package/dist/components/ui/rules-editor/model.d.ts +128 -0
  116. package/dist/components/ui/rules-editor/model.js +144 -0
  117. package/dist/components/ui/rules-editor/rule-card.cjs +470 -0
  118. package/dist/components/ui/rules-editor/rule-card.d.ts +14 -0
  119. package/dist/components/ui/rules-editor/rule-card.js +436 -0
  120. package/dist/components/ui/rules-editor/rules-editor.cjs +160 -0
  121. package/dist/components/ui/rules-editor/rules-editor.d.ts +66 -0
  122. package/dist/components/ui/rules-editor/rules-editor.js +126 -0
  123. package/dist/components/ui/rules-editor/strings.cjs +68 -0
  124. package/dist/components/ui/rules-editor/strings.d.ts +56 -0
  125. package/dist/components/ui/rules-editor/strings.js +34 -0
  126. package/dist/components/ui/select.cjs +1 -1
  127. package/dist/components/ui/select.js +1 -1
  128. package/dist/index.cjs +129 -8
  129. package/dist/index.d.ts +17 -4
  130. package/dist/index.js +10 -3
  131. package/dist/styles.css +97 -24
  132. package/package.json +2 -2
@@ -0,0 +1,97 @@
1
+ import { type ConditionOperators } from '../ui/conditions-editor';
2
+ import { type Rule, type RuleOutcome } from '../ui/rules-editor';
3
+ import { type FieldRulesStrings } from './field-rules-strings';
4
+ import type { FieldCondition, FieldRule } from './form-schema';
5
+ import { type FieldRuleField } from './rules-engine-dialect';
6
+ export type FieldRuleEffects = FieldRule['effects'];
7
+ /** An outcome, with the effects it stands for, such as Show as `{ visible: true }`. */
8
+ export interface FieldRuleOutcome extends RuleOutcome {
9
+ effects: FieldRuleEffects;
10
+ }
11
+ export interface FieldRulesOptions {
12
+ outcomes: readonly FieldRuleOutcome[];
13
+ fields: readonly FieldRuleField[];
14
+ /**
15
+ * Defaults to `RULES_ENGINE_OPERATORS`. Pass the editor's own if it translates them, as
16
+ * `createRulesEngineVocabulary` makes them.
17
+ */
18
+ operators?: ConditionOperators;
19
+ /** Translates the reasons a stored rule needs repair, and the default operators' messages. */
20
+ strings?: Partial<FieldRulesStrings>;
21
+ /**
22
+ * The outcome whose rule with no conditions `useFieldRules` stores as the field's own `required`
23
+ * flag rather than as a rule, for a host that keeps one: hitl's carries its required message.
24
+ * Its effects must be `{ required: true }` alone, as that is all the flag says; for any other
25
+ * outcome the flag is left as it is. Omit to store the rule as a rule, which RulesEngine runs
26
+ * the same.
27
+ */
28
+ requiredOutcome?: string;
29
+ /**
30
+ * Rewrites a condition the host stored in a form of its own, such as an older syntax, and says
31
+ * why. A rule whose rewritten conditions all read as rows opens as stored, flagged with the
32
+ * reason, and its repair is those rows; otherwise the rewrite is not used.
33
+ */
34
+ upgradeCondition?: (stored: FieldCondition) => {
35
+ condition: FieldCondition;
36
+ reason: string;
37
+ } | undefined;
38
+ }
39
+ /** A field's stored rules, and its own `required` flag when the host keeps one. */
40
+ export interface StoredFieldRules {
41
+ rules?: readonly FieldRule[];
42
+ required?: boolean;
43
+ }
44
+ /**
45
+ * Stored rules as editor rules. A rule whose conditions are all rows opens as conditions; any
46
+ * other opens as one expression, unless only its stored form runs: then it is preserved, shown as
47
+ * its stored conditions. Ids come from the stored rules, so reading twice gives the same.
48
+ */
49
+ export declare function fromFieldRules(rules: readonly FieldRule[], options: FieldRulesOptions): Rule[];
50
+ /**
51
+ * Editor rules as stored rules RulesEngine runs. Incomplete conditions are left out, as the
52
+ * editor says, and a rule with none complete is left out whole. A rule read by `fromFieldRules`
53
+ * and not edited since is written back as the stored object it came from.
54
+ */
55
+ export declare function toFieldRules(rules: readonly Rule[], options: FieldRulesOptions): FieldRule[];
56
+ /**
57
+ * Editor rules from a field's stored rules and, with `requiredOutcome`, its `required` flag, read
58
+ * as a rule of that outcome with no conditions, first. A stored rule that already is one stands
59
+ * for the flag too.
60
+ */
61
+ export declare function readStoredRules(stored: StoredFieldRules, options: FieldRulesOptions): Rule[];
62
+ /**
63
+ * Editor rules as a field's stored rules and `required` flag. With `requiredOutcome`, the first
64
+ * rule of that outcome with no conditions is written as the flag, which applies before every
65
+ * rule. It stays a rule where that would change the result: it carries effects the flag cannot,
66
+ * or an earlier rule sets `required` otherwise, which it overrode.
67
+ */
68
+ export declare function writeStoredRules(rules: readonly Rule[], options: FieldRulesOptions): {
69
+ rules: FieldRule[];
70
+ required: boolean;
71
+ };
72
+ /** `requiredOutcome`, when the flag can stand for it: its effects are `{ required: true }` alone. */
73
+ export declare function flagOutcome(options: FieldRulesOptions): string | undefined;
74
+ /** The ids of the rules that apply always, having no conditions. */
75
+ export declare function alwaysApplying(rules: readonly Rule[]): Set<string>;
76
+ /**
77
+ * The rules as they apply. A rule that applied always, by id in `always`, still does while none
78
+ * of its conditions is finished, so giving it a first condition changes nothing until that one is
79
+ * done.
80
+ */
81
+ export declare function settleAlways(rules: readonly Rule[], options: FieldRulesOptions, always: ReadonlySet<string>): Rule[];
82
+ /**
83
+ * The stored rules with field `from` renamed `to` wherever they name it: each condition's `when`
84
+ * and the expressions in `custom`, paths into the field included. A rule that names neither is
85
+ * returned as the same object, and an empty `from` or `to` renames nothing.
86
+ *
87
+ * A path is renamed with its parent even when the form lists it as a field of its own, as
88
+ * `user.role` is with `user`. An expression cannot name a `to` that is not an identifier path, so
89
+ * it keeps naming `from` and the editor flags it as naming a field the form does not contain. An
90
+ * expression the dialect cannot print again is left as it is.
91
+ */
92
+ export declare function renameFieldInRules(rules: readonly FieldRule[], from: string, to: string): FieldRule[];
93
+ /**
94
+ * The ids of the stored rules that name field `key`, or a path into it, in a condition's `when` or
95
+ * expression, such as to say which rules removing it would leave flagged.
96
+ */
97
+ export declare function rulesReferencing(rules: readonly FieldRule[], key: string): string[];
@@ -0,0 +1,468 @@
1
+ import { createCondition, createConditionGroup } from "../ui/conditions-editor/index.js";
2
+ import { isComplete, resolveCondition } from "../ui/conditions-editor/status.js";
3
+ import { createRule, isUnconditionalRule } from "../ui/rules-editor/index.js";
4
+ import { DEFAULT_FIELD_RULES_STRINGS } from "./field-rules-strings.js";
5
+ import { RULES_ENGINE_OPERATORS, canName, canRun, conditionExpression, createRulesEngineVocabulary, emptyCheck, fieldKeysOf, markRepairNeeded, notEmptyCheck, offered, parseCondition, parseExpression, printLiteral, renameInExpression, rulesEngineVocabulary, typedValue, valueText } from "./rules-engine-dialect.js";
6
+ const originals = new WeakMap();
7
+ const unknownFieldConditions = new WeakMap();
8
+ function vocabularyOf(options) {
9
+ return {
10
+ fields: options.fields,
11
+ operators: options.operators ?? defaultOperators(options.strings),
12
+ valueModes: rulesEngineVocabulary.valueModes
13
+ };
14
+ }
15
+ const SPECIAL = /[.*+?^${}()|[\]\\]/g;
16
+ const escapePattern = (text)=>text.replace(SPECIAL, '\\$&');
17
+ const unescapePattern = (text)=>text.replace(/\\([.*+?^${}()|[\]\\])/g, '$1');
18
+ function literalText(pattern) {
19
+ const text = unescapePattern(pattern);
20
+ return escapePattern(text) === pattern ? text : void 0;
21
+ }
22
+ function definedKeys(condition) {
23
+ return Object.keys(condition).filter((key)=>'when' !== key && void 0 !== condition[key]);
24
+ }
25
+ function readCondition(stored, vocabulary, id) {
26
+ const keys = definedKeys(stored);
27
+ if (0 === keys.length) return createCondition({
28
+ id,
29
+ field: stored.when || void 0
30
+ });
31
+ if (void 0 !== stored.custom) {
32
+ const node = parseExpression(stored.custom);
33
+ return node && canRun(stored.custom, vocabulary.fields) ? parseCondition(node, vocabulary, id) : void 0;
34
+ }
35
+ if (keys.length > 1) return;
36
+ const field = stored.when;
37
+ let row;
38
+ if (void 0 !== stored.is) row = '' === stored.is ? {
39
+ field,
40
+ operator: 'isEmpty'
41
+ } : {
42
+ field,
43
+ operator: 'equals',
44
+ value: valueText(stored.is)
45
+ };
46
+ else if (void 0 !== stored.isNot) row = '' === stored.isNot ? {
47
+ field,
48
+ operator: 'isNotEmpty'
49
+ } : {
50
+ field,
51
+ operator: 'notEquals',
52
+ value: valueText(stored.isNot)
53
+ };
54
+ else if (void 0 !== stored.in) row = {
55
+ field,
56
+ operator: 'isOneOf',
57
+ values: stored.in.map(valueText)
58
+ };
59
+ else if (void 0 !== stored.notIn) row = {
60
+ field,
61
+ operator: 'isNotOneOf',
62
+ values: stored.notIn.map(valueText)
63
+ };
64
+ else if (void 0 !== stored.empty) row = {
65
+ field,
66
+ operator: stored.empty ? 'isEmpty' : 'isNotEmpty'
67
+ };
68
+ else {
69
+ const pattern = stored.matches ?? '';
70
+ const text = literalText(pattern);
71
+ const start = pattern.startsWith('^') ? literalText(pattern.slice(1)) : void 0;
72
+ row = void 0 !== text ? {
73
+ field,
74
+ operator: 'contains',
75
+ value: text
76
+ } : void 0 !== start ? {
77
+ field,
78
+ operator: 'startsWith',
79
+ value: start
80
+ } : {
81
+ field,
82
+ operator: 'matches',
83
+ value: pattern
84
+ };
85
+ }
86
+ const condition = createCondition({
87
+ id,
88
+ ...row
89
+ });
90
+ if (!offered(condition, vocabulary)) return;
91
+ const known = vocabulary.fields.some((option)=>option.value === field);
92
+ return !known || isComplete(condition, vocabulary) ? condition : void 0;
93
+ }
94
+ function readStoredCondition(stored, vocabulary, id) {
95
+ const condition = readCondition(stored, vocabulary, id);
96
+ const field = condition?.field;
97
+ if (condition && field && !vocabulary.fields.some((option)=>option.value === field)) unknownFieldConditions.set(condition, stored);
98
+ return condition;
99
+ }
100
+ function storedExpression(stored) {
101
+ if (0 === definedKeys(stored).length) return null;
102
+ if (void 0 !== stored.custom) return stored.custom;
103
+ if (!canName(stored.when)) return;
104
+ const name = stored.when;
105
+ const list = (values, symbol, joiner, none)=>0 === values.length ? none : values.map((value)=>`${name} ${symbol} ${printLiteral(value)}`).join(joiner);
106
+ if (void 0 !== stored.is) return `${name} === ${printLiteral(stored.is)}`;
107
+ if (void 0 !== stored.isNot) return `${name} !== ${printLiteral(stored.isNot)}`;
108
+ if (void 0 !== stored.in) return list(stored.in, '===', ' || ', 'false');
109
+ if (void 0 !== stored.notIn) return list(stored.notIn, '!==', ' && ', 'true');
110
+ }
111
+ function repairReason(stored, row, fields, strings) {
112
+ const field = fields.find((option)=>option.value === row.field);
113
+ if (!field) return;
114
+ const values = [
115
+ stored.is,
116
+ stored.isNot,
117
+ ...stored.in ?? [],
118
+ ...stored.notIn ?? []
119
+ ];
120
+ const mistyped = values.find((value)=>void 0 !== value && '' !== value && typedValue(field, valueText(value)) !== value);
121
+ if (void 0 === mistyped) return;
122
+ const expected = 'boolean' == typeof typedValue(field, valueText(mistyped)) ? 'boolean' : 'number';
123
+ return strings.repairComparedWithText(field.label, valueText(mistyped), expected);
124
+ }
125
+ function defaultOperators(strings) {
126
+ return strings ? createRulesEngineVocabulary({
127
+ strings
128
+ }).operators : RULES_ENGINE_OPERATORS;
129
+ }
130
+ function storedRuleExpression(stored, placeholder) {
131
+ const texts = stored.conditions.map(storedExpression);
132
+ if (texts.includes(void 0)) return;
133
+ const parts = texts.flatMap((text)=>null != text ? [
134
+ text
135
+ ] : void 0 === placeholder ? [] : [
136
+ placeholder
137
+ ]);
138
+ const joiner = 'OR' === stored.operator ? ' || ' : ' && ';
139
+ return 1 === parts.length ? parts[0] : parts.map((part)=>`(${part})`).join(joiner);
140
+ }
141
+ function storedFieldKeys(stored) {
142
+ const keys = stored.conditions.flatMap((condition)=>[
143
+ ...condition.when ? [
144
+ condition.when
145
+ ] : [],
146
+ ...void 0 === condition.custom ? [] : fieldKeysOf(condition.custom)
147
+ ]);
148
+ return Array.from(new Set(keys));
149
+ }
150
+ function matchOutcome(effects, outcomes) {
151
+ let best;
152
+ let claims = -1;
153
+ for (const outcome of outcomes){
154
+ const entries = Object.entries(outcome.effects);
155
+ const matches = entries.every(([key, value])=>effects[key] === value);
156
+ if (matches && entries.length > claims) {
157
+ best = outcome;
158
+ claims = entries.length;
159
+ }
160
+ }
161
+ return best;
162
+ }
163
+ function readRule(stored, index, options) {
164
+ const strings = {
165
+ ...DEFAULT_FIELD_RULES_STRINGS,
166
+ ...options.strings
167
+ };
168
+ const vocabulary = vocabularyOf(options);
169
+ const id = stored.id || `rule-${index}`;
170
+ const effects = stored.effects ?? {};
171
+ const outcome = matchOutcome(effects, options.outcomes);
172
+ const claimed = Object.keys(outcome?.effects ?? {});
173
+ const otherEffects = Object.fromEntries(Object.entries(effects).filter(([key])=>!claimed.includes(key)));
174
+ const base = {
175
+ id,
176
+ outcome: outcome?.value ?? '',
177
+ ...Object.keys(otherEffects).length > 0 ? {
178
+ otherEffects
179
+ } : {}
180
+ };
181
+ const preserved = ()=>({
182
+ ...base,
183
+ mode: 'preserved',
184
+ preservedSource: JSON.stringify({
185
+ operator: stored.operator ?? 'AND',
186
+ conditions: stored.conditions
187
+ }, null, 2),
188
+ fieldKeys: storedFieldKeys(stored),
189
+ saved: {
190
+ conditions: stored.conditions,
191
+ operator: stored.operator
192
+ }
193
+ });
194
+ const readRows = (conditions)=>conditions.map((condition, position)=>readStoredCondition(condition, vocabulary, `${id}-condition-${position}`));
195
+ const allRows = (found)=>found.every((row)=>void 0 !== row);
196
+ const upgrades = stored.conditions.map((condition)=>options.upgradeCondition?.(condition));
197
+ const rewritten = stored.conditions.map((condition, i)=>upgrades[i]?.condition ?? condition);
198
+ const upgradedRows = upgrades.some(Boolean) ? readRows(rewritten) : void 0;
199
+ const upgraded = upgradedRows && allRows(upgradedRows) ? upgradedRows : void 0;
200
+ const conditions = upgraded ? rewritten : stored.conditions;
201
+ const rows = upgraded ?? readRows(stored.conditions);
202
+ let rule;
203
+ if (allRows(rows)) {
204
+ rule = {
205
+ ...base,
206
+ mode: 'conditions',
207
+ conditions: createConditionGroup('OR' === stored.operator ? 'any' : 'all', rows, `${id}-conditions`)
208
+ };
209
+ const placeholders = stored.conditions.filter((c)=>0 === definedKeys(c).length).length;
210
+ const blocked = 'OR' !== stored.operator && placeholders > 0 && placeholders < stored.conditions.length;
211
+ const reason = upgraded ? upgrades.find((upgrade)=>void 0 !== upgrade)?.reason : blocked ? strings.repairEmptyCondition : conditions.map((condition, position)=>definedKeys(condition).length > 0 ? repairReason(condition, rows[position], options.fields, strings) : void 0).find((found)=>void 0 !== found);
212
+ if (reason) {
213
+ const expression = storedRuleExpression(stored, 'false');
214
+ const shown = void 0 === expression ? preserved() : {
215
+ ...base,
216
+ mode: 'expression',
217
+ expression,
218
+ saved: {
219
+ expression,
220
+ conditions: stored.conditions,
221
+ operator: stored.operator
222
+ }
223
+ };
224
+ rule = markRepairNeeded(shown, rule.conditions, reason);
225
+ }
226
+ } else {
227
+ const expression = storedRuleExpression(stored);
228
+ const saved = {
229
+ conditions: stored.conditions,
230
+ operator: stored.operator
231
+ };
232
+ rule = void 0 === expression ? preserved() : {
233
+ ...base,
234
+ mode: 'expression',
235
+ expression,
236
+ saved: {
237
+ ...saved,
238
+ expression
239
+ }
240
+ };
241
+ }
242
+ originals.set(rule, stored);
243
+ return rule;
244
+ }
245
+ function fromFieldRules(rules, options) {
246
+ return rules.map((rule, index)=>readRule(rule, index, options));
247
+ }
248
+ function writeCondition(c, vocabulary) {
249
+ const stored = unknownFieldConditions.get(c);
250
+ if (stored) return stored;
251
+ if (!isComplete(c, vocabulary)) return;
252
+ const resolved = resolveCondition(c, vocabulary);
253
+ const when = c.field ?? '';
254
+ const id = resolved.operator?.value;
255
+ const typed = (text)=>typedValue(resolved.field, text);
256
+ if ('isEmpty' === id || 'isNotEmpty' === id) {
257
+ const empty = 'isEmpty' === id;
258
+ if (resolved.field?.type === 'other') return {
259
+ when,
260
+ empty
261
+ };
262
+ if (!canName(when)) return empty ? {
263
+ when,
264
+ is: ''
265
+ } : {
266
+ when,
267
+ isNot: ''
268
+ };
269
+ return {
270
+ when,
271
+ custom: empty ? emptyCheck(when) : notEmptyCheck(when)
272
+ };
273
+ }
274
+ if ('literal' === resolved.mode) {
275
+ const value = c.value ?? '';
276
+ switch(id){
277
+ case 'equals':
278
+ return {
279
+ when,
280
+ is: typed(value)
281
+ };
282
+ case 'notEquals':
283
+ return {
284
+ when,
285
+ isNot: typed(value)
286
+ };
287
+ case 'isOneOf':
288
+ return {
289
+ when,
290
+ in: (c.values ?? []).map(typed)
291
+ };
292
+ case 'isNotOneOf':
293
+ return {
294
+ when,
295
+ notIn: (c.values ?? []).map(typed)
296
+ };
297
+ case 'contains':
298
+ return {
299
+ when,
300
+ matches: escapePattern(value)
301
+ };
302
+ case 'startsWith':
303
+ return {
304
+ when,
305
+ matches: `^${escapePattern(value)}`
306
+ };
307
+ case 'matches':
308
+ return {
309
+ when,
310
+ matches: value
311
+ };
312
+ }
313
+ }
314
+ const text = conditionExpression(c, vocabulary);
315
+ return void 0 === text ? void 0 : {
316
+ when,
317
+ custom: text
318
+ };
319
+ }
320
+ function writeGroup(group, vocabulary) {
321
+ const written = [];
322
+ for (const child of group.children){
323
+ const condition = 'condition' === child.kind ? writeCondition(child, vocabulary) : void 0;
324
+ if (condition) written.push(condition);
325
+ }
326
+ return written;
327
+ }
328
+ function writeRule(rule, options) {
329
+ const original = originals.get(rule);
330
+ if (original) return original;
331
+ const stored = rule;
332
+ const vocabulary = vocabularyOf(options);
333
+ const outcome = options.outcomes.find((option)=>option.value === rule.outcome);
334
+ const effects = {
335
+ ...stored.otherEffects,
336
+ ...outcome?.effects
337
+ };
338
+ const { saved } = stored;
339
+ if ('preserved' === rule.mode) return saved && {
340
+ id: rule.id,
341
+ conditions: saved.conditions,
342
+ operator: saved.operator,
343
+ effects
344
+ };
345
+ if ('expression' === rule.mode) {
346
+ if (saved && rule.expression === saved.expression) return {
347
+ id: rule.id,
348
+ conditions: saved.conditions,
349
+ operator: saved.operator,
350
+ effects
351
+ };
352
+ const expression = rule.expression.trim();
353
+ if (!expression) return;
354
+ const when = fieldKeysOf(expression)[0] ?? '';
355
+ return {
356
+ id: rule.id,
357
+ conditions: [
358
+ {
359
+ when,
360
+ custom: expression
361
+ }
362
+ ],
363
+ operator: 'AND',
364
+ effects
365
+ };
366
+ }
367
+ const written = writeGroup(rule.conditions, vocabulary);
368
+ if (rule.conditions.children.length > 0 && 0 === written.length) return;
369
+ return {
370
+ id: rule.id,
371
+ conditions: written,
372
+ operator: 'any' === rule.conditions.mode ? 'OR' : 'AND',
373
+ effects
374
+ };
375
+ }
376
+ function toFieldRules(rules, options) {
377
+ return rules.flatMap((rule)=>writeRule(rule, options) ?? []);
378
+ }
379
+ const REQUIRED_RULE_ID = 'required-flag';
380
+ function readStoredRules(stored, options) {
381
+ const rules = fromFieldRules(stored.rules ?? [], options);
382
+ const outcome = flagOutcome(options);
383
+ if (!outcome || !stored.required || rules.some((rule)=>isRequiredRule(rule, outcome))) return rules;
384
+ const conditions = createConditionGroup('all', [], `${REQUIRED_RULE_ID}-conditions`);
385
+ return [
386
+ createRule({
387
+ id: REQUIRED_RULE_ID,
388
+ outcome,
389
+ conditions
390
+ }),
391
+ ...rules
392
+ ];
393
+ }
394
+ function writeStoredRules(rules, options) {
395
+ const outcome = flagOutcome(options);
396
+ const index = outcome ? rules.findIndex((rule)=>isRequiredRule(rule, outcome)) : -1;
397
+ const overrides = rules.slice(0, Math.max(index, 0)).some((rule)=>(effectsOf(rule, options).required ?? true) !== true);
398
+ if (index < 0 || rules[index].otherEffects || overrides) return {
399
+ rules: toFieldRules(rules, options),
400
+ required: false
401
+ };
402
+ return {
403
+ rules: toFieldRules(rules.filter((_, position)=>position !== index), options),
404
+ required: true
405
+ };
406
+ }
407
+ function isRequiredRule(rule, outcome) {
408
+ return rule.outcome === outcome && isUnconditionalRule(rule);
409
+ }
410
+ function flagOutcome(options) {
411
+ const value = options.requiredOutcome;
412
+ const effects = options.outcomes.find((option)=>option.value === value)?.effects ?? {};
413
+ const keys = Object.keys(effects);
414
+ return 1 === keys.length && true === effects.required ? value : void 0;
415
+ }
416
+ function effectsOf(rule, options) {
417
+ const outcome = options.outcomes.find((option)=>option.value === rule.outcome);
418
+ return {
419
+ ...rule.otherEffects,
420
+ ...outcome?.effects
421
+ };
422
+ }
423
+ function alwaysApplying(rules) {
424
+ return new Set(rules.filter(isUnconditionalRule).map((rule)=>rule.id));
425
+ }
426
+ function settleAlways(rules, options, always) {
427
+ const vocabulary = vocabularyOf(options);
428
+ return rules.map((rule)=>'conditions' === rule.mode && rule.conditions.children.length > 0 && always.has(rule.id) && 0 === writeGroup(rule.conditions, vocabulary).length ? {
429
+ ...rule,
430
+ conditions: {
431
+ ...rule.conditions,
432
+ children: []
433
+ }
434
+ } : rule);
435
+ }
436
+ const namesField = (name, key)=>name === key || name.startsWith(`${key}.`);
437
+ function renameFieldInRules(rules, from, to) {
438
+ if (from === to || !from || !to) return [
439
+ ...rules
440
+ ];
441
+ return rules.map((rule)=>{
442
+ let changed = false;
443
+ const conditions = rule.conditions.map((condition)=>{
444
+ const when = namesField(condition.when, from) ? `${to}${condition.when.slice(from.length)}` : condition.when;
445
+ const custom = void 0 === condition.custom ? void 0 : renameInExpression(condition.custom, from, to);
446
+ if (when === condition.when && custom === condition.custom) return condition;
447
+ changed = true;
448
+ return {
449
+ ...condition,
450
+ when,
451
+ ...void 0 === custom ? {} : {
452
+ custom
453
+ }
454
+ };
455
+ });
456
+ return changed ? {
457
+ ...rule,
458
+ conditions
459
+ } : rule;
460
+ });
461
+ }
462
+ function rulesReferencing(rules, key) {
463
+ if (!key) return [];
464
+ return rules.flatMap((rule, index)=>rule.conditions.some((condition)=>namesField(condition.when, key) || void 0 !== condition.custom && fieldKeysOf(condition.custom).some((name)=>namesField(name, key))) ? [
465
+ rule.id || `rule-${index}`
466
+ ] : []);
467
+ }
468
+ export { alwaysApplying, flagOutcome, fromFieldRules, readStoredRules, renameFieldInRules, rulesReferencing, settleAlways, toFieldRules, writeStoredRules };