@abyss-project/runtime 3.7.0 → 3.8.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/.eslintrc.js +32 -32
- package/.prettierrc +5 -5
- package/README.md +88 -88
- package/dist/engine/engine-source.js +1 -1
- package/dist/engine/run-in-isolate.js +32 -2
- package/dist/engine/run-in-isolate.js.map +1 -1
- package/dist/runner-protocol/execution-protocol.types.d.ts +2 -0
- package/dist/runner-protocol/execution-protocol.types.js +2 -1
- package/dist/runner-protocol/execution-protocol.types.js.map +1 -1
- package/jest.config.ts +11 -11
- package/package.json +10 -15
- package/scripts/build-engine.cjs +70 -70
- package/src/__tests__/engine-bundle.test.ts +121 -121
- package/src/__tests__/surface.test.ts +12 -1
- package/src/access/__tests__/host-match.test.ts +24 -24
- package/src/access/access.types.ts +25 -25
- package/src/access/host-match.ts +13 -13
- package/src/cost/__tests__/execution-cost.test.ts +196 -196
- package/src/cost/execution-cost.ts +186 -186
- package/src/definition/__tests__/validate-definition.test.ts +354 -354
- package/src/definition/definition.limits.ts +9 -9
- package/src/definition/definition.schema.ts +172 -172
- package/src/definition/definition.types.ts +171 -171
- package/src/definition/validate-definition.ts +206 -206
- package/src/definition/walk-steps.ts +44 -44
- package/src/discord/__tests__/discord-event-input.test.ts +89 -89
- package/src/discord/discord.types.ts +639 -639
- package/src/engine/__tests__/run-in-isolate.test.ts +56 -5
- package/src/engine/engine-entry.ts +3 -3
- package/src/engine/engine-global.ts +2 -2
- package/src/engine/run-in-isolate.ts +47 -4
- package/src/errors/runtime-error-code.enum.ts +37 -37
- package/src/index.ts +32 -32
- package/src/interpreter/__tests__/interpreter.test.ts +854 -854
- package/src/interpreter/__tests__/log-respond-resume.test.ts +271 -271
- package/src/interpreter/interpreter-error.ts +12 -12
- package/src/interpreter/interpreter.ts +483 -483
- package/src/interpreter/interpreter.types.ts +204 -204
- package/src/interpreter/sequence-path.ts +67 -67
- package/src/interpreter/test-host.ts +85 -85
- package/src/runner-protocol/evaluation.types.ts +21 -21
- package/src/runner-protocol/execution-protocol.types.ts +20 -3
- package/src/schedule/schedule.types.ts +100 -100
- package/src/server/__tests__/code-runner-session.test.ts +311 -311
- package/src/server/code-runner-error.ts +12 -12
- package/src/server/code-runner-session.ts +310 -310
- package/src/server/index.ts +11 -11
- package/src/steps/__tests__/global-references.test.ts +133 -133
- package/src/steps/execute-step.ts +186 -186
- package/src/steps/global-references.ts +48 -48
- package/src/steps/step-access.ts +56 -56
- package/src/steps/step-fields.ts +87 -87
- package/src/steps/value-source.ts +69 -69
- package/tsconfig.check.json +15 -15
- package/tsconfig.json +35 -35
|
@@ -1,171 +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
|
-
/** 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
|
-
}
|
|
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
|
+
}
|