@lowdefy/api 4.3.2 → 4.5.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/LICENSE +183 -183
- package/dist/context/createApiContext.js +4 -2
- package/dist/context/createEvaluateOperators.js +26 -0
- package/dist/index.js +3 -2
- package/dist/routes/endpoints/addStepResult.js +23 -0
- package/dist/routes/endpoints/authorizeApiEndpoint.js +31 -0
- package/dist/routes/endpoints/callEndpoint.js +58 -0
- package/dist/routes/endpoints/control/controlFor.js +68 -0
- package/dist/routes/endpoints/control/controlIf.js +53 -0
- package/dist/routes/endpoints/control/controlLog.js +43 -0
- package/dist/routes/endpoints/control/controlParallel.js +44 -0
- package/dist/routes/endpoints/control/controlParallelFor.js +76 -0
- package/dist/routes/endpoints/control/controlReject.js +40 -0
- package/dist/routes/endpoints/control/controlReturn.js +32 -0
- package/dist/routes/endpoints/control/controlSetState.js +22 -0
- package/dist/routes/endpoints/control/controlSwitch.js +60 -0
- package/dist/routes/endpoints/control/controlThrow.js +40 -0
- package/dist/routes/endpoints/control/controlTry.js +46 -0
- package/dist/routes/endpoints/control/handleControl.js +51 -0
- package/dist/routes/endpoints/getEndpointConfig.js +30 -0
- package/dist/routes/endpoints/handleRequest.js +85 -0
- package/dist/routes/endpoints/runRoutine.js +60 -0
- package/dist/routes/endpoints/test/runTest.js +107 -0
- package/dist/routes/request/callRequest.js +5 -4
- package/dist/routes/request/callRequestResolver.js +3 -2
- package/dist/routes/request/evaluateOperators.js +4 -18
- package/dist/test/testContext.js +4 -1
- package/package.json +7 -7
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import runRoutine from '../runRoutine.js';
|
|
16
|
+
async function controlIf(context, routineContext, { control }) {
|
|
17
|
+
const { logger, evaluateOperators } = context;
|
|
18
|
+
const { items } = routineContext;
|
|
19
|
+
const evaluatedIf = evaluateOperators({
|
|
20
|
+
input: control[':if'],
|
|
21
|
+
items,
|
|
22
|
+
location: 'TODO:'
|
|
23
|
+
});
|
|
24
|
+
logger.debug({
|
|
25
|
+
event: 'debug_control_if',
|
|
26
|
+
condition: {
|
|
27
|
+
input: control[':if'],
|
|
28
|
+
evaluated: evaluatedIf
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
if (evaluatedIf) {
|
|
32
|
+
logger.debug({
|
|
33
|
+
event: 'debug_control_if_run_then'
|
|
34
|
+
});
|
|
35
|
+
if (!control[':then']) {
|
|
36
|
+
throw new Error('Invalid :if - missing :then.');
|
|
37
|
+
}
|
|
38
|
+
return runRoutine(context, routineContext, {
|
|
39
|
+
routine: control[':then']
|
|
40
|
+
});
|
|
41
|
+
} else if (control[':else']) {
|
|
42
|
+
logger.debug({
|
|
43
|
+
event: 'debug_control_if_run_else'
|
|
44
|
+
});
|
|
45
|
+
return runRoutine(context, routineContext, {
|
|
46
|
+
routine: control[':else']
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
status: 'continue'
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export default controlIf;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
async function controlLog(context, routineContext, { control }) {
|
|
17
|
+
const { logger, evaluateOperators } = context;
|
|
18
|
+
const { items } = routineContext;
|
|
19
|
+
logger.debug({
|
|
20
|
+
event: 'debug_control_log'
|
|
21
|
+
});
|
|
22
|
+
const log = evaluateOperators({
|
|
23
|
+
input: control[':log'],
|
|
24
|
+
items,
|
|
25
|
+
location: 'TODO:'
|
|
26
|
+
});
|
|
27
|
+
const logLevel = evaluateOperators({
|
|
28
|
+
input: control[':level'],
|
|
29
|
+
items,
|
|
30
|
+
location: 'TODO:'
|
|
31
|
+
}) ?? 'info';
|
|
32
|
+
if (!type.isString(logLevel)) {
|
|
33
|
+
throw new Error(`Unrecognised type for :level. Received ${logLevel}.`);
|
|
34
|
+
}
|
|
35
|
+
if (!logger[logLevel]) {
|
|
36
|
+
throw new Error(`Invalid log level for :log. Received ${logLevel}.`);
|
|
37
|
+
}
|
|
38
|
+
logger[logLevel](log);
|
|
39
|
+
return {
|
|
40
|
+
status: 'continue'
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export default controlLog;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import runRoutine from '../runRoutine.js';
|
|
16
|
+
async function controlParallel(context, routineContext, { control }) {
|
|
17
|
+
const { logger } = context;
|
|
18
|
+
logger.debug({
|
|
19
|
+
event: 'debug_control_parallel'
|
|
20
|
+
});
|
|
21
|
+
const results = await Promise.all(control[':parallel'].map((subRoutine)=>{
|
|
22
|
+
logger.debug({
|
|
23
|
+
event: 'debug_control_parallel_start',
|
|
24
|
+
start: Date.now()
|
|
25
|
+
});
|
|
26
|
+
return runRoutine(context, routineContext, {
|
|
27
|
+
routine: subRoutine
|
|
28
|
+
});
|
|
29
|
+
}));
|
|
30
|
+
const resultsMap = {
|
|
31
|
+
error: [],
|
|
32
|
+
reject: [],
|
|
33
|
+
return: [],
|
|
34
|
+
continue: []
|
|
35
|
+
};
|
|
36
|
+
results.forEach((res)=>resultsMap[res.status] = [
|
|
37
|
+
...resultsMap[res.status],
|
|
38
|
+
res
|
|
39
|
+
]);
|
|
40
|
+
return resultsMap.error?.[0] ?? resultsMap.reject?.[0] ?? resultsMap.return?.[0] ?? {
|
|
41
|
+
status: 'continue'
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export default controlParallel;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import runRoutine from '../runRoutine.js';
|
|
16
|
+
async function controlParallelFor(context, routineContext, { control }) {
|
|
17
|
+
const { logger, evaluateOperators } = context;
|
|
18
|
+
const { items } = routineContext;
|
|
19
|
+
const itemName = control[':parallel_for'];
|
|
20
|
+
if (!itemName) {
|
|
21
|
+
throw new Error('Invalid :parallel_for - missing variable name in :parallel_for.');
|
|
22
|
+
}
|
|
23
|
+
const array = evaluateOperators({
|
|
24
|
+
input: control[':in'],
|
|
25
|
+
items,
|
|
26
|
+
location: 'controlParallelFor'
|
|
27
|
+
});
|
|
28
|
+
logger.debug({
|
|
29
|
+
event: 'debug_control_parallel',
|
|
30
|
+
array,
|
|
31
|
+
itemName
|
|
32
|
+
});
|
|
33
|
+
if (!Array.isArray(array)) {
|
|
34
|
+
throw new Error('Invalid :parallel_for - evaluated :in to non-array.');
|
|
35
|
+
}
|
|
36
|
+
if (!control[':do']) {
|
|
37
|
+
throw new Error('Invalid :parallel_for - missing :do.');
|
|
38
|
+
}
|
|
39
|
+
const promises = array.map((item, index)=>{
|
|
40
|
+
const updatedItems = {
|
|
41
|
+
...items,
|
|
42
|
+
[itemName]: item
|
|
43
|
+
};
|
|
44
|
+
logger.debug({
|
|
45
|
+
event: 'debug_control_parallel_iteration',
|
|
46
|
+
itemName: itemName,
|
|
47
|
+
value: item,
|
|
48
|
+
items: updatedItems
|
|
49
|
+
});
|
|
50
|
+
return runRoutine(context, {
|
|
51
|
+
...routineContext,
|
|
52
|
+
arrayIndices: [
|
|
53
|
+
...routineContext.arrayIndices,
|
|
54
|
+
index
|
|
55
|
+
],
|
|
56
|
+
items: updatedItems
|
|
57
|
+
}, {
|
|
58
|
+
routine: control[':do']
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
const results = await Promise.all(promises);
|
|
62
|
+
const resultsMap = {
|
|
63
|
+
error: [],
|
|
64
|
+
reject: [],
|
|
65
|
+
return: [],
|
|
66
|
+
continue: []
|
|
67
|
+
};
|
|
68
|
+
results.forEach((res)=>resultsMap[res.status] = [
|
|
69
|
+
...resultsMap[res.status],
|
|
70
|
+
res
|
|
71
|
+
]);
|
|
72
|
+
return resultsMap.error?.[0] ?? resultsMap.reject?.[0] ?? resultsMap.return?.[0] ?? {
|
|
73
|
+
status: 'continue'
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export default controlParallelFor;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ async function controlReject(context, routineContext, { control }) {
|
|
16
|
+
const { evaluateOperators } = context;
|
|
17
|
+
const { items } = routineContext;
|
|
18
|
+
const message = evaluateOperators({
|
|
19
|
+
input: control[':reject'],
|
|
20
|
+
items,
|
|
21
|
+
location: 'TODO'
|
|
22
|
+
});
|
|
23
|
+
const cause = evaluateOperators({
|
|
24
|
+
input: control[':cause'],
|
|
25
|
+
items,
|
|
26
|
+
location: 'TODO'
|
|
27
|
+
});
|
|
28
|
+
const error = new Error(message, {
|
|
29
|
+
cause
|
|
30
|
+
});
|
|
31
|
+
context.logger.warn({
|
|
32
|
+
event: 'warn_control_reject',
|
|
33
|
+
error
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
status: 'reject',
|
|
37
|
+
error
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export default controlReject;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ async function controlReturn(context, routineContext, { control }) {
|
|
16
|
+
const { evaluateOperators } = context;
|
|
17
|
+
const { items } = routineContext;
|
|
18
|
+
const response = evaluateOperators({
|
|
19
|
+
input: control[':return'],
|
|
20
|
+
items,
|
|
21
|
+
location: 'TODO'
|
|
22
|
+
});
|
|
23
|
+
context.logger.debug({
|
|
24
|
+
event: 'debug_control_return',
|
|
25
|
+
response
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
status: 'return',
|
|
29
|
+
response
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export default controlReturn;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { set } from '@lowdefy/helpers';
|
|
2
|
+
function controlSetState(context, routineContext, { control }) {
|
|
3
|
+
const { logger, evaluateOperators } = context;
|
|
4
|
+
const { items } = routineContext;
|
|
5
|
+
const evaluatedSetState = evaluateOperators({
|
|
6
|
+
input: control[':set_state'],
|
|
7
|
+
items,
|
|
8
|
+
location: 'TODO:'
|
|
9
|
+
});
|
|
10
|
+
logger.debug({
|
|
11
|
+
event: 'debug_control_set_state',
|
|
12
|
+
input: control[':set_state'],
|
|
13
|
+
evaluated: evaluatedSetState
|
|
14
|
+
});
|
|
15
|
+
Object.entries(evaluatedSetState).forEach(([key, value])=>{
|
|
16
|
+
set(context.state, key, value);
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
status: 'continue'
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export default controlSetState;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import runRoutine from '../runRoutine.js';
|
|
16
|
+
async function controlSwitch(context, routineContext, { control }) {
|
|
17
|
+
const { logger, evaluateOperators } = context;
|
|
18
|
+
const { items } = routineContext;
|
|
19
|
+
const cases = control[':switch'];
|
|
20
|
+
logger.debug({
|
|
21
|
+
event: 'debug_control_switch'
|
|
22
|
+
});
|
|
23
|
+
for (const caseObj of cases){
|
|
24
|
+
const evaluatedCase = evaluateOperators({
|
|
25
|
+
input: caseObj[':case'],
|
|
26
|
+
items,
|
|
27
|
+
location: 'TODO'
|
|
28
|
+
});
|
|
29
|
+
logger.debug({
|
|
30
|
+
event: 'debug_control_switch_case',
|
|
31
|
+
case: {
|
|
32
|
+
input: caseObj[':case'],
|
|
33
|
+
evaluated: evaluatedCase
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
if (evaluatedCase) {
|
|
37
|
+
logger.debug({
|
|
38
|
+
event: 'debug_control_switch_run_then'
|
|
39
|
+
});
|
|
40
|
+
if (!caseObj[':then']) {
|
|
41
|
+
throw new Error('Invalid switch :case - missing :then');
|
|
42
|
+
}
|
|
43
|
+
return runRoutine(context, routineContext, {
|
|
44
|
+
routine: caseObj[':then']
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (control[':default']) {
|
|
49
|
+
logger.debug({
|
|
50
|
+
event: 'debug_control_switch_run_default'
|
|
51
|
+
});
|
|
52
|
+
return runRoutine(context, routineContext, {
|
|
53
|
+
routine: control[':default']
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
status: 'continue'
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export default controlSwitch;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ async function controlThrow(context, routineContext, { control }) {
|
|
16
|
+
const { evaluateOperators } = context;
|
|
17
|
+
const { items } = routineContext;
|
|
18
|
+
const message = evaluateOperators({
|
|
19
|
+
input: control[':throw'],
|
|
20
|
+
items,
|
|
21
|
+
location: 'TODO'
|
|
22
|
+
});
|
|
23
|
+
const cause = evaluateOperators({
|
|
24
|
+
input: control[':cause'],
|
|
25
|
+
items,
|
|
26
|
+
location: 'TODO'
|
|
27
|
+
});
|
|
28
|
+
const error = new Error(message, {
|
|
29
|
+
cause
|
|
30
|
+
});
|
|
31
|
+
context.logger.error({
|
|
32
|
+
event: 'error_control_throw',
|
|
33
|
+
error
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
status: 'error',
|
|
37
|
+
error
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export default controlThrow;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import runRoutine from '../runRoutine.js';
|
|
16
|
+
async function controlTry(context, routineContext, { control }) {
|
|
17
|
+
context.logger.debug({
|
|
18
|
+
event: 'debug_control_try'
|
|
19
|
+
});
|
|
20
|
+
let res = await runRoutine(context, routineContext, {
|
|
21
|
+
routine: control[':try']
|
|
22
|
+
});
|
|
23
|
+
if (res.status === 'error') {
|
|
24
|
+
if (control[':catch']) {
|
|
25
|
+
context.logger.debug({
|
|
26
|
+
event: 'debug_control_catch'
|
|
27
|
+
});
|
|
28
|
+
res = await runRoutine(context, routineContext, {
|
|
29
|
+
routine: control[':catch']
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (control[':finally']) {
|
|
34
|
+
context.logger.debug({
|
|
35
|
+
event: 'debug_control_finally'
|
|
36
|
+
});
|
|
37
|
+
const finallyRes = await runRoutine(context, routineContext, {
|
|
38
|
+
routine: control[':finally']
|
|
39
|
+
});
|
|
40
|
+
if (finallyRes.status !== 'continue') {
|
|
41
|
+
res = finallyRes;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return res;
|
|
45
|
+
}
|
|
46
|
+
export default controlTry;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import controlFor from './controlFor.js';
|
|
16
|
+
import controlIf from './controlIf.js';
|
|
17
|
+
import controlLog from './controlLog.js';
|
|
18
|
+
import controlParallel from './controlParallel.js';
|
|
19
|
+
import controlParallelFor from './controlParallelFor.js';
|
|
20
|
+
import controlReject from './controlReject.js';
|
|
21
|
+
import controlReturn from './controlReturn.js';
|
|
22
|
+
import controlSetState from './controlSetState.js';
|
|
23
|
+
import controlSwitch from './controlSwitch.js';
|
|
24
|
+
import controlThrow from './controlThrow.js';
|
|
25
|
+
import controlTry from './controlTry.js';
|
|
26
|
+
const controlHandlers = {
|
|
27
|
+
':for': controlFor,
|
|
28
|
+
':if': controlIf,
|
|
29
|
+
':log': controlLog,
|
|
30
|
+
':parallel_for': controlParallelFor,
|
|
31
|
+
':parallel': controlParallel,
|
|
32
|
+
':reject': controlReject,
|
|
33
|
+
':return': controlReturn,
|
|
34
|
+
':set_state': controlSetState,
|
|
35
|
+
':switch': controlSwitch,
|
|
36
|
+
':throw': controlThrow,
|
|
37
|
+
':try': controlTry
|
|
38
|
+
};
|
|
39
|
+
async function handleControl(context, routineContext, { control }) {
|
|
40
|
+
for (const [key, handler] of Object.entries(controlHandlers)){
|
|
41
|
+
if (key in control) {
|
|
42
|
+
return await handler(context, routineContext, {
|
|
43
|
+
control
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
throw new Error('Unexpected control.', {
|
|
48
|
+
cause: control
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export default handleControl;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { ConfigurationError } from '../../context/errors.js';
|
|
16
|
+
async function getEndpointConfig({ logger, readConfigFile }, { endpointId }) {
|
|
17
|
+
const endpoint = await readConfigFile(`api/${endpointId}.json`);
|
|
18
|
+
if (!endpoint) {
|
|
19
|
+
const err = new ConfigurationError(`API Endpoint "${endpointId}" does not exist.`);
|
|
20
|
+
logger.debug({
|
|
21
|
+
params: {
|
|
22
|
+
endpointId
|
|
23
|
+
},
|
|
24
|
+
err
|
|
25
|
+
}, err.message);
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
return endpoint;
|
|
29
|
+
}
|
|
30
|
+
export default getEndpointConfig;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import addStepResult from './addStepResult.js';
|
|
16
|
+
import callRequestResolver from '../request/callRequestResolver.js';
|
|
17
|
+
import checkConnectionRead from '../request/checkConnectionRead.js';
|
|
18
|
+
import checkConnectionWrite from '../request/checkConnectionWrite.js';
|
|
19
|
+
import evaluateOperators from '../request/evaluateOperators.js';
|
|
20
|
+
import getConnection from '../request/getConnection.js';
|
|
21
|
+
import getConnectionConfig from '../request/getConnectionConfig.js';
|
|
22
|
+
import getRequestResolver from '../request/getRequestResolver.js';
|
|
23
|
+
import validateSchemas from '../request/validateSchemas.js';
|
|
24
|
+
async function handleRequest(context, routineContext, { request }) {
|
|
25
|
+
const { logger } = context;
|
|
26
|
+
const { items } = routineContext;
|
|
27
|
+
logger.debug({
|
|
28
|
+
event: 'debug_start_request',
|
|
29
|
+
request
|
|
30
|
+
});
|
|
31
|
+
const requestConfig = request;
|
|
32
|
+
const connectionConfig = await getConnectionConfig(context, {
|
|
33
|
+
requestConfig
|
|
34
|
+
});
|
|
35
|
+
const connection = getConnection(context, {
|
|
36
|
+
connectionConfig
|
|
37
|
+
});
|
|
38
|
+
const requestResolver = getRequestResolver(context, {
|
|
39
|
+
connection,
|
|
40
|
+
requestConfig
|
|
41
|
+
});
|
|
42
|
+
const { connectionProperties, requestProperties } = evaluateOperators(context, {
|
|
43
|
+
connectionConfig,
|
|
44
|
+
items,
|
|
45
|
+
requestConfig
|
|
46
|
+
});
|
|
47
|
+
checkConnectionRead(context, {
|
|
48
|
+
connectionConfig,
|
|
49
|
+
connectionProperties,
|
|
50
|
+
requestConfig,
|
|
51
|
+
requestResolver
|
|
52
|
+
});
|
|
53
|
+
checkConnectionWrite(context, {
|
|
54
|
+
connectionConfig,
|
|
55
|
+
connectionProperties,
|
|
56
|
+
requestConfig,
|
|
57
|
+
requestResolver
|
|
58
|
+
});
|
|
59
|
+
validateSchemas(context, {
|
|
60
|
+
connection,
|
|
61
|
+
connectionProperties,
|
|
62
|
+
requestConfig,
|
|
63
|
+
requestResolver,
|
|
64
|
+
requestProperties
|
|
65
|
+
});
|
|
66
|
+
const result = await callRequestResolver(context, {
|
|
67
|
+
connectionProperties,
|
|
68
|
+
requestConfig,
|
|
69
|
+
requestProperties,
|
|
70
|
+
requestResolver
|
|
71
|
+
});
|
|
72
|
+
addStepResult(context, routineContext, {
|
|
73
|
+
result,
|
|
74
|
+
stepId: request.requestId
|
|
75
|
+
});
|
|
76
|
+
context.logger.debug({
|
|
77
|
+
event: 'debug_end_request',
|
|
78
|
+
id: requestConfig.id,
|
|
79
|
+
result
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
status: 'continue'
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export default handleRequest;
|