@valerypopoff/rivet2-core 2.10.0 → 2.12.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.
- package/dist/cjs/bundle.cjs +714 -493
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/esm/model/Nodes.js +3 -0
- package/dist/esm/model/nodes/CoalesceNewNode.js +1 -1
- package/dist/esm/model/nodes/CoalesceNode.js +1 -1
- package/dist/esm/model/nodes/GetGlobalNode.js +2 -6
- package/dist/esm/model/nodes/HttpCallNode.js +47 -16
- package/dist/esm/model/nodes/MatchCaseNode.js +132 -0
- package/dist/esm/model/nodes/MatchCaseNodeBase.js +237 -0
- package/dist/esm/model/nodes/MatchNode.js +24 -177
- package/dist/types/model/EditorDefinition.d.ts +2 -0
- package/dist/types/model/Nodes.d.ts +3 -2
- package/dist/types/model/nodes/MatchCaseNode.d.ts +43 -0
- package/dist/types/model/nodes/MatchCaseNodeBase.d.ts +52 -0
- package/dist/types/model/nodes/MatchNode.d.ts +13 -21
- package/package.json +1 -1
package/dist/esm/model/Nodes.js
CHANGED
|
@@ -22,6 +22,8 @@ import { expressionNode } from './nodes/ExpressionNode.js';
|
|
|
22
22
|
export * from './nodes/ExpressionNode.js';
|
|
23
23
|
import { matchNode } from './nodes/MatchNode.js';
|
|
24
24
|
export * from './nodes/MatchNode.js';
|
|
25
|
+
import { matchCaseNode } from './nodes/MatchCaseNode.js';
|
|
26
|
+
export * from './nodes/MatchCaseNode.js';
|
|
25
27
|
import { ifNode } from './nodes/IfNode.js';
|
|
26
28
|
export * from './nodes/IfNode.js';
|
|
27
29
|
import { readDirectoryNode } from './nodes/ReadDirectoryNode.js';
|
|
@@ -227,6 +229,7 @@ export const registerBuiltInNodes = (registry) => {
|
|
|
227
229
|
.register(codeNewNode)
|
|
228
230
|
.register(expressionNode)
|
|
229
231
|
.register(matchNode)
|
|
232
|
+
.register(matchCaseNode)
|
|
230
233
|
.register(ifNode)
|
|
231
234
|
.register(readDirectoryNode)
|
|
232
235
|
.register(readFileNode)
|
|
@@ -9,7 +9,7 @@ export class CoalesceNewNodeImpl extends CoalesceNodeBase {
|
|
|
9
9
|
static getUIData() {
|
|
10
10
|
return {
|
|
11
11
|
infoBoxBody: dedent `
|
|
12
|
-
Takes in any number of inputs and outputs the first value that is not "Not Ran". Useful for consolidating branches after a Match node.
|
|
12
|
+
Takes in any number of inputs and outputs the first value that is not "Not Ran". Useful for consolidating branches after a Match case node.
|
|
13
13
|
|
|
14
14
|
Null and undefined input values are emitted by default, but the node can be configured to skip either value and continue checking later inputs.
|
|
15
15
|
`,
|
|
@@ -12,7 +12,7 @@ export class CoalesceNodeImpl extends CoalesceNodeBase {
|
|
|
12
12
|
static getUIData() {
|
|
13
13
|
return {
|
|
14
14
|
infoBoxBody: dedent `
|
|
15
|
-
Legacy Coalesce node. Takes in any number of inputs and outputs the first value that is not "Not Ran". Useful for consolidating branches after a Match node.
|
|
15
|
+
Legacy Coalesce node. Takes in any number of inputs and outputs the first value that is not "Not Ran". Useful for consolidating branches after a Match case node.
|
|
16
16
|
|
|
17
17
|
Its Conditional input can exclude the node itself. New graphs should use Coalesce instead, which has the same fallback behavior without that port.
|
|
18
18
|
`,
|
|
@@ -60,16 +60,12 @@ export class GetGlobalNodeImpl extends NodeImpl {
|
|
|
60
60
|
return [
|
|
61
61
|
{
|
|
62
62
|
type: 'custom',
|
|
63
|
-
label: 'Search Global Variables',
|
|
64
|
-
customEditorId: 'GetGlobalVariableSelector',
|
|
65
|
-
autoFocus: true,
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
type: 'string',
|
|
69
63
|
label: 'Variable ID',
|
|
64
|
+
customEditorId: 'GetGlobalVariableSelector',
|
|
70
65
|
dataKey: 'id',
|
|
71
66
|
useInputToggleDataKey: 'useIdInput',
|
|
72
67
|
includeInGraphSearch: true,
|
|
68
|
+
autoFocus: true,
|
|
73
69
|
},
|
|
74
70
|
{
|
|
75
71
|
type: 'dataTypeSelector',
|
|
@@ -9,6 +9,7 @@ import { getError } from '../../utils/errors.js';
|
|
|
9
9
|
const REQUEST_FAILED_OUTPUT_ID = 'requestFailed';
|
|
10
10
|
const REQUEST_ERROR_OUTPUT_ID = 'requestError';
|
|
11
11
|
const STATUS_CODE_OUTPUT_ID = 'statusCode';
|
|
12
|
+
const RESPONSE_HEADERS_OUTPUT_ID = 'res_headers';
|
|
12
13
|
const DEFAULT_RETRY_ON_NON_200_REPEAT_TIMES = 1;
|
|
13
14
|
const DEFAULT_RETRY_ON_NON_200_COOLDOWN_MS = 0;
|
|
14
15
|
function isAbortError(error, signal) {
|
|
@@ -54,13 +55,18 @@ function formatCaughtRequestFailureError(error, seen = new Set()) {
|
|
|
54
55
|
function createHttpCallRequestAttempts() {
|
|
55
56
|
return {
|
|
56
57
|
statusCodeValues: [],
|
|
58
|
+
responseHeaderValues: [],
|
|
57
59
|
requestFailedValues: [],
|
|
58
60
|
requestErrorMessages: [],
|
|
59
61
|
};
|
|
60
62
|
}
|
|
63
|
+
function getHttpCallResponseHeaders(response) {
|
|
64
|
+
return Object.fromEntries(response.headers.entries());
|
|
65
|
+
}
|
|
61
66
|
function recordHttpCallResponseAttempt(attempts, response) {
|
|
62
67
|
const requestFailed = response.status !== 200;
|
|
63
68
|
attempts.statusCodeValues.push(response.status);
|
|
69
|
+
attempts.responseHeaderValues.push(getHttpCallResponseHeaders(response));
|
|
64
70
|
attempts.requestFailedValues.push(requestFailed);
|
|
65
71
|
if (requestFailed) {
|
|
66
72
|
attempts.requestErrorMessages.push(formatCaughtRequestFailureError(buildNon2xxStatusCodeError(response.status)));
|
|
@@ -84,6 +90,22 @@ function buildRetryAttemptOutput(type, values) {
|
|
|
84
90
|
value: undefined,
|
|
85
91
|
};
|
|
86
92
|
}
|
|
93
|
+
function buildHttpCallResponseMetadataOutputs(response, requestAttempts) {
|
|
94
|
+
return {
|
|
95
|
+
[STATUS_CODE_OUTPUT_ID]: requestAttempts
|
|
96
|
+
? buildRetryAttemptOutput('number[]', requestAttempts.statusCodeValues)
|
|
97
|
+
: {
|
|
98
|
+
type: 'number',
|
|
99
|
+
value: response.status,
|
|
100
|
+
},
|
|
101
|
+
[RESPONSE_HEADERS_OUTPUT_ID]: requestAttempts
|
|
102
|
+
? buildRetryAttemptOutput('object[]', requestAttempts.responseHeaderValues)
|
|
103
|
+
: {
|
|
104
|
+
type: 'object',
|
|
105
|
+
value: getHttpCallResponseHeaders(response),
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
87
109
|
function isCaughtFailureAlreadyRecorded(attempts, error) {
|
|
88
110
|
const formattedError = formatCaughtRequestFailureError(error);
|
|
89
111
|
if (attempts.requestErrorMessages.at(-1) === formattedError) {
|
|
@@ -104,7 +126,7 @@ function withCaughtFailureAttemptFallback(attempts, error) {
|
|
|
104
126
|
const requestFailedValues = attempts.requestFailedValues.length > 0 ? [...attempts.requestFailedValues] : [true];
|
|
105
127
|
requestFailedValues[requestFailedValues.length - 1] = true;
|
|
106
128
|
return {
|
|
107
|
-
|
|
129
|
+
...attempts,
|
|
108
130
|
requestFailedValues,
|
|
109
131
|
requestErrorMessages: [...attempts.requestErrorMessages, formatCaughtRequestFailureError(error)],
|
|
110
132
|
};
|
|
@@ -156,7 +178,7 @@ function buildRequestFailedOutputs(params) {
|
|
|
156
178
|
type: 'control-flow-excluded',
|
|
157
179
|
value: undefined,
|
|
158
180
|
},
|
|
159
|
-
[
|
|
181
|
+
[RESPONSE_HEADERS_OUTPUT_ID]: {
|
|
160
182
|
type: 'control-flow-excluded',
|
|
161
183
|
value: undefined,
|
|
162
184
|
},
|
|
@@ -321,8 +343,8 @@ export class HttpCallNodeImpl extends NodeImpl {
|
|
|
321
343
|
id: STATUS_CODE_OUTPUT_ID,
|
|
322
344
|
title: 'Status Code',
|
|
323
345
|
}, {
|
|
324
|
-
dataType: 'object',
|
|
325
|
-
id:
|
|
346
|
+
dataType: this.data.retryOnNon200 ? 'object[]' : 'object',
|
|
347
|
+
id: RESPONSE_HEADERS_OUTPUT_ID,
|
|
326
348
|
title: 'Headers',
|
|
327
349
|
});
|
|
328
350
|
if (this.data.catchRequestFailed || this.data.retryOnNon200) {
|
|
@@ -411,6 +433,9 @@ export class HttpCallNodeImpl extends NodeImpl {
|
|
|
411
433
|
type: 'toggle',
|
|
412
434
|
label: 'Fail on non-2XX status code',
|
|
413
435
|
dataKey: 'errorOnNon200',
|
|
436
|
+
helperMessage: (data) => data.retryOnNon200
|
|
437
|
+
? 'With Retry on non-200 enabled, only the final response after all retries is checked.'
|
|
438
|
+
: undefined,
|
|
414
439
|
},
|
|
415
440
|
{
|
|
416
441
|
type: 'toggle',
|
|
@@ -520,21 +545,27 @@ export class HttpCallNodeImpl extends NodeImpl {
|
|
|
520
545
|
response = await performTrackedRequest();
|
|
521
546
|
}
|
|
522
547
|
}
|
|
548
|
+
const responseMetadataOutputs = buildHttpCallResponseMetadataOutputs(response, requestAttempts);
|
|
523
549
|
if (this.data.errorOnNon200 && !response.ok) {
|
|
550
|
+
// The request reached the server, so retain its response metadata for
|
|
551
|
+
// display on the terminal nodeError. It remains inspection evidence,
|
|
552
|
+
// never a successful graph output. Caught failures return their
|
|
553
|
+
// existing normal output contract instead and must not leave a stale
|
|
554
|
+
// failure checkpoint behind.
|
|
555
|
+
if (!this.data.catchRequestFailed) {
|
|
556
|
+
// GraphProcessor supplies the durable terminal channel. Direct/custom
|
|
557
|
+
// node consumers receive the same metadata through their ordinary
|
|
558
|
+
// live-output callback when that channel is unavailable.
|
|
559
|
+
if (context.setFailureOutputs) {
|
|
560
|
+
context.setFailureOutputs(responseMetadataOutputs);
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
context.onPartialOutputs?.(responseMetadataOutputs);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
524
566
|
throw buildNon2xxStatusCodeError(response.status);
|
|
525
567
|
}
|
|
526
|
-
const output =
|
|
527
|
-
[STATUS_CODE_OUTPUT_ID]: requestAttempts
|
|
528
|
-
? buildRetryAttemptOutput('number[]', requestAttempts.statusCodeValues)
|
|
529
|
-
: {
|
|
530
|
-
type: 'number',
|
|
531
|
-
value: response.status,
|
|
532
|
-
},
|
|
533
|
-
['res_headers']: {
|
|
534
|
-
type: 'object',
|
|
535
|
-
value: Object.fromEntries(response.headers.entries()),
|
|
536
|
-
},
|
|
537
|
-
};
|
|
568
|
+
const output = responseMetadataOutputs;
|
|
538
569
|
if (this.data.isBinaryOutput) {
|
|
539
570
|
const responseBlob = await response.blob();
|
|
540
571
|
output['binary'] = {
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { nanoid } from 'nanoid/non-secure';
|
|
2
|
+
import { dedent } from 'ts-dedent';
|
|
3
|
+
import { nodeDefinition } from '../NodeDefinition.js';
|
|
4
|
+
import {} from '../NodeImpl.js';
|
|
5
|
+
import {} from '../NodeBase.js';
|
|
6
|
+
import {} from '../EditorDefinition.js';
|
|
7
|
+
import { MatchCaseNodeBase, } from './MatchCaseNodeBase.js';
|
|
8
|
+
/** Match case is the current routing node; legacy `match` remains regex-only. */
|
|
9
|
+
export class MatchCaseNodeImpl extends MatchCaseNodeBase {
|
|
10
|
+
caseEditorLabel = 'Cases';
|
|
11
|
+
caseEditorPlaceholder = 'Case';
|
|
12
|
+
casesEditorPlacement = 'before-trigger';
|
|
13
|
+
customCaseValuesEditorLabel = '';
|
|
14
|
+
defaultExclusive = true;
|
|
15
|
+
firstMatchingBodyValue = 'First matching case';
|
|
16
|
+
inputTitle = 'Input';
|
|
17
|
+
matchingCasesToTriggerOptions = [
|
|
18
|
+
{ value: true, label: 'First matching case' },
|
|
19
|
+
{ value: false, label: 'All matching cases' },
|
|
20
|
+
];
|
|
21
|
+
sharedCustomValueInputTitle = 'Return value';
|
|
22
|
+
triggerEditorLabel = 'Trigger';
|
|
23
|
+
static create() {
|
|
24
|
+
return {
|
|
25
|
+
type: 'matchCase',
|
|
26
|
+
title: 'Match case',
|
|
27
|
+
id: nanoid(),
|
|
28
|
+
visualData: {
|
|
29
|
+
x: 0,
|
|
30
|
+
y: 0,
|
|
31
|
+
width: 250,
|
|
32
|
+
},
|
|
33
|
+
data: {
|
|
34
|
+
cases: ['YES', 'NO'],
|
|
35
|
+
casePortIds: [nanoid(), nanoid()],
|
|
36
|
+
valueInputMode: 'shared',
|
|
37
|
+
matchMode: 'plainText',
|
|
38
|
+
caseSensitive: true,
|
|
39
|
+
exclusive: true,
|
|
40
|
+
returnValue: 'true',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
matchesCase(input, caseValue) {
|
|
45
|
+
if (this.getMatchMode() === 'regex') {
|
|
46
|
+
return new RegExp(caseValue).test(input);
|
|
47
|
+
}
|
|
48
|
+
if (this.getCaseSensitive()) {
|
|
49
|
+
return input === caseValue;
|
|
50
|
+
}
|
|
51
|
+
return input.toLowerCase() === caseValue.toLowerCase();
|
|
52
|
+
}
|
|
53
|
+
describeCaseMatch(caseValue) {
|
|
54
|
+
return this.getMatchMode() === 'plainText'
|
|
55
|
+
? this.getCaseSensitive()
|
|
56
|
+
? `the Input value exactly equals ${JSON.stringify(caseValue)}`
|
|
57
|
+
: `the Input value equals ${JSON.stringify(caseValue)} without regard to case`
|
|
58
|
+
: `/${caseValue}/ matches the Input value`;
|
|
59
|
+
}
|
|
60
|
+
describeNoCaseMatches() {
|
|
61
|
+
if (this.getMatchMode() === 'regex') {
|
|
62
|
+
return 'no regular expression matches the Input value';
|
|
63
|
+
}
|
|
64
|
+
return this.getCaseSensitive()
|
|
65
|
+
? 'no case exactly equals the Input value'
|
|
66
|
+
: 'no case equals the Input value without regard to case';
|
|
67
|
+
}
|
|
68
|
+
getReturnValueMode() {
|
|
69
|
+
return this.data.returnValue === 'testValue' || this.data.returnValue === 'custom'
|
|
70
|
+
? this.data.returnValue
|
|
71
|
+
: 'true';
|
|
72
|
+
}
|
|
73
|
+
getEditorsAfterTrigger() {
|
|
74
|
+
return [
|
|
75
|
+
{
|
|
76
|
+
type: 'segmented',
|
|
77
|
+
label: 'Output value',
|
|
78
|
+
dataKey: 'returnValue',
|
|
79
|
+
defaultValue: 'true',
|
|
80
|
+
options: [
|
|
81
|
+
{ value: 'true', label: 'True' },
|
|
82
|
+
{ value: 'testValue', label: 'Input value' },
|
|
83
|
+
{ value: 'custom', label: 'Custom' },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
shouldHideCustomCaseValues(data) {
|
|
89
|
+
return (data.returnValue ?? 'true') !== 'custom';
|
|
90
|
+
}
|
|
91
|
+
getEditors() {
|
|
92
|
+
return [
|
|
93
|
+
{
|
|
94
|
+
type: 'segmented',
|
|
95
|
+
label: 'Match mode',
|
|
96
|
+
dataKey: 'matchMode',
|
|
97
|
+
defaultValue: 'plainText',
|
|
98
|
+
options: [
|
|
99
|
+
{ value: 'plainText', label: 'Plain text' },
|
|
100
|
+
{ value: 'regex', label: 'Regular expression' },
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
type: 'toggle',
|
|
105
|
+
label: 'Case sensitive',
|
|
106
|
+
dataKey: 'caseSensitive',
|
|
107
|
+
defaultValue: true,
|
|
108
|
+
hideIf: (data) => data.matchMode === 'regex',
|
|
109
|
+
},
|
|
110
|
+
...super.getEditors(),
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
static getUIData() {
|
|
114
|
+
return {
|
|
115
|
+
infoBoxBody: dedent `
|
|
116
|
+
Routes an Input value to matching case outputs. Plain text cases use exact, case-sensitive equality by default; turn off Case sensitive to ignore letter case. Choose Regular expression to use the existing JavaScript RegExp pattern behavior; the Case sensitive switch does not apply in that mode.
|
|
117
|
+
|
|
118
|
+
Choose First matching case to trigger only the first matching output, or All matching cases to trigger every matching output. Active outputs return True by default. They can instead return the Input value, or a custom value supplied through one shared Return value input or separate Return values inputs for every case and Unmatched.
|
|
119
|
+
`,
|
|
120
|
+
infoBoxTitle: 'Match case Node',
|
|
121
|
+
contextMenuTitle: 'Match case',
|
|
122
|
+
group: ['Logic'],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
getMatchMode() {
|
|
126
|
+
return this.data.matchMode === 'regex' ? 'regex' : 'plainText';
|
|
127
|
+
}
|
|
128
|
+
getCaseSensitive() {
|
|
129
|
+
return this.data.caseSensitive !== false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
export const matchCaseNode = nodeDefinition(MatchCaseNodeImpl, 'Match case');
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import {} from '../DataValue.js';
|
|
2
|
+
import {} from '../EditorDefinition.js';
|
|
3
|
+
import {} from '../GraphProcessor.js';
|
|
4
|
+
import { NodeImpl } from '../NodeImpl.js';
|
|
5
|
+
import {} from '../NodeBase.js';
|
|
6
|
+
import { coerceType } from '../../utils/coerceType.js';
|
|
7
|
+
import { resolveStoredOrderedPortIds } from '../../utils/orderedStringPortIds.js';
|
|
8
|
+
/**
|
|
9
|
+
* Shared ports, custom-value routing, and case-output handling for the current
|
|
10
|
+
* Match case node and the regex-only compatibility node. Each subclass owns
|
|
11
|
+
* only its matching semantics and editor wording.
|
|
12
|
+
*/
|
|
13
|
+
export class MatchCaseNodeBase extends NodeImpl {
|
|
14
|
+
casesEditorPlacement = 'after-custom-values';
|
|
15
|
+
customCaseValuesEditorLabel = 'Custom case values';
|
|
16
|
+
defaultExclusive = false;
|
|
17
|
+
firstMatchingBodyValue = 'First matching case only';
|
|
18
|
+
inputTitle = 'Test';
|
|
19
|
+
matchingCasesToTriggerOptions = [
|
|
20
|
+
{ value: false, label: 'Trigger all matching cases' },
|
|
21
|
+
{ value: true, label: 'Trigger first only' },
|
|
22
|
+
];
|
|
23
|
+
sharedCustomValueInputTitle = 'Custom value';
|
|
24
|
+
triggerEditorLabel = 'Matching cases to trigger';
|
|
25
|
+
getReturnValueMode() {
|
|
26
|
+
return 'custom';
|
|
27
|
+
}
|
|
28
|
+
getEditorsAfterTrigger() {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
shouldHideCustomCaseValues(_data) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
getInputDefinitions() {
|
|
35
|
+
const inputs = [
|
|
36
|
+
{
|
|
37
|
+
id: 'input',
|
|
38
|
+
title: this.inputTitle,
|
|
39
|
+
dataType: 'string',
|
|
40
|
+
required: true,
|
|
41
|
+
description: `The ${this.inputTitle} value tested against each case.`,
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
if (this.getReturnValueMode() !== 'custom') {
|
|
45
|
+
return inputs;
|
|
46
|
+
}
|
|
47
|
+
if (this.getValueInputMode() === 'shared') {
|
|
48
|
+
inputs.push({
|
|
49
|
+
id: 'value',
|
|
50
|
+
title: this.sharedCustomValueInputTitle,
|
|
51
|
+
dataType: 'any',
|
|
52
|
+
description: `The optional value passed through to every matching output. If unconnected, the ${this.inputTitle} value is passed through.`,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const portIds = this.getCasePortIds();
|
|
57
|
+
this.data.cases.forEach((caseValue, index) => {
|
|
58
|
+
inputs.push({
|
|
59
|
+
id: this.getCaseValueInputId(portIds[index]),
|
|
60
|
+
title: this.getCaseTitle(caseValue, index),
|
|
61
|
+
dataType: 'any',
|
|
62
|
+
description: `The optional custom value emitted when ${this.describeCaseMatch(caseValue)}. If unconnected, ${this.inputTitle} is passed through.`,
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
inputs.push({
|
|
66
|
+
id: 'value-unmatched',
|
|
67
|
+
title: 'Unmatched',
|
|
68
|
+
dataType: 'any',
|
|
69
|
+
description: `The optional custom value emitted when ${this.describeNoCaseMatches()}. If unconnected, ${this.inputTitle} is passed through.`,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return inputs;
|
|
73
|
+
}
|
|
74
|
+
getOutputDefinitions() {
|
|
75
|
+
const outputs = [];
|
|
76
|
+
const portIds = this.getCasePortIds();
|
|
77
|
+
const returnValueMode = this.getReturnValueMode();
|
|
78
|
+
const dataType = returnValueMode === 'true' ? 'boolean' : returnValueMode === 'testValue' ? 'string' : 'any';
|
|
79
|
+
for (let index = 0; index < this.data.cases.length; index++) {
|
|
80
|
+
const caseValue = this.data.cases[index];
|
|
81
|
+
const title = this.getCaseTitle(caseValue, index);
|
|
82
|
+
outputs.push({
|
|
83
|
+
id: portIds[index],
|
|
84
|
+
title,
|
|
85
|
+
dataType,
|
|
86
|
+
description: this.getMatchingOutputDescription(caseValue, title),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
outputs.push({
|
|
90
|
+
id: 'unmatched',
|
|
91
|
+
title: 'Unmatched',
|
|
92
|
+
dataType,
|
|
93
|
+
description: this.getUnmatchedOutputDescription(),
|
|
94
|
+
});
|
|
95
|
+
return outputs;
|
|
96
|
+
}
|
|
97
|
+
getBody() {
|
|
98
|
+
return this.getExclusive() ? `Trigger: ${this.firstMatchingBodyValue}` : 'Trigger: All matching cases';
|
|
99
|
+
}
|
|
100
|
+
getEditors() {
|
|
101
|
+
const casesEditor = {
|
|
102
|
+
type: 'stringList',
|
|
103
|
+
dataKey: 'cases',
|
|
104
|
+
label: this.caseEditorLabel,
|
|
105
|
+
placeholder: this.caseEditorPlaceholder,
|
|
106
|
+
reorderable: true,
|
|
107
|
+
portBinding: {
|
|
108
|
+
side: 'output',
|
|
109
|
+
identity: 'stored-stable-id',
|
|
110
|
+
idDataKey: 'casePortIds',
|
|
111
|
+
legacyPortIdPattern: {
|
|
112
|
+
kind: 'prefix',
|
|
113
|
+
prefix: 'case',
|
|
114
|
+
startIndex: 1,
|
|
115
|
+
},
|
|
116
|
+
companionBindings: [{ side: 'input', prefix: 'value-' }],
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
return [
|
|
120
|
+
...(this.casesEditorPlacement === 'before-trigger' ? [casesEditor] : []),
|
|
121
|
+
{
|
|
122
|
+
type: 'segmented',
|
|
123
|
+
label: this.triggerEditorLabel,
|
|
124
|
+
dataKey: 'exclusive',
|
|
125
|
+
defaultValue: this.defaultExclusive,
|
|
126
|
+
options: this.matchingCasesToTriggerOptions,
|
|
127
|
+
},
|
|
128
|
+
...this.getEditorsAfterTrigger(),
|
|
129
|
+
{
|
|
130
|
+
type: 'segmented',
|
|
131
|
+
label: this.customCaseValuesEditorLabel,
|
|
132
|
+
ariaLabel: 'Custom case values',
|
|
133
|
+
dataKey: 'valueInputMode',
|
|
134
|
+
defaultValue: 'shared',
|
|
135
|
+
hideIf: (data) => this.shouldHideCustomCaseValues(data),
|
|
136
|
+
options: [
|
|
137
|
+
{ value: 'shared', label: 'One shared custom value' },
|
|
138
|
+
{ value: 'per-output', label: 'Custom values per case' },
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
...(this.casesEditorPlacement === 'after-custom-values' ? [casesEditor] : []),
|
|
142
|
+
];
|
|
143
|
+
}
|
|
144
|
+
async process(inputs) {
|
|
145
|
+
const inputValue = inputs['input'];
|
|
146
|
+
const inputString = inputValue?.value == null ? undefined : coerceType(inputValue, 'string');
|
|
147
|
+
const portIds = this.getCasePortIds();
|
|
148
|
+
const sharedValue = inputs['value'];
|
|
149
|
+
const returnValueMode = this.getReturnValueMode();
|
|
150
|
+
const getInputOutputValue = () => ({
|
|
151
|
+
type: 'string',
|
|
152
|
+
value: inputString,
|
|
153
|
+
});
|
|
154
|
+
const getSharedOutputValue = () => sharedValue ?? getInputOutputValue();
|
|
155
|
+
const getConfiguredOutputValue = (customValueInputId) => {
|
|
156
|
+
if (returnValueMode === 'true') {
|
|
157
|
+
return { type: 'boolean', value: true };
|
|
158
|
+
}
|
|
159
|
+
if (returnValueMode === 'testValue') {
|
|
160
|
+
return getInputOutputValue();
|
|
161
|
+
}
|
|
162
|
+
return this.getValueInputMode() === 'shared'
|
|
163
|
+
? getSharedOutputValue()
|
|
164
|
+
: inputs[customValueInputId] ?? getInputOutputValue();
|
|
165
|
+
};
|
|
166
|
+
const getOutputValue = (portId) => getConfiguredOutputValue(this.getCaseValueInputId(portId));
|
|
167
|
+
const getUnmatchedOutputValue = () => getConfiguredOutputValue('value-unmatched');
|
|
168
|
+
let matched = false;
|
|
169
|
+
const output = {};
|
|
170
|
+
for (let index = 0; index < this.data.cases.length; index++) {
|
|
171
|
+
const caseValue = this.data.cases[index];
|
|
172
|
+
const matches = inputString !== undefined && this.matchesCase(inputString, caseValue);
|
|
173
|
+
const canMatch = !this.getExclusive() || !matched;
|
|
174
|
+
const portId = portIds[index];
|
|
175
|
+
if (matches && canMatch) {
|
|
176
|
+
matched = true;
|
|
177
|
+
output[portId] = getOutputValue(portId);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
output[portId] = {
|
|
181
|
+
type: 'control-flow-excluded',
|
|
182
|
+
value: undefined,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
output['unmatched'] = matched
|
|
187
|
+
? {
|
|
188
|
+
type: 'control-flow-excluded',
|
|
189
|
+
value: undefined,
|
|
190
|
+
}
|
|
191
|
+
: getUnmatchedOutputValue();
|
|
192
|
+
return output;
|
|
193
|
+
}
|
|
194
|
+
getValueInputMode() {
|
|
195
|
+
return this.data.valueInputMode === 'per-output' ? 'per-output' : 'shared';
|
|
196
|
+
}
|
|
197
|
+
getExclusive() {
|
|
198
|
+
return this.data.exclusive ?? this.defaultExclusive;
|
|
199
|
+
}
|
|
200
|
+
getMatchingOutputDescription(caseValue, title) {
|
|
201
|
+
const condition = this.describeCaseMatch(caseValue);
|
|
202
|
+
if (this.getReturnValueMode() === 'true') {
|
|
203
|
+
return `True if ${condition}.`;
|
|
204
|
+
}
|
|
205
|
+
if (this.getReturnValueMode() === 'testValue') {
|
|
206
|
+
return `The ${this.inputTitle} value passed through if ${condition}.`;
|
|
207
|
+
}
|
|
208
|
+
return this.getValueInputMode() === 'shared'
|
|
209
|
+
? `The shared ${this.sharedCustomValueInputTitle} (or ${this.inputTitle} if it is unconnected) passed through if ${condition}.`
|
|
210
|
+
: `The corresponding ${title} custom value (or ${this.inputTitle} if it is unconnected) passed through if ${condition}.`;
|
|
211
|
+
}
|
|
212
|
+
getUnmatchedOutputDescription() {
|
|
213
|
+
const condition = this.describeNoCaseMatches();
|
|
214
|
+
if (this.getReturnValueMode() === 'true') {
|
|
215
|
+
return `True if ${condition}.`;
|
|
216
|
+
}
|
|
217
|
+
if (this.getReturnValueMode() === 'testValue') {
|
|
218
|
+
return `The ${this.inputTitle} value passed through if ${condition}.`;
|
|
219
|
+
}
|
|
220
|
+
return this.getValueInputMode() === 'shared'
|
|
221
|
+
? `The shared ${this.sharedCustomValueInputTitle} (or ${this.inputTitle} if it is unconnected) passed through if ${condition}.`
|
|
222
|
+
: `The Unmatched custom value (or ${this.inputTitle} if it is unconnected) passed through if ${condition}.`;
|
|
223
|
+
}
|
|
224
|
+
getCasePortIds() {
|
|
225
|
+
return resolveStoredOrderedPortIds(this.data.cases.length, this.data.casePortIds, {
|
|
226
|
+
kind: 'prefix',
|
|
227
|
+
prefix: 'case',
|
|
228
|
+
startIndex: 1,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
getCaseTitle(caseValue, index) {
|
|
232
|
+
return caseValue?.trim() ? caseValue : `Case ${index + 1}`;
|
|
233
|
+
}
|
|
234
|
+
getCaseValueInputId(portId) {
|
|
235
|
+
return `value-${portId}`;
|
|
236
|
+
}
|
|
237
|
+
}
|