@abyss-project/runtime 0.0.0-stage → 1.0.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 -0
- package/.prettierrc +5 -0
- package/README.md +25 -3
- package/dist/access/access.types.d.ts +14 -0
- package/dist/access/access.types.js +9 -0
- package/dist/access/access.types.js.map +1 -0
- package/dist/access/host-match.d.ts +1 -0
- package/dist/access/host-match.js +14 -0
- package/dist/access/host-match.js.map +1 -0
- package/dist/definition/definition.schema.d.ts +8 -0
- package/dist/definition/definition.schema.js +107 -0
- package/dist/definition/definition.schema.js.map +1 -0
- package/dist/definition/definition.types.d.ts +98 -0
- package/dist/definition/definition.types.js +29 -0
- package/dist/definition/definition.types.js.map +1 -0
- package/dist/definition/validate-definition.d.ts +9 -0
- package/dist/definition/validate-definition.js +163 -0
- package/dist/definition/validate-definition.js.map +1 -0
- package/dist/definition/walk-steps.d.ts +5 -0
- package/dist/definition/walk-steps.js +31 -0
- package/dist/definition/walk-steps.js.map +1 -0
- package/dist/errors/runtime-error-code.enum.d.ts +18 -0
- package/dist/errors/runtime-error-code.enum.js +19 -0
- package/dist/errors/runtime-error-code.enum.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/interpreter/interpreter-error.d.ts +5 -0
- package/dist/interpreter/interpreter-error.js +12 -0
- package/dist/interpreter/interpreter-error.js.map +1 -0
- package/dist/interpreter/interpreter.d.ts +4 -0
- package/dist/interpreter/interpreter.js +241 -0
- package/dist/interpreter/interpreter.js.map +1 -0
- package/dist/interpreter/interpreter.types.d.ts +121 -0
- package/dist/interpreter/interpreter.types.js +25 -0
- package/dist/interpreter/interpreter.types.js.map +1 -0
- package/dist/interpreter/sequence-path.d.ts +6 -0
- package/dist/interpreter/sequence-path.js +53 -0
- package/dist/interpreter/sequence-path.js.map +1 -0
- package/dist/interpreter/test-host.d.ts +16 -0
- package/dist/interpreter/test-host.js +37 -0
- package/dist/interpreter/test-host.js.map +1 -0
- package/dist/runner-protocol/runner-protocol.types.d.ts +92 -0
- package/dist/runner-protocol/runner-protocol.types.js +26 -0
- package/dist/runner-protocol/runner-protocol.types.js.map +1 -0
- package/dist/server/code-runner-client.d.ts +13 -0
- package/dist/server/code-runner-client.js +155 -0
- package/dist/server/code-runner-client.js.map +1 -0
- package/dist/server/code-runner-error.d.ts +5 -0
- package/dist/server/code-runner-error.js +12 -0
- package/dist/server/code-runner-error.js.map +1 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +8 -0
- package/dist/server/index.js.map +1 -0
- package/dist/steps/execute-step.d.ts +40 -0
- package/dist/steps/execute-step.js +99 -0
- package/dist/steps/execute-step.js.map +1 -0
- package/dist/steps/step-access.d.ts +8 -0
- package/dist/steps/step-access.js +39 -0
- package/dist/steps/step-access.js.map +1 -0
- package/dist/steps/step-fields.d.ts +5 -0
- package/dist/steps/step-fields.js +60 -0
- package/dist/steps/step-fields.js.map +1 -0
- package/dist/steps/value-source.d.ts +6 -0
- package/dist/steps/value-source.js +58 -0
- package/dist/steps/value-source.js.map +1 -0
- package/jest.config.ts +11 -0
- package/package.json +60 -3
- package/src/__tests__/surface.test.ts +53 -0
- package/src/access/__tests__/host-match.test.ts +24 -0
- package/src/access/access.types.ts +25 -0
- package/src/access/host-match.ts +13 -0
- package/src/definition/__tests__/validate-definition.test.ts +303 -0
- package/src/definition/definition.schema.ts +139 -0
- package/src/definition/definition.types.ts +143 -0
- package/src/definition/validate-definition.ts +206 -0
- package/src/definition/walk-steps.ts +44 -0
- package/src/errors/runtime-error-code.enum.ts +37 -0
- package/src/index.ts +18 -0
- package/src/interpreter/__tests__/interpreter.test.ts +854 -0
- package/src/interpreter/interpreter-error.ts +12 -0
- package/src/interpreter/interpreter.ts +342 -0
- package/src/interpreter/interpreter.types.ts +140 -0
- package/src/interpreter/sequence-path.ts +67 -0
- package/src/interpreter/test-host.ts +74 -0
- package/src/runner-protocol/runner-protocol.types.ts +117 -0
- package/src/server/__tests__/code-runner-client.test.ts +262 -0
- package/src/server/code-runner-client.ts +201 -0
- package/src/server/code-runner-error.ts +12 -0
- package/src/server/index.ts +4 -0
- package/src/steps/execute-step.ts +132 -0
- package/src/steps/step-access.ts +56 -0
- package/src/steps/step-fields.ts +79 -0
- package/src/steps/value-source.ts +69 -0
- package/tsconfig.check.json +15 -0
- package/tsconfig.json +35 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RuntimeErrorCode = void 0;
|
|
4
|
+
var RuntimeErrorCode;
|
|
5
|
+
(function (RuntimeErrorCode) {
|
|
6
|
+
RuntimeErrorCode["EXPRESSION_ERROR"] = "EXPRESSION_ERROR";
|
|
7
|
+
RuntimeErrorCode["CODE_ERROR"] = "CODE_ERROR";
|
|
8
|
+
RuntimeErrorCode["TIMEOUT"] = "TIMEOUT";
|
|
9
|
+
RuntimeErrorCode["MEMORY_LIMIT"] = "MEMORY_LIMIT";
|
|
10
|
+
RuntimeErrorCode["HOST_FUNCTION_ERROR"] = "HOST_FUNCTION_ERROR";
|
|
11
|
+
RuntimeErrorCode["ACCESS_DENIED"] = "ACCESS_DENIED";
|
|
12
|
+
RuntimeErrorCode["BUDGET_EXCEEDED"] = "BUDGET_EXCEEDED";
|
|
13
|
+
RuntimeErrorCode["HOST_ERROR"] = "HOST_ERROR";
|
|
14
|
+
RuntimeErrorCode["HTTP_ERROR"] = "HTTP_ERROR";
|
|
15
|
+
RuntimeErrorCode["RUNNER_UNAVAILABLE"] = "RUNNER_UNAVAILABLE";
|
|
16
|
+
RuntimeErrorCode["RUNNER_SATURATED"] = "RUNNER_SATURATED";
|
|
17
|
+
RuntimeErrorCode["INVALID_REQUEST"] = "INVALID_REQUEST";
|
|
18
|
+
})(RuntimeErrorCode || (exports.RuntimeErrorCode = RuntimeErrorCode = {}));
|
|
19
|
+
//# sourceMappingURL=runtime-error-code.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-error-code.enum.js","sourceRoot":"","sources":["../../src/errors/runtime-error-code.enum.ts"],"names":[],"mappings":";;;AAKA,IAAY,gBAyBX;AAzBD,WAAY,gBAAgB;IAE1B,yDAAqC,CAAA;IAErC,6CAAyB,CAAA;IAEzB,uCAAmB,CAAA;IAEnB,iDAA6B,CAAA;IAE7B,+DAA2C,CAAA;IAE3C,mDAA+B,CAAA;IAE/B,uDAAmC,CAAA;IAEnC,6CAAyB,CAAA;IAEzB,6CAAyB,CAAA;IAEzB,6DAAyC,CAAA;IAEzC,yDAAqC,CAAA;IAErC,uDAAmC,CAAA;AACrC,CAAC,EAzBW,gBAAgB,gCAAhB,gBAAgB,QAyB3B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './errors/runtime-error-code.enum';
|
|
2
|
+
export * from './access/access.types';
|
|
3
|
+
export { hostMatches } from './access/host-match';
|
|
4
|
+
export * from './definition/definition.types';
|
|
5
|
+
export { validateDefinition } from './definition/validate-definition';
|
|
6
|
+
export type { ValidationResult } from './definition/validate-definition';
|
|
7
|
+
export { MAX_WAIT_DURATION_MS } from './definition/definition.schema';
|
|
8
|
+
export { walkSteps } from './definition/walk-steps';
|
|
9
|
+
export type { StepVisitor } from './definition/walk-steps';
|
|
10
|
+
export * from './interpreter/interpreter.types';
|
|
11
|
+
export { start, step } from './interpreter/interpreter';
|
|
12
|
+
export { InterpreterError } from './interpreter/interpreter-error';
|
|
13
|
+
export { runToCompletion } from './interpreter/test-host';
|
|
14
|
+
export type { TestHostHandlers, TestRunResult } from './interpreter/test-host';
|
|
15
|
+
export * from './runner-protocol/runner-protocol.types';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.runToCompletion = exports.InterpreterError = exports.step = exports.start = exports.walkSteps = exports.MAX_WAIT_DURATION_MS = exports.validateDefinition = exports.hostMatches = void 0;
|
|
18
|
+
__exportStar(require("./errors/runtime-error-code.enum"), exports);
|
|
19
|
+
__exportStar(require("./access/access.types"), exports);
|
|
20
|
+
var host_match_1 = require("./access/host-match");
|
|
21
|
+
Object.defineProperty(exports, "hostMatches", { enumerable: true, get: function () { return host_match_1.hostMatches; } });
|
|
22
|
+
__exportStar(require("./definition/definition.types"), exports);
|
|
23
|
+
var validate_definition_1 = require("./definition/validate-definition");
|
|
24
|
+
Object.defineProperty(exports, "validateDefinition", { enumerable: true, get: function () { return validate_definition_1.validateDefinition; } });
|
|
25
|
+
var definition_schema_1 = require("./definition/definition.schema");
|
|
26
|
+
Object.defineProperty(exports, "MAX_WAIT_DURATION_MS", { enumerable: true, get: function () { return definition_schema_1.MAX_WAIT_DURATION_MS; } });
|
|
27
|
+
var walk_steps_1 = require("./definition/walk-steps");
|
|
28
|
+
Object.defineProperty(exports, "walkSteps", { enumerable: true, get: function () { return walk_steps_1.walkSteps; } });
|
|
29
|
+
__exportStar(require("./interpreter/interpreter.types"), exports);
|
|
30
|
+
var interpreter_1 = require("./interpreter/interpreter");
|
|
31
|
+
Object.defineProperty(exports, "start", { enumerable: true, get: function () { return interpreter_1.start; } });
|
|
32
|
+
Object.defineProperty(exports, "step", { enumerable: true, get: function () { return interpreter_1.step; } });
|
|
33
|
+
var interpreter_error_1 = require("./interpreter/interpreter-error");
|
|
34
|
+
Object.defineProperty(exports, "InterpreterError", { enumerable: true, get: function () { return interpreter_error_1.InterpreterError; } });
|
|
35
|
+
var test_host_1 = require("./interpreter/test-host");
|
|
36
|
+
Object.defineProperty(exports, "runToCompletion", { enumerable: true, get: function () { return test_host_1.runToCompletion; } });
|
|
37
|
+
__exportStar(require("./runner-protocol/runner-protocol.types"), exports);
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAGA,mEAAiD;AACjD,wDAAsC;AACtC,kDAAkD;AAAzC,yGAAA,WAAW,OAAA;AACpB,gEAA8C;AAC9C,wEAAsE;AAA7D,yHAAA,kBAAkB,OAAA;AAE3B,oEAAsE;AAA7D,yHAAA,oBAAoB,OAAA;AAC7B,sDAAoD;AAA3C,uGAAA,SAAS,OAAA;AAElB,kEAAgD;AAChD,yDAAwD;AAA/C,oGAAA,KAAK,OAAA;AAAE,mGAAA,IAAI,OAAA;AACpB,qEAAmE;AAA1D,qHAAA,gBAAgB,OAAA;AACzB,qDAA0D;AAAjD,4GAAA,eAAe,OAAA;AAExB,0EAAwD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InterpreterError = void 0;
|
|
4
|
+
class InterpreterError extends Error {
|
|
5
|
+
constructor(code, message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'InterpreterError';
|
|
8
|
+
this.code = code;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.InterpreterError = InterpreterError;
|
|
12
|
+
//# sourceMappingURL=interpreter-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interpreter-error.js","sourceRoot":"","sources":["../../src/interpreter/interpreter-error.ts"],"names":[],"mappings":";;;AAGA,MAAa,gBAAiB,SAAQ,KAAK;IAGzC,YAAY,IAAsB,EAAE,OAAe;QACjD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AARD,4CAQC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RuntimeDefinition } from '../definition/definition.types';
|
|
2
|
+
import type { RunEvent, RunOptions, RunState, StepResult } from './interpreter.types';
|
|
3
|
+
export declare const start: (definition: RuntimeDefinition, input: unknown, options: RunOptions) => StepResult;
|
|
4
|
+
export declare const step: (definition: RuntimeDefinition, state: RunState, event: RunEvent, options: RunOptions) => StepResult;
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.step = exports.start = void 0;
|
|
4
|
+
const runtime_error_code_enum_1 = require("../errors/runtime-error-code.enum");
|
|
5
|
+
const definition_schema_1 = require("../definition/definition.schema");
|
|
6
|
+
const definition_types_1 = require("../definition/definition.types");
|
|
7
|
+
const execute_step_1 = require("../steps/execute-step");
|
|
8
|
+
const step_fields_1 = require("../steps/step-fields");
|
|
9
|
+
const step_access_1 = require("../steps/step-access");
|
|
10
|
+
const interpreter_error_1 = require("./interpreter-error");
|
|
11
|
+
const interpreter_types_1 = require("./interpreter.types");
|
|
12
|
+
const sequence_path_1 = require("./sequence-path");
|
|
13
|
+
const NO_RESULTS = new Map();
|
|
14
|
+
const invalidRequest = (message) => new interpreter_error_1.InterpreterError(runtime_error_code_enum_1.RuntimeErrorCode.INVALID_REQUEST, message);
|
|
15
|
+
const draftOf = (state) => ({
|
|
16
|
+
...state,
|
|
17
|
+
stack: state.stack.map((frame) => ({ ...frame })),
|
|
18
|
+
outputs: { ...state.outputs },
|
|
19
|
+
vars: { ...state.vars },
|
|
20
|
+
counters: { ...state.counters },
|
|
21
|
+
});
|
|
22
|
+
const setOwn = (target, key, value) => {
|
|
23
|
+
Object.defineProperty(target, key, {
|
|
24
|
+
value,
|
|
25
|
+
writable: true,
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
const topFrame = (draft) => draft.stack[draft.stack.length - 1];
|
|
31
|
+
const advance = (draft) => {
|
|
32
|
+
topFrame(draft).index += 1;
|
|
33
|
+
};
|
|
34
|
+
const settle = (draft, status) => {
|
|
35
|
+
draft.status = status;
|
|
36
|
+
draft.pending = null;
|
|
37
|
+
return { state: draft, effects: [], status };
|
|
38
|
+
};
|
|
39
|
+
const failRun = (draft, error, stepId) => {
|
|
40
|
+
draft.outcome = { status: definition_types_1.StopStatus.FAILED, error: { ...error, stepId } };
|
|
41
|
+
return settle(draft, interpreter_types_1.RunStatus.FAILED);
|
|
42
|
+
};
|
|
43
|
+
const emit = (draft, effect, options) => {
|
|
44
|
+
if (draft.counters.effects + 1 > options.budget.maxEffects) {
|
|
45
|
+
return failRun(draft, { code: runtime_error_code_enum_1.RuntimeErrorCode.BUDGET_EXCEEDED, message: 'Effect budget exceeded' }, effect.stepId);
|
|
46
|
+
}
|
|
47
|
+
draft.counters.effects += 1;
|
|
48
|
+
draft.pending = effect;
|
|
49
|
+
draft.status = interpreter_types_1.RunStatus.WAITING;
|
|
50
|
+
return { state: draft, effects: [effect], status: interpreter_types_1.RunStatus.WAITING };
|
|
51
|
+
};
|
|
52
|
+
const accessDenied = (verdict, subject) => ({
|
|
53
|
+
code: runtime_error_code_enum_1.RuntimeErrorCode.ACCESS_DENIED,
|
|
54
|
+
message: verdict === step_access_1.AccessVerdict.NOT_DECLARED
|
|
55
|
+
? `${subject} is not declared by the definition`
|
|
56
|
+
: `${subject} is not granted to the run`,
|
|
57
|
+
});
|
|
58
|
+
const validateHostInput = (step, options) => {
|
|
59
|
+
const definition = options.catalog.get(step.action);
|
|
60
|
+
if (!definition) {
|
|
61
|
+
return {
|
|
62
|
+
error: { code: runtime_error_code_enum_1.RuntimeErrorCode.HOST_ERROR, message: 'Host action is not in the catalog' },
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const { error, value } = definition.inputSchema.validate(step.input, { abortEarly: false });
|
|
66
|
+
if (error) {
|
|
67
|
+
const reasons = error.details.map((detail) => detail.message).join('; ');
|
|
68
|
+
return {
|
|
69
|
+
error: {
|
|
70
|
+
code: runtime_error_code_enum_1.RuntimeErrorCode.HOST_ERROR,
|
|
71
|
+
message: `Invalid host action input: ${reasons}`,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return { input: value };
|
|
76
|
+
};
|
|
77
|
+
const applyAction = (definition, draft, step, action, options) => {
|
|
78
|
+
switch (action.kind) {
|
|
79
|
+
case execute_step_1.StepActionKind.FAIL:
|
|
80
|
+
return failRun(draft, action.error, step.id);
|
|
81
|
+
case execute_step_1.StepActionKind.STOP:
|
|
82
|
+
draft.outcome = { status: action.status, output: action.output };
|
|
83
|
+
return settle(draft, action.status === definition_types_1.StopStatus.SUCCEEDED ? interpreter_types_1.RunStatus.SUCCEEDED : interpreter_types_1.RunStatus.FAILED);
|
|
84
|
+
case execute_step_1.StepActionKind.DONE: {
|
|
85
|
+
setOwn(draft.outputs, step.id, { output: action.output });
|
|
86
|
+
if (action.variable) {
|
|
87
|
+
setOwn(draft.vars, action.variable.name, action.variable.value);
|
|
88
|
+
}
|
|
89
|
+
if (action.branch === undefined) {
|
|
90
|
+
advance(draft);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
draft.stack.push({ sequencePath: (0, sequence_path_1.branchPath)(topFrame(draft), action.branch), index: 0 });
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
case execute_step_1.StepActionKind.WAIT: {
|
|
98
|
+
const maxWaitMs = Math.min(options.budget.maxWaitMs, definition_schema_1.MAX_WAIT_DURATION_MS);
|
|
99
|
+
if (action.durationMs !== undefined && action.durationMs > maxWaitMs) {
|
|
100
|
+
return failRun(draft, {
|
|
101
|
+
code: runtime_error_code_enum_1.RuntimeErrorCode.BUDGET_EXCEEDED,
|
|
102
|
+
message: `Wait duration exceeds the budget of ${maxWaitMs} ms`,
|
|
103
|
+
}, step.id);
|
|
104
|
+
}
|
|
105
|
+
const effect = { type: interpreter_types_1.EffectType.WAIT, stepId: step.id };
|
|
106
|
+
if (action.durationMs !== undefined) {
|
|
107
|
+
effect.durationMs = action.durationMs;
|
|
108
|
+
}
|
|
109
|
+
if (action.until !== undefined) {
|
|
110
|
+
effect.until = action.until;
|
|
111
|
+
}
|
|
112
|
+
return emit(draft, effect, options);
|
|
113
|
+
}
|
|
114
|
+
case execute_step_1.StepActionKind.HTTP: {
|
|
115
|
+
const verdict = (0, step_access_1.checkHttpAccess)(action.request.url, definition.accesses, options.grants);
|
|
116
|
+
if (verdict !== step_access_1.AccessVerdict.ALLOWED) {
|
|
117
|
+
return failRun(draft, accessDenied(verdict, 'HTTP request host'), step.id);
|
|
118
|
+
}
|
|
119
|
+
return emit(draft, { type: interpreter_types_1.EffectType.HTTP, stepId: step.id, request: action.request }, options);
|
|
120
|
+
}
|
|
121
|
+
case execute_step_1.StepActionKind.HOST: {
|
|
122
|
+
const verdict = (0, step_access_1.checkHostActionAccess)(action.action, definition.accesses, options.grants);
|
|
123
|
+
if (verdict !== step_access_1.AccessVerdict.ALLOWED) {
|
|
124
|
+
return failRun(draft, accessDenied(verdict, 'Host action'), step.id);
|
|
125
|
+
}
|
|
126
|
+
const validated = validateHostInput(action, options);
|
|
127
|
+
if ('error' in validated) {
|
|
128
|
+
return failRun(draft, validated.error, step.id);
|
|
129
|
+
}
|
|
130
|
+
return emit(draft, { type: interpreter_types_1.EffectType.HOST, stepId: step.id, action: action.action, input: validated.input }, options);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const runStep = (definition, draft, step, results, options) => {
|
|
135
|
+
if (results === undefined) {
|
|
136
|
+
const items = (0, step_fields_1.collectStepItems)(step);
|
|
137
|
+
if (items.length > 0) {
|
|
138
|
+
const context = { input: draft.input, steps: draft.outputs, vars: draft.vars };
|
|
139
|
+
return emit(draft, { type: interpreter_types_1.EffectType.EVALUATE, stepId: step.id, items, context }, options);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const fields = (0, step_fields_1.resolveStepFields)(step, results ?? NO_RESULTS);
|
|
143
|
+
return applyAction(definition, draft, step, (0, execute_step_1.executeStep)(step, fields), options);
|
|
144
|
+
};
|
|
145
|
+
const drive = (definition, draft, options) => {
|
|
146
|
+
for (;;) {
|
|
147
|
+
const frame = topFrame(draft);
|
|
148
|
+
if (!frame) {
|
|
149
|
+
draft.outcome = { status: definition_types_1.StopStatus.SUCCEEDED };
|
|
150
|
+
return settle(draft, interpreter_types_1.RunStatus.SUCCEEDED);
|
|
151
|
+
}
|
|
152
|
+
const sequence = (0, sequence_path_1.resolveSequence)(definition, frame.sequencePath);
|
|
153
|
+
if (frame.index >= sequence.length) {
|
|
154
|
+
draft.stack.pop();
|
|
155
|
+
if (draft.stack.length > 0) {
|
|
156
|
+
advance(draft);
|
|
157
|
+
}
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const step = sequence[frame.index];
|
|
161
|
+
if (draft.counters.steps + 1 > options.budget.maxSteps) {
|
|
162
|
+
return failRun(draft, { code: runtime_error_code_enum_1.RuntimeErrorCode.BUDGET_EXCEEDED, message: 'Step budget exceeded' }, step.id);
|
|
163
|
+
}
|
|
164
|
+
draft.counters.steps += 1;
|
|
165
|
+
const result = runStep(definition, draft, step, undefined, options);
|
|
166
|
+
if (result) {
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const start = (definition, input, options) => drive(definition, {
|
|
172
|
+
formatVersion: definition_types_1.CURRENT_FORMAT_VERSION,
|
|
173
|
+
status: interpreter_types_1.RunStatus.WAITING,
|
|
174
|
+
input,
|
|
175
|
+
stack: [{ sequencePath: sequence_path_1.ROOT_SEQUENCE_PATH, index: 0 }],
|
|
176
|
+
outputs: {},
|
|
177
|
+
vars: {},
|
|
178
|
+
pending: null,
|
|
179
|
+
counters: { steps: 0, effects: 0 },
|
|
180
|
+
}, options);
|
|
181
|
+
exports.start = start;
|
|
182
|
+
const unexpected = (event, pending) => invalidRequest(`Event ${event.type} does not answer the pending ${pending.type} effect`);
|
|
183
|
+
const readEvaluation = (pending, results) => {
|
|
184
|
+
if (pending.type !== interpreter_types_1.EffectType.EVALUATE) {
|
|
185
|
+
throw invalidRequest(`Event ${interpreter_types_1.RunEventType.EVALUATED} does not answer the pending ${pending.type} effect`);
|
|
186
|
+
}
|
|
187
|
+
const values = new Map();
|
|
188
|
+
for (const item of pending.items) {
|
|
189
|
+
const result = results.find((candidate) => candidate.id === item.id);
|
|
190
|
+
if (!result) {
|
|
191
|
+
throw invalidRequest('Evaluation results do not cover every item of the lot');
|
|
192
|
+
}
|
|
193
|
+
if (!result.ok) {
|
|
194
|
+
return result.error;
|
|
195
|
+
}
|
|
196
|
+
values.set(item.id, result.value);
|
|
197
|
+
}
|
|
198
|
+
return values;
|
|
199
|
+
};
|
|
200
|
+
const complete = (definition, draft, step, output, options) => {
|
|
201
|
+
setOwn(draft.outputs, step.id, { output });
|
|
202
|
+
advance(draft);
|
|
203
|
+
return drive(definition, draft, options);
|
|
204
|
+
};
|
|
205
|
+
const step = (definition, state, event, options) => {
|
|
206
|
+
const pending = state.pending;
|
|
207
|
+
if (state.status !== interpreter_types_1.RunStatus.WAITING || !pending) {
|
|
208
|
+
throw invalidRequest(`Event ${event.type} received by a run that waits for nothing`);
|
|
209
|
+
}
|
|
210
|
+
const draft = draftOf(state);
|
|
211
|
+
draft.pending = null;
|
|
212
|
+
const current = (0, sequence_path_1.resolveStep)(definition, topFrame(draft));
|
|
213
|
+
switch (event.type) {
|
|
214
|
+
case interpreter_types_1.RunEventType.EVALUATED: {
|
|
215
|
+
const values = readEvaluation(pending, event.results);
|
|
216
|
+
if (!(values instanceof Map)) {
|
|
217
|
+
return failRun(draft, values, current.id);
|
|
218
|
+
}
|
|
219
|
+
return (runStep(definition, draft, current, values, options) ?? drive(definition, draft, options));
|
|
220
|
+
}
|
|
221
|
+
case interpreter_types_1.RunEventType.HTTP_COMPLETED:
|
|
222
|
+
if (pending.type !== interpreter_types_1.EffectType.HTTP) {
|
|
223
|
+
throw unexpected(event, pending);
|
|
224
|
+
}
|
|
225
|
+
return complete(definition, draft, current, event.response, options);
|
|
226
|
+
case interpreter_types_1.RunEventType.HOST_COMPLETED:
|
|
227
|
+
if (pending.type !== interpreter_types_1.EffectType.HOST) {
|
|
228
|
+
throw unexpected(event, pending);
|
|
229
|
+
}
|
|
230
|
+
return complete(definition, draft, current, event.output, options);
|
|
231
|
+
case interpreter_types_1.RunEventType.WAIT_ELAPSED:
|
|
232
|
+
if (pending.type !== interpreter_types_1.EffectType.WAIT) {
|
|
233
|
+
throw unexpected(event, pending);
|
|
234
|
+
}
|
|
235
|
+
return complete(definition, draft, current, null, options);
|
|
236
|
+
case interpreter_types_1.RunEventType.EFFECT_FAILED:
|
|
237
|
+
return failRun(draft, event.error, current.id);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
exports.step = step;
|
|
241
|
+
//# sourceMappingURL=interpreter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interpreter.js","sourceRoot":"","sources":["../../src/interpreter/interpreter.ts"],"names":[],"mappings":";;;AAAA,+EAAqE;AAErE,uEAAuE;AACvE,qEAAoF;AAEpF,wDAAoE;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UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACnC,CAAC;YACD,OAAO,QAAQ,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAC7D,KAAK,gCAAY,CAAC,aAAa;YAC7B,OAAO,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IACnD,CAAC;AACH,CAAC,CAAC;AA1CW,QAAA,IAAI,QA0Cf"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { AccessGrant } from '../access/access.types';
|
|
2
|
+
import type { HostActionCatalog, HttpMethod, StopStatus } from '../definition/definition.types';
|
|
3
|
+
import type { RuntimeErrorDetail } from '../errors/runtime-error-code.enum';
|
|
4
|
+
import type { EvaluationItem, EvaluationResult } from '../runner-protocol/runner-protocol.types';
|
|
5
|
+
export declare enum RunStatus {
|
|
6
|
+
WAITING = "WAITING",
|
|
7
|
+
SUCCEEDED = "SUCCEEDED",
|
|
8
|
+
FAILED = "FAILED"
|
|
9
|
+
}
|
|
10
|
+
export interface RunBudget {
|
|
11
|
+
maxSteps: number;
|
|
12
|
+
maxEffects: number;
|
|
13
|
+
maxWaitMs: number;
|
|
14
|
+
}
|
|
15
|
+
export interface RunOptions {
|
|
16
|
+
catalog: HostActionCatalog;
|
|
17
|
+
grants: AccessGrant[];
|
|
18
|
+
budget: RunBudget;
|
|
19
|
+
}
|
|
20
|
+
export interface EvaluationContext {
|
|
21
|
+
input: unknown;
|
|
22
|
+
steps: Record<string, {
|
|
23
|
+
output: unknown;
|
|
24
|
+
}>;
|
|
25
|
+
vars: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
export declare enum EffectType {
|
|
28
|
+
EVALUATE = "EVALUATE",
|
|
29
|
+
HTTP = "HTTP",
|
|
30
|
+
HOST = "HOST",
|
|
31
|
+
WAIT = "WAIT"
|
|
32
|
+
}
|
|
33
|
+
export interface EvaluateEffect {
|
|
34
|
+
type: EffectType.EVALUATE;
|
|
35
|
+
stepId: string;
|
|
36
|
+
items: EvaluationItem[];
|
|
37
|
+
context: EvaluationContext;
|
|
38
|
+
}
|
|
39
|
+
export interface HttpRequest {
|
|
40
|
+
method: HttpMethod;
|
|
41
|
+
url: string;
|
|
42
|
+
headers: Record<string, string>;
|
|
43
|
+
body?: unknown;
|
|
44
|
+
timeoutMs?: number;
|
|
45
|
+
}
|
|
46
|
+
export interface HttpEffect {
|
|
47
|
+
type: EffectType.HTTP;
|
|
48
|
+
stepId: string;
|
|
49
|
+
request: HttpRequest;
|
|
50
|
+
}
|
|
51
|
+
export interface HostEffect {
|
|
52
|
+
type: EffectType.HOST;
|
|
53
|
+
stepId: string;
|
|
54
|
+
action: string;
|
|
55
|
+
input: Record<string, unknown>;
|
|
56
|
+
}
|
|
57
|
+
export interface WaitEffect {
|
|
58
|
+
type: EffectType.WAIT;
|
|
59
|
+
stepId: string;
|
|
60
|
+
durationMs?: number;
|
|
61
|
+
until?: string;
|
|
62
|
+
}
|
|
63
|
+
export type Effect = EvaluateEffect | HttpEffect | HostEffect | WaitEffect;
|
|
64
|
+
export declare enum RunEventType {
|
|
65
|
+
EVALUATED = "EVALUATED",
|
|
66
|
+
HTTP_COMPLETED = "HTTP_COMPLETED",
|
|
67
|
+
HOST_COMPLETED = "HOST_COMPLETED",
|
|
68
|
+
WAIT_ELAPSED = "WAIT_ELAPSED",
|
|
69
|
+
EFFECT_FAILED = "EFFECT_FAILED"
|
|
70
|
+
}
|
|
71
|
+
export interface HttpResponse {
|
|
72
|
+
status: number;
|
|
73
|
+
headers: Record<string, string>;
|
|
74
|
+
body: unknown;
|
|
75
|
+
}
|
|
76
|
+
export type RunEvent = {
|
|
77
|
+
type: RunEventType.EVALUATED;
|
|
78
|
+
results: EvaluationResult[];
|
|
79
|
+
} | {
|
|
80
|
+
type: RunEventType.HTTP_COMPLETED;
|
|
81
|
+
response: HttpResponse;
|
|
82
|
+
} | {
|
|
83
|
+
type: RunEventType.HOST_COMPLETED;
|
|
84
|
+
output: unknown;
|
|
85
|
+
} | {
|
|
86
|
+
type: RunEventType.WAIT_ELAPSED;
|
|
87
|
+
} | {
|
|
88
|
+
type: RunEventType.EFFECT_FAILED;
|
|
89
|
+
error: RuntimeErrorDetail;
|
|
90
|
+
};
|
|
91
|
+
export interface Frame {
|
|
92
|
+
sequencePath: string;
|
|
93
|
+
index: number;
|
|
94
|
+
}
|
|
95
|
+
export interface RunState {
|
|
96
|
+
formatVersion: number;
|
|
97
|
+
status: RunStatus;
|
|
98
|
+
input: unknown;
|
|
99
|
+
stack: Frame[];
|
|
100
|
+
outputs: Record<string, {
|
|
101
|
+
output: unknown;
|
|
102
|
+
}>;
|
|
103
|
+
vars: Record<string, unknown>;
|
|
104
|
+
pending: Effect | null;
|
|
105
|
+
counters: {
|
|
106
|
+
steps: number;
|
|
107
|
+
effects: number;
|
|
108
|
+
};
|
|
109
|
+
outcome?: {
|
|
110
|
+
status: StopStatus;
|
|
111
|
+
output?: unknown;
|
|
112
|
+
error?: RuntimeErrorDetail & {
|
|
113
|
+
stepId?: string;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export interface StepResult {
|
|
118
|
+
state: RunState;
|
|
119
|
+
effects: Effect[];
|
|
120
|
+
status: RunStatus;
|
|
121
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RunEventType = exports.EffectType = exports.RunStatus = void 0;
|
|
4
|
+
var RunStatus;
|
|
5
|
+
(function (RunStatus) {
|
|
6
|
+
RunStatus["WAITING"] = "WAITING";
|
|
7
|
+
RunStatus["SUCCEEDED"] = "SUCCEEDED";
|
|
8
|
+
RunStatus["FAILED"] = "FAILED";
|
|
9
|
+
})(RunStatus || (exports.RunStatus = RunStatus = {}));
|
|
10
|
+
var EffectType;
|
|
11
|
+
(function (EffectType) {
|
|
12
|
+
EffectType["EVALUATE"] = "EVALUATE";
|
|
13
|
+
EffectType["HTTP"] = "HTTP";
|
|
14
|
+
EffectType["HOST"] = "HOST";
|
|
15
|
+
EffectType["WAIT"] = "WAIT";
|
|
16
|
+
})(EffectType || (exports.EffectType = EffectType = {}));
|
|
17
|
+
var RunEventType;
|
|
18
|
+
(function (RunEventType) {
|
|
19
|
+
RunEventType["EVALUATED"] = "EVALUATED";
|
|
20
|
+
RunEventType["HTTP_COMPLETED"] = "HTTP_COMPLETED";
|
|
21
|
+
RunEventType["HOST_COMPLETED"] = "HOST_COMPLETED";
|
|
22
|
+
RunEventType["WAIT_ELAPSED"] = "WAIT_ELAPSED";
|
|
23
|
+
RunEventType["EFFECT_FAILED"] = "EFFECT_FAILED";
|
|
24
|
+
})(RunEventType || (exports.RunEventType = RunEventType = {}));
|
|
25
|
+
//# sourceMappingURL=interpreter.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interpreter.types.js","sourceRoot":"","sources":["../../src/interpreter/interpreter.types.ts"],"names":[],"mappings":";;;AAKA,IAAY,SAKX;AALD,WAAY,SAAS;IAEnB,gCAAmB,CAAA;IACnB,oCAAuB,CAAA;IACvB,8BAAiB,CAAA;AACnB,CAAC,EALW,SAAS,yBAAT,SAAS,QAKpB;AAuBD,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,mCAAqB,CAAA;IACrB,2BAAa,CAAA;IACb,2BAAa,CAAA;IACb,2BAAa,CAAA;AACf,CAAC,EALW,UAAU,0BAAV,UAAU,QAKrB;AA8CD,IAAY,YAMX;AAND,WAAY,YAAY;IACtB,uCAAuB,CAAA;IACvB,iDAAiC,CAAA;IACjC,iDAAiC,CAAA;IACjC,6CAA6B,CAAA;IAC7B,+CAA+B,CAAA;AACjC,CAAC,EANW,YAAY,4BAAZ,YAAY,QAMvB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RuntimeDefinition, Step } from '../definition/definition.types';
|
|
2
|
+
import type { Frame } from './interpreter.types';
|
|
3
|
+
export declare const resolveSequence: (definition: RuntimeDefinition, path: string) => Step[];
|
|
4
|
+
export declare const resolveStep: (definition: RuntimeDefinition, frame: Frame) => Step;
|
|
5
|
+
export declare const branchPath: (frame: Frame, branch: string) => string;
|
|
6
|
+
export declare const ROOT_SEQUENCE_PATH = "steps";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ROOT_SEQUENCE_PATH = exports.branchPath = exports.resolveStep = exports.resolveSequence = void 0;
|
|
4
|
+
const runtime_error_code_enum_1 = require("../errors/runtime-error-code.enum");
|
|
5
|
+
const definition_types_1 = require("../definition/definition.types");
|
|
6
|
+
const interpreter_error_1 = require("./interpreter-error");
|
|
7
|
+
const ROOT = 'steps';
|
|
8
|
+
const SEGMENT = /\[(\d+)\]\.(?:(then|else|default)|cases\[(\d+)\]\.steps)/y;
|
|
9
|
+
const corrupted = (path) => new interpreter_error_1.InterpreterError(runtime_error_code_enum_1.RuntimeErrorCode.INVALID_REQUEST, `Run state points outside the definition: ${path}`);
|
|
10
|
+
const branchOf = (step, name, caseIndex) => {
|
|
11
|
+
if (step.type === definition_types_1.StepType.CONDITION) {
|
|
12
|
+
return name === 'then' ? step.then : name === 'else' ? step.else : undefined;
|
|
13
|
+
}
|
|
14
|
+
if (step.type === definition_types_1.StepType.SWITCH) {
|
|
15
|
+
return name === 'default'
|
|
16
|
+
? step.default
|
|
17
|
+
: caseIndex === undefined
|
|
18
|
+
? undefined
|
|
19
|
+
: step.cases[Number(caseIndex)]?.steps;
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
};
|
|
23
|
+
const resolveSequence = (definition, path) => {
|
|
24
|
+
if (!path.startsWith(ROOT)) {
|
|
25
|
+
throw corrupted(path);
|
|
26
|
+
}
|
|
27
|
+
let sequence = definition.steps;
|
|
28
|
+
let position = ROOT.length;
|
|
29
|
+
while (position < path.length) {
|
|
30
|
+
SEGMENT.lastIndex = position;
|
|
31
|
+
const match = SEGMENT.exec(path);
|
|
32
|
+
const next = match ? branchOf(sequence[Number(match[1])], match[2], match[3]) : undefined;
|
|
33
|
+
if (!match || !next) {
|
|
34
|
+
throw corrupted(path);
|
|
35
|
+
}
|
|
36
|
+
sequence = next;
|
|
37
|
+
position = SEGMENT.lastIndex;
|
|
38
|
+
}
|
|
39
|
+
return sequence;
|
|
40
|
+
};
|
|
41
|
+
exports.resolveSequence = resolveSequence;
|
|
42
|
+
const resolveStep = (definition, frame) => {
|
|
43
|
+
const step = (0, exports.resolveSequence)(definition, frame.sequencePath)[frame.index];
|
|
44
|
+
if (!step) {
|
|
45
|
+
throw corrupted(frame.sequencePath);
|
|
46
|
+
}
|
|
47
|
+
return step;
|
|
48
|
+
};
|
|
49
|
+
exports.resolveStep = resolveStep;
|
|
50
|
+
const branchPath = (frame, branch) => `${frame.sequencePath}[${frame.index}].${branch}`;
|
|
51
|
+
exports.branchPath = branchPath;
|
|
52
|
+
exports.ROOT_SEQUENCE_PATH = ROOT;
|
|
53
|
+
//# sourceMappingURL=sequence-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sequence-path.js","sourceRoot":"","sources":["../../src/interpreter/sequence-path.ts"],"names":[],"mappings":";;;AAAA,+EAAqE;AACrE,qEAA0D;AAE1D,2DAAuD;AAGvD,MAAM,IAAI,GAAG,OAAO,CAAC;AACrB,MAAM,OAAO,GAAG,2DAA2D,CAAC;AAE5E,MAAM,SAAS,GAAG,CAAC,IAAY,EAAoB,EAAE,CACnD,IAAI,oCAAgB,CAClB,0CAAgB,CAAC,eAAe,EAChC,4CAA4C,IAAI,EAAE,CACnD,CAAC;AAEJ,MAAM,QAAQ,GAAG,CACf,IAAU,EACV,IAAwB,EACxB,SAA6B,EACT,EAAE;IACtB,IAAI,IAAI,CAAC,IAAI,KAAK,2BAAQ,CAAC,SAA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,CAAC,IAAI,EAAE,CAAC;YACpB,MAAM,SAAS,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;QACD,QAAQ,GAAG,IAAI,CAAC;QAChB,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;IAC/B,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAjBW,QAAA,eAAe,mBAiB1B;AAGK,MAAM,WAAW,GAAG,CAAC,UAA6B,EAAE,KAAY,EAAQ,EAAE;IAC/E,MAAM,IAAI,GAAG,IAAA,uBAAe,EAAC,UAAU,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1E,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,SAAS,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AANW,QAAA,WAAW,eAMtB;AAGK,MAAM,UAAU,GAAG,CAAC,KAAY,EAAE,MAAc,EAAU,EAAE,CACjE,GAAG,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,KAAK,KAAK,MAAM,EAAE,CAAC;AADvC,QAAA,UAAU,cAC6B;AAEvC,QAAA,kBAAkB,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RuntimeDefinition } from '../definition/definition.types';
|
|
2
|
+
import type { Effect, EvaluateEffect, HostEffect, HttpEffect, HttpResponse, RunOptions, RunState, WaitEffect } from './interpreter.types';
|
|
3
|
+
import type { EvaluationResult } from '../runner-protocol/runner-protocol.types';
|
|
4
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
5
|
+
export interface TestHostHandlers {
|
|
6
|
+
evaluate: (effect: EvaluateEffect) => MaybePromise<EvaluationResult[]>;
|
|
7
|
+
http?: (effect: HttpEffect) => MaybePromise<HttpResponse>;
|
|
8
|
+
host?: (effect: HostEffect) => MaybePromise<unknown>;
|
|
9
|
+
wait?: (effect: WaitEffect) => MaybePromise<void>;
|
|
10
|
+
}
|
|
11
|
+
export interface TestRunResult {
|
|
12
|
+
state: RunState;
|
|
13
|
+
effects: Effect[];
|
|
14
|
+
}
|
|
15
|
+
export declare const runToCompletion: (definition: RuntimeDefinition, input: unknown, options: RunOptions, handlers: TestHostHandlers) => Promise<TestRunResult>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runToCompletion = void 0;
|
|
4
|
+
const interpreter_1 = require("./interpreter");
|
|
5
|
+
const interpreter_types_1 = require("./interpreter.types");
|
|
6
|
+
const DEFAULT_HTTP_RESPONSE = { status: 200, headers: {}, body: null };
|
|
7
|
+
const answer = async (effect, handlers) => {
|
|
8
|
+
switch (effect.type) {
|
|
9
|
+
case interpreter_types_1.EffectType.EVALUATE:
|
|
10
|
+
return { type: interpreter_types_1.RunEventType.EVALUATED, results: await handlers.evaluate(effect) };
|
|
11
|
+
case interpreter_types_1.EffectType.HTTP:
|
|
12
|
+
return {
|
|
13
|
+
type: interpreter_types_1.RunEventType.HTTP_COMPLETED,
|
|
14
|
+
response: handlers.http ? await handlers.http(effect) : DEFAULT_HTTP_RESPONSE,
|
|
15
|
+
};
|
|
16
|
+
case interpreter_types_1.EffectType.HOST:
|
|
17
|
+
return {
|
|
18
|
+
type: interpreter_types_1.RunEventType.HOST_COMPLETED,
|
|
19
|
+
output: handlers.host ? await handlers.host(effect) : null,
|
|
20
|
+
};
|
|
21
|
+
case interpreter_types_1.EffectType.WAIT:
|
|
22
|
+
await handlers.wait?.(effect);
|
|
23
|
+
return { type: interpreter_types_1.RunEventType.WAIT_ELAPSED };
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const runToCompletion = async (definition, input, options, handlers) => {
|
|
27
|
+
const effects = [];
|
|
28
|
+
let result = (0, interpreter_1.start)(definition, input, options);
|
|
29
|
+
while (result.effects.length > 0) {
|
|
30
|
+
const [effect] = result.effects;
|
|
31
|
+
effects.push(effect);
|
|
32
|
+
result = (0, interpreter_1.step)(definition, result.state, await answer(effect, handlers), options);
|
|
33
|
+
}
|
|
34
|
+
return { state: result.state, effects };
|
|
35
|
+
};
|
|
36
|
+
exports.runToCompletion = runToCompletion;
|
|
37
|
+
//# sourceMappingURL=test-host.js.map
|