@abyss-project/runtime 3.4.0 → 3.6.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/dist/discord/discord.types.d.ts +167 -4
  4. package/dist/discord/discord.types.js +48 -1
  5. package/dist/discord/discord.types.js.map +1 -1
  6. package/dist/engine/engine-source.js +1 -1
  7. package/dist/interpreter/interpreter.js +18 -4
  8. package/dist/interpreter/interpreter.js.map +1 -1
  9. package/dist/interpreter/interpreter.types.d.ts +2 -0
  10. package/dist/interpreter/interpreter.types.js.map +1 -1
  11. package/dist/runner-protocol/execution-protocol.types.d.ts +11 -0
  12. package/dist/runner-protocol/execution-protocol.types.js +2 -1
  13. package/dist/runner-protocol/execution-protocol.types.js.map +1 -1
  14. package/jest.config.ts +11 -11
  15. package/package.json +15 -10
  16. package/scripts/build-engine.cjs +70 -70
  17. package/src/__tests__/engine-bundle.test.ts +121 -121
  18. package/src/__tests__/surface.test.ts +5 -1
  19. package/src/access/__tests__/host-match.test.ts +24 -24
  20. package/src/access/access.types.ts +25 -25
  21. package/src/access/host-match.ts +13 -13
  22. package/src/cost/__tests__/execution-cost.test.ts +196 -196
  23. package/src/cost/execution-cost.ts +186 -186
  24. package/src/definition/__tests__/validate-definition.test.ts +354 -354
  25. package/src/definition/definition.limits.ts +9 -9
  26. package/src/definition/definition.schema.ts +172 -172
  27. package/src/definition/definition.types.ts +171 -171
  28. package/src/definition/validate-definition.ts +206 -206
  29. package/src/definition/walk-steps.ts +44 -44
  30. package/src/discord/discord.types.ts +264 -5
  31. package/src/engine/__tests__/run-in-isolate.test.ts +468 -468
  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 +404 -404
  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 +270 -223
  39. package/src/interpreter/interpreter-error.ts +12 -12
  40. package/src/interpreter/interpreter.ts +482 -461
  41. package/src/interpreter/interpreter.types.ts +202 -192
  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 +254 -231
  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,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
+ };