@abyss-project/runtime 3.6.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.
Files changed (58) hide show
  1. package/.eslintrc.js +32 -32
  2. package/.prettierrc +5 -5
  3. package/README.md +88 -88
  4. package/dist/engine/engine-source.js +1 -1
  5. package/dist/engine/run-in-isolate.js +37 -4
  6. package/dist/engine/run-in-isolate.js.map +1 -1
  7. package/dist/interpreter/interpreter.js +1 -0
  8. package/dist/interpreter/interpreter.js.map +1 -1
  9. package/dist/interpreter/interpreter.types.d.ts +1 -0
  10. package/dist/runner-protocol/execution-protocol.types.d.ts +3 -0
  11. package/dist/runner-protocol/execution-protocol.types.js +2 -1
  12. package/dist/runner-protocol/execution-protocol.types.js.map +1 -1
  13. package/jest.config.ts +11 -11
  14. package/package.json +10 -15
  15. package/scripts/build-engine.cjs +70 -70
  16. package/src/__tests__/engine-bundle.test.ts +121 -121
  17. package/src/__tests__/surface.test.ts +12 -1
  18. package/src/access/__tests__/host-match.test.ts +24 -24
  19. package/src/access/access.types.ts +25 -25
  20. package/src/access/host-match.ts +13 -13
  21. package/src/cost/__tests__/execution-cost.test.ts +196 -196
  22. package/src/cost/execution-cost.ts +186 -186
  23. package/src/definition/__tests__/validate-definition.test.ts +354 -354
  24. package/src/definition/definition.limits.ts +9 -9
  25. package/src/definition/definition.schema.ts +172 -172
  26. package/src/definition/definition.types.ts +171 -171
  27. package/src/definition/validate-definition.ts +206 -206
  28. package/src/definition/walk-steps.ts +44 -44
  29. package/src/discord/__tests__/discord-event-input.test.ts +89 -89
  30. package/src/discord/discord.types.ts +639 -639
  31. package/src/engine/__tests__/run-in-isolate.test.ts +56 -5
  32. package/src/engine/engine-entry.ts +3 -3
  33. package/src/engine/engine-global.ts +2 -2
  34. package/src/engine/run-in-isolate.ts +64 -6
  35. package/src/errors/runtime-error-code.enum.ts +37 -37
  36. package/src/index.ts +32 -32
  37. package/src/interpreter/__tests__/interpreter.test.ts +854 -854
  38. package/src/interpreter/__tests__/log-respond-resume.test.ts +271 -270
  39. package/src/interpreter/interpreter-error.ts +12 -12
  40. package/src/interpreter/interpreter.ts +483 -482
  41. package/src/interpreter/interpreter.types.ts +204 -202
  42. package/src/interpreter/sequence-path.ts +67 -67
  43. package/src/interpreter/test-host.ts +85 -85
  44. package/src/runner-protocol/evaluation.types.ts +21 -21
  45. package/src/runner-protocol/execution-protocol.types.ts +26 -3
  46. package/src/schedule/schedule.types.ts +100 -100
  47. package/src/server/__tests__/code-runner-session.test.ts +311 -311
  48. package/src/server/code-runner-error.ts +12 -12
  49. package/src/server/code-runner-session.ts +310 -310
  50. package/src/server/index.ts +11 -11
  51. package/src/steps/__tests__/global-references.test.ts +133 -133
  52. package/src/steps/execute-step.ts +186 -186
  53. package/src/steps/global-references.ts +48 -48
  54. package/src/steps/step-access.ts +56 -56
  55. package/src/steps/step-fields.ts +87 -87
  56. package/src/steps/value-source.ts +69 -69
  57. package/tsconfig.check.json +15 -15
  58. 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
+ }