@abyss-project/runtime 1.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/dist/cost/execution-cost.d.ts +45 -0
- package/dist/cost/execution-cost.js +114 -0
- package/dist/cost/execution-cost.js.map +1 -0
- package/dist/definition/definition.limits.d.ts +4 -0
- package/dist/definition/definition.limits.js +8 -0
- package/dist/definition/definition.limits.js.map +1 -0
- package/dist/definition/definition.schema.d.ts +2 -2
- package/dist/definition/definition.schema.js +20 -4
- package/dist/definition/definition.schema.js.map +1 -1
- package/dist/definition/definition.types.d.ts +20 -1
- package/dist/definition/definition.types.js +9 -1
- package/dist/definition/definition.types.js.map +1 -1
- package/dist/engine/engine-entry.d.ts +1 -0
- package/dist/engine/engine-entry.js +6 -0
- package/dist/engine/engine-entry.js.map +1 -0
- package/dist/engine/engine-global.d.ts +1 -0
- package/dist/engine/engine-global.js +5 -0
- package/dist/engine/engine-global.js.map +1 -0
- package/dist/engine/engine-source.d.ts +2 -0
- package/dist/engine/engine-source.js +3 -0
- package/dist/engine/run-in-isolate.d.ts +34 -0
- package/dist/engine/run-in-isolate.js +267 -0
- package/dist/engine/run-in-isolate.js.map +1 -0
- package/dist/errors/runtime-error-code.enum.d.ts +2 -2
- package/dist/errors/runtime-error-code.enum.js +1 -1
- package/dist/errors/runtime-error-code.enum.js.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/dist/interpreter/interpreter.d.ts +27 -1
- package/dist/interpreter/interpreter.js +114 -42
- package/dist/interpreter/interpreter.js.map +1 -1
- package/dist/interpreter/interpreter.types.d.ts +35 -4
- package/dist/interpreter/interpreter.types.js +7 -1
- package/dist/interpreter/interpreter.types.js.map +1 -1
- package/dist/interpreter/test-host.d.ts +4 -2
- package/dist/interpreter/test-host.js +6 -0
- package/dist/interpreter/test-host.js.map +1 -1
- package/dist/runner-protocol/evaluation.types.d.ts +20 -0
- package/dist/runner-protocol/evaluation.types.js +10 -0
- package/dist/runner-protocol/evaluation.types.js.map +1 -0
- package/dist/runner-protocol/execution-protocol.types.d.ts +132 -0
- package/dist/runner-protocol/execution-protocol.types.js +48 -0
- package/dist/runner-protocol/execution-protocol.types.js.map +1 -0
- package/dist/server/code-runner-session.d.ts +28 -0
- package/dist/server/code-runner-session.js +208 -0
- package/dist/server/code-runner-session.js.map +1 -0
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +5 -3
- package/dist/server/index.js.map +1 -1
- package/dist/steps/execute-step.d.ts +12 -2
- package/dist/steps/execute-step.js +37 -0
- package/dist/steps/execute-step.js.map +1 -1
- package/dist/steps/global-references.d.ts +2 -0
- package/dist/steps/global-references.js +28 -0
- package/dist/steps/global-references.js.map +1 -0
- package/dist/steps/step-fields.d.ts +1 -1
- package/dist/steps/step-fields.js +10 -2
- package/dist/steps/step-fields.js.map +1 -1
- package/dist/steps/value-source.d.ts +1 -1
- package/dist/steps/value-source.js +3 -3
- package/dist/steps/value-source.js.map +1 -1
- package/package.json +10 -2
- package/scripts/build-engine.cjs +70 -0
- package/src/__tests__/engine-bundle.test.ts +121 -0
- package/src/cost/__tests__/execution-cost.test.ts +200 -0
- package/src/cost/execution-cost.ts +192 -0
- package/src/definition/__tests__/validate-definition.test.ts +354 -303
- package/src/definition/definition.limits.ts +9 -0
- package/src/definition/definition.schema.ts +172 -139
- package/src/definition/definition.types.ts +171 -143
- package/src/engine/__tests__/run-in-isolate.test.ts +468 -0
- package/src/engine/engine-entry.ts +3 -0
- package/src/engine/engine-global.ts +2 -0
- package/src/engine/run-in-isolate.ts +404 -0
- package/src/errors/runtime-error-code.enum.ts +37 -37
- package/src/index.ts +30 -18
- package/src/interpreter/__tests__/interpreter.test.ts +854 -854
- package/src/interpreter/__tests__/log-respond-resume.test.ts +223 -0
- package/src/interpreter/interpreter.ts +461 -342
- package/src/interpreter/interpreter.types.ts +192 -140
- package/src/interpreter/test-host.ts +85 -74
- package/src/runner-protocol/evaluation.types.ts +21 -0
- package/src/runner-protocol/execution-protocol.types.ts +221 -0
- package/src/server/__tests__/code-runner-session.test.ts +311 -0
- package/src/server/code-runner-error.ts +12 -12
- package/src/server/code-runner-session.ts +310 -0
- package/src/server/index.ts +11 -4
- package/src/steps/__tests__/global-references.test.ts +113 -0
- package/src/steps/execute-step.ts +186 -132
- package/src/steps/global-references.ts +48 -0
- package/src/steps/step-access.ts +56 -56
- package/src/steps/step-fields.ts +87 -79
- package/src/steps/value-source.ts +69 -69
- package/dist/runner-protocol/runner-protocol.types.d.ts +0 -92
- package/dist/runner-protocol/runner-protocol.types.js +0 -26
- package/dist/runner-protocol/runner-protocol.types.js.map +0 -1
- package/dist/server/code-runner-client.d.ts +0 -13
- package/dist/server/code-runner-client.js +0 -155
- package/dist/server/code-runner-client.js.map +0 -1
- package/src/runner-protocol/runner-protocol.types.ts +0 -117
- package/src/server/__tests__/code-runner-client.test.ts +0 -262
- package/src/server/code-runner-client.ts +0 -201
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Bounds of the definition format, without Joi: the interpreter and the isolate engine bundle
|
|
2
|
+
// read them, and neither may pull Joi in (see `engine/run-in-isolate.ts`).
|
|
3
|
+
|
|
4
|
+
export const MAX_HTTP_TIMEOUT_MS = 30_000;
|
|
5
|
+
export const MAX_WAIT_DURATION_MS = 30 * 24 * 60 * 60 * 1000;
|
|
6
|
+
|
|
7
|
+
/** HTTP status range a RESPOND step may send. */
|
|
8
|
+
export const MIN_RESPONSE_STATUS = 200;
|
|
9
|
+
export const MAX_RESPONSE_STATUS = 599;
|
|
@@ -1,139 +1,172 @@
|
|
|
1
|
-
import Joi from 'joi';
|
|
2
|
-
import { AccessKind } from '../access/access.types';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*/
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}),
|
|
135
|
-
[
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
1
|
+
import Joi from 'joi';
|
|
2
|
+
import { AccessKind } from '../access/access.types';
|
|
3
|
+
import {
|
|
4
|
+
MAX_HTTP_TIMEOUT_MS,
|
|
5
|
+
MAX_RESPONSE_STATUS,
|
|
6
|
+
MAX_WAIT_DURATION_MS,
|
|
7
|
+
MIN_RESPONSE_STATUS,
|
|
8
|
+
} from './definition.limits';
|
|
9
|
+
import {
|
|
10
|
+
CURRENT_FORMAT_VERSION,
|
|
11
|
+
HttpMethod,
|
|
12
|
+
LogLevel,
|
|
13
|
+
StepType,
|
|
14
|
+
StopStatus,
|
|
15
|
+
} from './definition.types';
|
|
16
|
+
|
|
17
|
+
export { MAX_HTTP_TIMEOUT_MS, MAX_WAIT_DURATION_MS };
|
|
18
|
+
|
|
19
|
+
/** Names that would hit `Object.prototype` when used as a key of `outputs` or `vars`. */
|
|
20
|
+
const RESERVED_NAMES = ['__proto__', 'constructor', 'prototype'];
|
|
21
|
+
|
|
22
|
+
const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
23
|
+
const HOST_PATTERN = /^(\*\.)?[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i;
|
|
24
|
+
|
|
25
|
+
let valueSourceCount = 0;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Literal JSON, `{ $expression }` (that key alone), arrays and objects of value sources. Joi
|
|
29
|
+
* links resolve by id and ids must be unique inside one schema tree, hence a fresh id per use.
|
|
30
|
+
*/
|
|
31
|
+
const valueSource = (): Joi.AlternativesSchema => {
|
|
32
|
+
const id = `valueSource${valueSourceCount++}`;
|
|
33
|
+
return Joi.alternatives()
|
|
34
|
+
.try(
|
|
35
|
+
Joi.string().allow(''),
|
|
36
|
+
Joi.number(),
|
|
37
|
+
Joi.boolean(),
|
|
38
|
+
Joi.valid(null),
|
|
39
|
+
Joi.array().items(Joi.link(`#${id}`)),
|
|
40
|
+
Joi.object({ $expression: Joi.string().required() }),
|
|
41
|
+
Joi.object().pattern(Joi.string().invalid('$expression'), Joi.link(`#${id}`)),
|
|
42
|
+
)
|
|
43
|
+
.id(id);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const valueMap = () => Joi.object().pattern(Joi.string(), valueSource());
|
|
47
|
+
|
|
48
|
+
/** A number is bounded here; anything else (template, `$expression`) is checked at run time. */
|
|
49
|
+
const durationSource = (): Joi.AlternativesSchema =>
|
|
50
|
+
Joi.alternatives().try(
|
|
51
|
+
Joi.number().integer().min(0).max(MAX_WAIT_DURATION_MS),
|
|
52
|
+
Joi.string().allow(''),
|
|
53
|
+
Joi.object({ $expression: Joi.string().required() }),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
/** A literal must be a date; a template or `$expression` is checked at run time. */
|
|
57
|
+
const untilSource = (): Joi.AlternativesSchema =>
|
|
58
|
+
Joi.alternatives().try(
|
|
59
|
+
Joi.string().pattern(/\{\{[\s\S]*?\}\}/),
|
|
60
|
+
Joi.string().isoDate(),
|
|
61
|
+
Joi.object({ $expression: Joi.string().required() }),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
/** A literal must be an HTTP status; a template or `$expression` is checked at run time. */
|
|
65
|
+
const statusSource = (): Joi.AlternativesSchema =>
|
|
66
|
+
Joi.alternatives().try(
|
|
67
|
+
Joi.number().integer().min(MIN_RESPONSE_STATUS).max(MAX_RESPONSE_STATUS),
|
|
68
|
+
Joi.string().pattern(/\{\{[\s\S]*?\}\}/),
|
|
69
|
+
Joi.object({ $expression: Joi.string().required() }),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const stepBase = {
|
|
73
|
+
id: Joi.string()
|
|
74
|
+
.min(1)
|
|
75
|
+
.invalid(...RESERVED_NAMES)
|
|
76
|
+
.required(),
|
|
77
|
+
name: Joi.string().allow(''),
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// Children (`then`, `else`, `steps`, `default`) are only checked to be arrays here: the
|
|
81
|
+
// validator walks them to give each nested step its own path.
|
|
82
|
+
export const STEP_SCHEMAS: Record<StepType, Joi.ObjectSchema> = {
|
|
83
|
+
[StepType.CONDITION]: Joi.object({
|
|
84
|
+
...stepBase,
|
|
85
|
+
type: Joi.valid(StepType.CONDITION).required(),
|
|
86
|
+
if: valueSource().required(),
|
|
87
|
+
then: Joi.array().required(),
|
|
88
|
+
else: Joi.array(),
|
|
89
|
+
}),
|
|
90
|
+
[StepType.SWITCH]: Joi.object({
|
|
91
|
+
...stepBase,
|
|
92
|
+
type: Joi.valid(StepType.SWITCH).required(),
|
|
93
|
+
value: valueSource().required(),
|
|
94
|
+
cases: Joi.array()
|
|
95
|
+
.min(1)
|
|
96
|
+
.items(Joi.object({ match: valueSource().required(), steps: Joi.array().required() }))
|
|
97
|
+
.required(),
|
|
98
|
+
default: Joi.array(),
|
|
99
|
+
}),
|
|
100
|
+
[StepType.WAIT]: Joi.object({
|
|
101
|
+
...stepBase,
|
|
102
|
+
type: Joi.valid(StepType.WAIT).required(),
|
|
103
|
+
durationMs: durationSource(),
|
|
104
|
+
until: untilSource(),
|
|
105
|
+
}).xor('durationMs', 'until'),
|
|
106
|
+
[StepType.SET]: Joi.object({
|
|
107
|
+
...stepBase,
|
|
108
|
+
type: Joi.valid(StepType.SET).required(),
|
|
109
|
+
variable: Joi.string()
|
|
110
|
+
.pattern(IDENTIFIER)
|
|
111
|
+
.invalid(...RESERVED_NAMES)
|
|
112
|
+
.required(),
|
|
113
|
+
value: valueSource().required(),
|
|
114
|
+
}),
|
|
115
|
+
[StepType.CODE]: Joi.object({
|
|
116
|
+
...stepBase,
|
|
117
|
+
type: Joi.valid(StepType.CODE).required(),
|
|
118
|
+
source: Joi.string().min(1).required(),
|
|
119
|
+
}),
|
|
120
|
+
[StepType.HTTP]: Joi.object({
|
|
121
|
+
...stepBase,
|
|
122
|
+
type: Joi.valid(StepType.HTTP).required(),
|
|
123
|
+
method: Joi.valid(...Object.values(HttpMethod)).required(),
|
|
124
|
+
url: valueSource().required(),
|
|
125
|
+
headers: valueMap(),
|
|
126
|
+
body: valueSource(),
|
|
127
|
+
timeoutMs: Joi.number().integer().min(1).max(MAX_HTTP_TIMEOUT_MS),
|
|
128
|
+
}),
|
|
129
|
+
[StepType.HOST]: Joi.object({
|
|
130
|
+
...stepBase,
|
|
131
|
+
type: Joi.valid(StepType.HOST).required(),
|
|
132
|
+
action: Joi.string().min(1).required(),
|
|
133
|
+
input: valueMap().required(),
|
|
134
|
+
}),
|
|
135
|
+
[StepType.LOG]: Joi.object({
|
|
136
|
+
...stepBase,
|
|
137
|
+
type: Joi.valid(StepType.LOG).required(),
|
|
138
|
+
level: Joi.valid(...Object.values(LogLevel)).required(),
|
|
139
|
+
message: valueSource().required(),
|
|
140
|
+
data: valueSource(),
|
|
141
|
+
}),
|
|
142
|
+
[StepType.RESPOND]: Joi.object({
|
|
143
|
+
...stepBase,
|
|
144
|
+
type: Joi.valid(StepType.RESPOND).required(),
|
|
145
|
+
status: statusSource().required(),
|
|
146
|
+
headers: valueMap(),
|
|
147
|
+
body: valueSource(),
|
|
148
|
+
}),
|
|
149
|
+
[StepType.STOP]: Joi.object({
|
|
150
|
+
...stepBase,
|
|
151
|
+
type: Joi.valid(StepType.STOP).required(),
|
|
152
|
+
status: Joi.valid(...Object.values(StopStatus)).required(),
|
|
153
|
+
output: valueSource(),
|
|
154
|
+
}),
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export const DEFINITION_SCHEMA = Joi.object({
|
|
158
|
+
formatVersion: Joi.valid(CURRENT_FORMAT_VERSION).required(),
|
|
159
|
+
accesses: Joi.array().required(),
|
|
160
|
+
steps: Joi.array().required(),
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
export const ACCESS_SCHEMAS: Record<AccessKind, Joi.ObjectSchema> = {
|
|
164
|
+
[AccessKind.HTTP]: Joi.object({
|
|
165
|
+
kind: Joi.valid(AccessKind.HTTP).required(),
|
|
166
|
+
hosts: Joi.array().items(Joi.string().pattern(HOST_PATTERN)).min(1).required(),
|
|
167
|
+
}),
|
|
168
|
+
[AccessKind.HOST_ACTION]: Joi.object({
|
|
169
|
+
kind: Joi.valid(AccessKind.HOST_ACTION).required(),
|
|
170
|
+
action: Joi.string().min(1).required(),
|
|
171
|
+
}),
|
|
172
|
+
};
|
|
@@ -1,143 +1,171 @@
|
|
|
1
|
-
import type { ObjectSchema } from 'joi';
|
|
2
|
-
import type { AccessDeclaration } from '../access/access.types';
|
|
3
|
-
|
|
4
|
-
export const CURRENT_FORMAT_VERSION = 1;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A full JavaScript expression, evaluated by the code runner. Any other string may embed
|
|
8
|
-
* `{{ … }}` templates; an object whose only key is `$expression` is an expression.
|
|
9
|
-
*/
|
|
10
|
-
export interface ExpressionValue {
|
|
11
|
-
$expression: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type ValueSource =
|
|
15
|
-
| string
|
|
16
|
-
| number
|
|
17
|
-
| boolean
|
|
18
|
-
| null
|
|
19
|
-
| ExpressionValue
|
|
20
|
-
| ValueSource[]
|
|
21
|
-
| { [key: string]: ValueSource };
|
|
22
|
-
|
|
23
|
-
export enum StepType {
|
|
24
|
-
CONDITION = 'CONDITION',
|
|
25
|
-
SWITCH = 'SWITCH',
|
|
26
|
-
WAIT = 'WAIT',
|
|
27
|
-
SET = 'SET',
|
|
28
|
-
CODE = 'CODE',
|
|
29
|
-
HTTP = 'HTTP',
|
|
30
|
-
HOST = 'HOST',
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
export
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
1
|
+
import type { ObjectSchema } from 'joi';
|
|
2
|
+
import type { AccessDeclaration } from '../access/access.types';
|
|
3
|
+
|
|
4
|
+
export const CURRENT_FORMAT_VERSION = 1;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A full JavaScript expression, evaluated by the code runner. Any other string may embed
|
|
8
|
+
* `{{ … }}` templates; an object whose only key is `$expression` is an expression.
|
|
9
|
+
*/
|
|
10
|
+
export interface ExpressionValue {
|
|
11
|
+
$expression: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ValueSource =
|
|
15
|
+
| string
|
|
16
|
+
| number
|
|
17
|
+
| boolean
|
|
18
|
+
| null
|
|
19
|
+
| ExpressionValue
|
|
20
|
+
| ValueSource[]
|
|
21
|
+
| { [key: string]: ValueSource };
|
|
22
|
+
|
|
23
|
+
export enum StepType {
|
|
24
|
+
CONDITION = 'CONDITION',
|
|
25
|
+
SWITCH = 'SWITCH',
|
|
26
|
+
WAIT = 'WAIT',
|
|
27
|
+
SET = 'SET',
|
|
28
|
+
CODE = 'CODE',
|
|
29
|
+
HTTP = 'HTTP',
|
|
30
|
+
HOST = 'HOST',
|
|
31
|
+
/** Writes a log line kept with the run, through the host capability `log.write`. */
|
|
32
|
+
LOG = 'LOG',
|
|
33
|
+
/** Sends the HTTP response to the caller now, through `http.respond`; the run goes on. */
|
|
34
|
+
RESPOND = 'RESPOND',
|
|
35
|
+
STOP = 'STOP',
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export enum LogLevel {
|
|
39
|
+
INFO = 'info',
|
|
40
|
+
WARN = 'warn',
|
|
41
|
+
ERROR = 'error',
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export enum HttpMethod {
|
|
45
|
+
GET = 'GET',
|
|
46
|
+
POST = 'POST',
|
|
47
|
+
PUT = 'PUT',
|
|
48
|
+
PATCH = 'PATCH',
|
|
49
|
+
DELETE = 'DELETE',
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export enum StopStatus {
|
|
53
|
+
SUCCEEDED = 'SUCCEEDED',
|
|
54
|
+
FAILED = 'FAILED',
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface StepBase {
|
|
58
|
+
/** Stable, unique in the definition; outputs are read as `steps.<id>.output`. */
|
|
59
|
+
id: string;
|
|
60
|
+
name?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface ConditionStep extends StepBase {
|
|
64
|
+
type: StepType.CONDITION;
|
|
65
|
+
if: ValueSource;
|
|
66
|
+
then: Step[];
|
|
67
|
+
else?: Step[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface SwitchCase {
|
|
71
|
+
match: ValueSource;
|
|
72
|
+
steps: Step[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface SwitchStep extends StepBase {
|
|
76
|
+
type: StepType.SWITCH;
|
|
77
|
+
value: ValueSource;
|
|
78
|
+
cases: SwitchCase[];
|
|
79
|
+
default?: Step[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Exactly one of `durationMs` and `until` (an ISO 8601 date); the host schedules the wake-up. */
|
|
83
|
+
export interface WaitStep extends StepBase {
|
|
84
|
+
type: StepType.WAIT;
|
|
85
|
+
durationMs?: ValueSource;
|
|
86
|
+
until?: ValueSource;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface SetStep extends StepBase {
|
|
90
|
+
type: StepType.SET;
|
|
91
|
+
/** Read back as `vars.<variable>`. */
|
|
92
|
+
variable: string;
|
|
93
|
+
value: ValueSource;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** JavaScript statements; the value of their `return` becomes the step's output. */
|
|
97
|
+
export interface CodeStep extends StepBase {
|
|
98
|
+
type: StepType.CODE;
|
|
99
|
+
source: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface HttpStep extends StepBase {
|
|
103
|
+
type: StepType.HTTP;
|
|
104
|
+
method: HttpMethod;
|
|
105
|
+
url: ValueSource;
|
|
106
|
+
headers?: Record<string, ValueSource>;
|
|
107
|
+
body?: ValueSource;
|
|
108
|
+
timeoutMs?: number;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface HostStep extends StepBase {
|
|
112
|
+
type: StepType.HOST;
|
|
113
|
+
action: string;
|
|
114
|
+
input: Record<string, ValueSource>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface LogStep extends StepBase {
|
|
118
|
+
type: StepType.LOG;
|
|
119
|
+
level: LogLevel;
|
|
120
|
+
/** Resolved to a string; a non-string value is written as its JSON. */
|
|
121
|
+
message: ValueSource;
|
|
122
|
+
data?: ValueSource;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface RespondStep extends StepBase {
|
|
126
|
+
type: StepType.RESPOND;
|
|
127
|
+
/** Resolved to an integer HTTP status, 100 to 599. */
|
|
128
|
+
status: ValueSource;
|
|
129
|
+
headers?: Record<string, ValueSource>;
|
|
130
|
+
body?: ValueSource;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface StopStep extends StepBase {
|
|
134
|
+
type: StepType.STOP;
|
|
135
|
+
status: StopStatus;
|
|
136
|
+
output?: ValueSource;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export type Step =
|
|
140
|
+
| ConditionStep
|
|
141
|
+
| SwitchStep
|
|
142
|
+
| WaitStep
|
|
143
|
+
| SetStep
|
|
144
|
+
| CodeStep
|
|
145
|
+
| HttpStep
|
|
146
|
+
| HostStep
|
|
147
|
+
| LogStep
|
|
148
|
+
| RespondStep
|
|
149
|
+
| StopStep;
|
|
150
|
+
|
|
151
|
+
export interface RuntimeDefinition {
|
|
152
|
+
formatVersion: typeof CURRENT_FORMAT_VERSION;
|
|
153
|
+
accesses: AccessDeclaration[];
|
|
154
|
+
steps: Step[];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** One action a product offers to its definitions (e-mail for Flow, Discord for Reflex…). */
|
|
158
|
+
export interface HostActionDefinition {
|
|
159
|
+
name: string;
|
|
160
|
+
/** Validates the input once every expression in it is resolved. */
|
|
161
|
+
inputSchema: ObjectSchema;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Supplied by each product; the core knows no Abyss service. */
|
|
165
|
+
export type HostActionCatalog = ReadonlyMap<string, HostActionDefinition>;
|
|
166
|
+
|
|
167
|
+
export interface DefinitionError {
|
|
168
|
+
/** JSON path of the offending node, e.g. `steps[2].then[0].action`. */
|
|
169
|
+
path: string;
|
|
170
|
+
message: string;
|
|
171
|
+
}
|