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