@versori/run 0.7.0-alpha.3 → 0.7.0-alpha.6

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 (175) hide show
  1. package/esm/mod.d.ts +1 -1
  2. package/esm/mod.d.ts.map +1 -1
  3. package/esm/mod.js +1 -1
  4. package/esm/src/connection/VanillaConnectionFactory.d.ts +16 -0
  5. package/esm/src/connection/VanillaConnectionFactory.d.ts.map +1 -0
  6. package/esm/src/connection/VanillaConnectionFactory.js +23 -0
  7. package/esm/src/context/ActivationImpl.d.ts +2 -1
  8. package/esm/src/context/ActivationImpl.d.ts.map +1 -1
  9. package/esm/src/context/Context.d.ts +4 -2
  10. package/esm/src/context/Context.d.ts.map +1 -1
  11. package/esm/src/context/ContextProvider.d.ts +6 -6
  12. package/esm/src/context/ContextProvider.d.ts.map +1 -1
  13. package/esm/src/context/VanillaContext.d.ts +60 -0
  14. package/esm/src/context/VanillaContext.d.ts.map +1 -0
  15. package/esm/src/context/VanillaContext.js +296 -0
  16. package/esm/src/dsl/http/mod.d.ts +1 -1
  17. package/esm/src/dsl/http/mod.d.ts.map +1 -1
  18. package/esm/src/dsl/http/types.d.ts +19 -134
  19. package/esm/src/dsl/http/types.d.ts.map +1 -1
  20. package/esm/src/dsl/http/versori/configloader.d.ts.map +1 -1
  21. package/esm/src/dsl/http/versori/configloader.js +3 -0
  22. package/esm/src/dsl/tasks/HttpTask.d.ts +5 -5
  23. package/esm/src/dsl/tasks/HttpTask.d.ts.map +1 -1
  24. package/esm/src/dsl/triggers/ScheduleTrigger.d.ts +2 -2
  25. package/esm/src/dsl/triggers/ScheduleTrigger.d.ts.map +1 -1
  26. package/esm/src/interpreter/memory/MemoryInterpreter.d.ts +2 -2
  27. package/esm/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
  28. package/esm/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
  29. package/esm/src/interpreter/mod.d.ts +1 -0
  30. package/esm/src/interpreter/mod.d.ts.map +1 -1
  31. package/esm/src/interpreter/mod.js +1 -0
  32. package/esm/src/interpreter/vanilla/ExecutionError.d.ts +27 -0
  33. package/esm/src/interpreter/vanilla/ExecutionError.d.ts.map +1 -0
  34. package/esm/src/interpreter/vanilla/ExecutionError.js +48 -0
  35. package/esm/src/interpreter/vanilla/ObservableCompiler.d.ts +38 -0
  36. package/esm/src/interpreter/vanilla/ObservableCompiler.d.ts.map +1 -0
  37. package/esm/src/interpreter/vanilla/ObservableCompiler.js +95 -0
  38. package/esm/src/interpreter/vanilla/Queue.d.ts +72 -0
  39. package/esm/src/interpreter/vanilla/Queue.d.ts.map +1 -0
  40. package/esm/src/interpreter/vanilla/Queue.js +176 -0
  41. package/esm/src/interpreter/vanilla/VanillaInterpreter.d.ts +95 -0
  42. package/esm/src/interpreter/vanilla/VanillaInterpreter.d.ts.map +1 -0
  43. package/esm/src/interpreter/vanilla/VanillaInterpreter.js +428 -0
  44. package/esm/src/interpreter/vanilla/compilers/background.d.ts +4 -0
  45. package/esm/src/interpreter/vanilla/compilers/background.d.ts.map +1 -0
  46. package/esm/src/interpreter/vanilla/compilers/background.js +34 -0
  47. package/esm/src/interpreter/vanilla/compilers/catch.d.ts +4 -0
  48. package/esm/src/interpreter/vanilla/compilers/catch.d.ts.map +1 -0
  49. package/esm/src/interpreter/vanilla/compilers/catch.js +75 -0
  50. package/esm/src/interpreter/vanilla/compilers/chain.d.ts +3 -0
  51. package/esm/src/interpreter/vanilla/compilers/chain.d.ts.map +1 -0
  52. package/esm/src/interpreter/vanilla/compilers/chain.js +21 -0
  53. package/esm/src/interpreter/vanilla/compilers/durableworkflow.d.ts +8 -0
  54. package/esm/src/interpreter/vanilla/compilers/durableworkflow.d.ts.map +1 -0
  55. package/esm/src/interpreter/vanilla/compilers/durableworkflow.js +90 -0
  56. package/esm/src/interpreter/vanilla/compilers/fn.d.ts +4 -0
  57. package/esm/src/interpreter/vanilla/compilers/fn.d.ts.map +1 -0
  58. package/esm/src/interpreter/vanilla/compilers/fn.js +34 -0
  59. package/esm/src/interpreter/vanilla/compilers/http.d.ts +4 -0
  60. package/esm/src/interpreter/vanilla/compilers/http.d.ts.map +1 -0
  61. package/esm/src/interpreter/vanilla/compilers/http.js +54 -0
  62. package/esm/src/interpreter/vanilla/compilers/mod.d.ts +2 -0
  63. package/esm/src/interpreter/vanilla/compilers/mod.d.ts.map +1 -0
  64. package/esm/src/interpreter/vanilla/compilers/mod.js +13 -0
  65. package/esm/src/interpreter/vanilla/compilers/parallel.d.ts +4 -0
  66. package/esm/src/interpreter/vanilla/compilers/parallel.d.ts.map +1 -0
  67. package/esm/src/interpreter/vanilla/compilers/parallel.js +31 -0
  68. package/esm/src/interpreter/vanilla/compilers/schedule.d.ts +4 -0
  69. package/esm/src/interpreter/vanilla/compilers/schedule.d.ts.map +1 -0
  70. package/esm/src/interpreter/vanilla/compilers/schedule.js +76 -0
  71. package/esm/src/interpreter/vanilla/compilers/serial.d.ts +4 -0
  72. package/esm/src/interpreter/vanilla/compilers/serial.d.ts.map +1 -0
  73. package/esm/src/interpreter/vanilla/compilers/serial.js +28 -0
  74. package/esm/src/interpreter/vanilla/compilers/types.d.ts +15 -0
  75. package/esm/src/interpreter/vanilla/compilers/types.d.ts.map +1 -0
  76. package/esm/src/interpreter/vanilla/compilers/types.js +13 -0
  77. package/esm/src/interpreter/vanilla/compilers/unpack.d.ts +4 -0
  78. package/esm/src/interpreter/vanilla/compilers/unpack.d.ts.map +1 -0
  79. package/esm/src/interpreter/vanilla/compilers/unpack.js +34 -0
  80. package/esm/src/interpreter/vanilla/compilers/webhook.d.ts +4 -0
  81. package/esm/src/interpreter/vanilla/compilers/webhook.d.ts.map +1 -0
  82. package/esm/src/interpreter/vanilla/compilers/webhook.js +259 -0
  83. package/esm/src/interpreter/vanilla/mod.d.ts +3 -0
  84. package/esm/src/interpreter/vanilla/mod.d.ts.map +1 -0
  85. package/esm/src/interpreter/vanilla/mod.js +14 -0
  86. package/esm/src/issues/Issues.d.ts +1 -18
  87. package/esm/src/issues/Issues.d.ts.map +1 -1
  88. package/package.json +1 -1
  89. package/script/mod.d.ts +1 -1
  90. package/script/mod.d.ts.map +1 -1
  91. package/script/mod.js +2 -1
  92. package/script/src/connection/VanillaConnectionFactory.d.ts +16 -0
  93. package/script/src/connection/VanillaConnectionFactory.d.ts.map +1 -0
  94. package/script/src/connection/VanillaConnectionFactory.js +28 -0
  95. package/script/src/context/ActivationImpl.d.ts +2 -1
  96. package/script/src/context/ActivationImpl.d.ts.map +1 -1
  97. package/script/src/context/Context.d.ts +4 -2
  98. package/script/src/context/Context.d.ts.map +1 -1
  99. package/script/src/context/ContextProvider.d.ts +6 -6
  100. package/script/src/context/ContextProvider.d.ts.map +1 -1
  101. package/script/src/context/VanillaContext.d.ts +60 -0
  102. package/script/src/context/VanillaContext.d.ts.map +1 -0
  103. package/script/src/context/VanillaContext.js +302 -0
  104. package/script/src/dsl/http/mod.d.ts +1 -1
  105. package/script/src/dsl/http/mod.d.ts.map +1 -1
  106. package/script/src/dsl/http/types.d.ts +19 -134
  107. package/script/src/dsl/http/types.d.ts.map +1 -1
  108. package/script/src/dsl/http/versori/configloader.d.ts.map +1 -1
  109. package/script/src/dsl/http/versori/configloader.js +3 -0
  110. package/script/src/dsl/tasks/HttpTask.d.ts +5 -5
  111. package/script/src/dsl/tasks/HttpTask.d.ts.map +1 -1
  112. package/script/src/dsl/triggers/ScheduleTrigger.d.ts +2 -2
  113. package/script/src/dsl/triggers/ScheduleTrigger.d.ts.map +1 -1
  114. package/script/src/interpreter/memory/MemoryInterpreter.d.ts +2 -2
  115. package/script/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
  116. package/script/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
  117. package/script/src/interpreter/mod.d.ts +1 -0
  118. package/script/src/interpreter/mod.d.ts.map +1 -1
  119. package/script/src/interpreter/mod.js +2 -1
  120. package/script/src/interpreter/vanilla/ExecutionError.d.ts +27 -0
  121. package/script/src/interpreter/vanilla/ExecutionError.d.ts.map +1 -0
  122. package/script/src/interpreter/vanilla/ExecutionError.js +52 -0
  123. package/script/src/interpreter/vanilla/ObservableCompiler.d.ts +38 -0
  124. package/script/src/interpreter/vanilla/ObservableCompiler.d.ts.map +1 -0
  125. package/script/src/interpreter/vanilla/ObservableCompiler.js +99 -0
  126. package/script/src/interpreter/vanilla/Queue.d.ts +72 -0
  127. package/script/src/interpreter/vanilla/Queue.d.ts.map +1 -0
  128. package/script/src/interpreter/vanilla/Queue.js +181 -0
  129. package/script/src/interpreter/vanilla/VanillaInterpreter.d.ts +95 -0
  130. package/script/src/interpreter/vanilla/VanillaInterpreter.d.ts.map +1 -0
  131. package/script/src/interpreter/vanilla/VanillaInterpreter.js +435 -0
  132. package/script/src/interpreter/vanilla/compilers/background.d.ts +4 -0
  133. package/script/src/interpreter/vanilla/compilers/background.d.ts.map +1 -0
  134. package/script/src/interpreter/vanilla/compilers/background.js +37 -0
  135. package/script/src/interpreter/vanilla/compilers/catch.d.ts +4 -0
  136. package/script/src/interpreter/vanilla/compilers/catch.d.ts.map +1 -0
  137. package/script/src/interpreter/vanilla/compilers/catch.js +78 -0
  138. package/script/src/interpreter/vanilla/compilers/chain.d.ts +3 -0
  139. package/script/src/interpreter/vanilla/compilers/chain.d.ts.map +1 -0
  140. package/script/src/interpreter/vanilla/compilers/chain.js +24 -0
  141. package/script/src/interpreter/vanilla/compilers/durableworkflow.d.ts +8 -0
  142. package/script/src/interpreter/vanilla/compilers/durableworkflow.d.ts.map +1 -0
  143. package/script/src/interpreter/vanilla/compilers/durableworkflow.js +94 -0
  144. package/script/src/interpreter/vanilla/compilers/fn.d.ts +4 -0
  145. package/script/src/interpreter/vanilla/compilers/fn.d.ts.map +1 -0
  146. package/script/src/interpreter/vanilla/compilers/fn.js +37 -0
  147. package/script/src/interpreter/vanilla/compilers/http.d.ts +4 -0
  148. package/script/src/interpreter/vanilla/compilers/http.d.ts.map +1 -0
  149. package/script/src/interpreter/vanilla/compilers/http.js +57 -0
  150. package/script/src/interpreter/vanilla/compilers/mod.d.ts +2 -0
  151. package/script/src/interpreter/vanilla/compilers/mod.d.ts.map +1 -0
  152. package/script/src/interpreter/vanilla/compilers/mod.js +14 -0
  153. package/script/src/interpreter/vanilla/compilers/parallel.d.ts +4 -0
  154. package/script/src/interpreter/vanilla/compilers/parallel.d.ts.map +1 -0
  155. package/script/src/interpreter/vanilla/compilers/parallel.js +34 -0
  156. package/script/src/interpreter/vanilla/compilers/schedule.d.ts +4 -0
  157. package/script/src/interpreter/vanilla/compilers/schedule.d.ts.map +1 -0
  158. package/script/src/interpreter/vanilla/compilers/schedule.js +79 -0
  159. package/script/src/interpreter/vanilla/compilers/serial.d.ts +4 -0
  160. package/script/src/interpreter/vanilla/compilers/serial.d.ts.map +1 -0
  161. package/script/src/interpreter/vanilla/compilers/serial.js +31 -0
  162. package/script/src/interpreter/vanilla/compilers/types.d.ts +15 -0
  163. package/script/src/interpreter/vanilla/compilers/types.d.ts.map +1 -0
  164. package/script/src/interpreter/vanilla/compilers/types.js +14 -0
  165. package/script/src/interpreter/vanilla/compilers/unpack.d.ts +4 -0
  166. package/script/src/interpreter/vanilla/compilers/unpack.d.ts.map +1 -0
  167. package/script/src/interpreter/vanilla/compilers/unpack.js +37 -0
  168. package/script/src/interpreter/vanilla/compilers/webhook.d.ts +4 -0
  169. package/script/src/interpreter/vanilla/compilers/webhook.d.ts.map +1 -0
  170. package/script/src/interpreter/vanilla/compilers/webhook.js +265 -0
  171. package/script/src/interpreter/vanilla/mod.d.ts +3 -0
  172. package/script/src/interpreter/vanilla/mod.d.ts.map +1 -0
  173. package/script/src/interpreter/vanilla/mod.js +30 -0
  174. package/script/src/issues/Issues.d.ts +1 -18
  175. package/script/src/issues/Issues.d.ts.map +1 -1
@@ -0,0 +1,435 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Versori Group Inc
4
+ *
5
+ * Use of this software is governed by the Business Source License 1.1
6
+ * included in the LICENSE file at the root of this repository.
7
+ *
8
+ * Change Date: 2029-01-01
9
+ * Change License: Apache License, Version 2.0
10
+ *
11
+ * As of the Change Date, in accordance with the Business Source License,
12
+ * use of this software will be governed by the Apache License, Version 2.0.
13
+ */
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.VanillaInterpreter = void 0;
19
+ const api_1 = __importDefault(require("@opentelemetry/api"));
20
+ const exporter_trace_otlp_proto_1 = require("@opentelemetry/exporter-trace-otlp-proto");
21
+ const resources_1 = require("@opentelemetry/resources");
22
+ const sdk_node_1 = require("@opentelemetry/sdk-node");
23
+ const express_1 = __importDefault(require("express"));
24
+ const rxjs_1 = require("rxjs");
25
+ const configloader_js_1 = require("../../dsl/http/versori/configloader.js");
26
+ const constants_js_1 = require("../../dsl/http/versori/constants.js");
27
+ const cronapi_js_1 = require("../../dsl/http/versori/cronapi.js");
28
+ const Workflow_js_1 = require("../../dsl/Workflow.js");
29
+ const Issues_js_1 = require("../../issues/Issues.js");
30
+ const MemoryKeyValueProvider_js_1 = require("../../kv/memory/MemoryKeyValueProvider.js");
31
+ const SDKKeyValueProvider_js_1 = require("../../kv/sdk/SDKKeyValueProvider.js");
32
+ const ConsoleLogger_js_1 = require("../../observability/logging/ConsoleLogger.js");
33
+ const ObservableCompiler_js_1 = require("./ObservableCompiler.js");
34
+ const Queue_js_1 = require("./Queue.js");
35
+ const VanillaConnectionFactory_js_1 = require("../../connection/VanillaConnectionFactory.js");
36
+ const VanillaContext_js_1 = require("../../context/VanillaContext.js");
37
+ function getKVProvider(runLocal) {
38
+ if (runLocal) {
39
+ return Promise.resolve(new MemoryKeyValueProvider_js_1.MemoryKeyValueProvider());
40
+ }
41
+ return SDKKeyValueProvider_js_1.SDKKeyValueProvider.fromEnv();
42
+ }
43
+ /**
44
+ * VanillaInterpreter is an interpreter for executing Versori workflows with support for durable, queue-based workflow
45
+ * execution. It supports all trigger types including the {@link workflow} trigger which allows workflows to be started
46
+ * programmatically.
47
+ *
48
+ * Unlike {@link DurableInterpreter}, this interpreter is incapable of using connections. Therefore, all fetch requests will need
49
+ * to use fully qualified URLs and authentication must be handled manually within the workflow.
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * import { VanillaInterpreter, workflow, fn } from '@versori/run';
54
+ *
55
+ * const processJob = workflow('process-job', { maxAttempts: 3 })
56
+ * .then(fn('task', async (ctx) => {
57
+ * ctx.log.info('Processing job', { data: ctx.data });
58
+ * // ... long-running process
59
+ * }));
60
+ *
61
+ * const interpreter = new VanillaInterpreter();
62
+ * interpreter.register(processJob);
63
+ * await interpreter.start();
64
+ * ```
65
+ */
66
+ class VanillaInterpreter {
67
+ constructor(log, compiler, contextProvider, webhookRouter, cronRouter, cronRegistry, cnxFetchFactory, cronProvider, tracer, cfgReader, queueProvider, otelSDK) {
68
+ Object.defineProperty(this, "log", {
69
+ enumerable: true,
70
+ configurable: true,
71
+ writable: true,
72
+ value: log
73
+ });
74
+ Object.defineProperty(this, "compiler", {
75
+ enumerable: true,
76
+ configurable: true,
77
+ writable: true,
78
+ value: compiler
79
+ });
80
+ Object.defineProperty(this, "contextProvider", {
81
+ enumerable: true,
82
+ configurable: true,
83
+ writable: true,
84
+ value: contextProvider
85
+ });
86
+ Object.defineProperty(this, "webhookRouter", {
87
+ enumerable: true,
88
+ configurable: true,
89
+ writable: true,
90
+ value: webhookRouter
91
+ });
92
+ Object.defineProperty(this, "cronRouter", {
93
+ enumerable: true,
94
+ configurable: true,
95
+ writable: true,
96
+ value: cronRouter
97
+ });
98
+ Object.defineProperty(this, "cronRegistry", {
99
+ enumerable: true,
100
+ configurable: true,
101
+ writable: true,
102
+ value: cronRegistry
103
+ });
104
+ Object.defineProperty(this, "cnxFetchFactory", {
105
+ enumerable: true,
106
+ configurable: true,
107
+ writable: true,
108
+ value: cnxFetchFactory
109
+ });
110
+ Object.defineProperty(this, "cronProvider", {
111
+ enumerable: true,
112
+ configurable: true,
113
+ writable: true,
114
+ value: cronProvider
115
+ });
116
+ Object.defineProperty(this, "tracer", {
117
+ enumerable: true,
118
+ configurable: true,
119
+ writable: true,
120
+ value: tracer
121
+ });
122
+ Object.defineProperty(this, "cfgReader", {
123
+ enumerable: true,
124
+ configurable: true,
125
+ writable: true,
126
+ value: cfgReader
127
+ });
128
+ Object.defineProperty(this, "queueProvider", {
129
+ enumerable: true,
130
+ configurable: true,
131
+ writable: true,
132
+ value: queueProvider
133
+ });
134
+ Object.defineProperty(this, "otelSDK", {
135
+ enumerable: true,
136
+ configurable: true,
137
+ writable: true,
138
+ value: otelSDK
139
+ });
140
+ Object.defineProperty(this, "registeredWorkflows", {
141
+ enumerable: true,
142
+ configurable: true,
143
+ writable: true,
144
+ value: []
145
+ });
146
+ Object.defineProperty(this, "webhookServer", {
147
+ enumerable: true,
148
+ configurable: true,
149
+ writable: true,
150
+ value: void 0
151
+ });
152
+ Object.defineProperty(this, "cronServer", {
153
+ enumerable: true,
154
+ configurable: true,
155
+ writable: true,
156
+ value: void 0
157
+ });
158
+ Object.defineProperty(this, "shutdownServer", {
159
+ enumerable: true,
160
+ configurable: true,
161
+ writable: true,
162
+ value: void 0
163
+ });
164
+ Object.defineProperty(this, "isShuttingDown", {
165
+ enumerable: true,
166
+ configurable: true,
167
+ writable: true,
168
+ value: false
169
+ });
170
+ if (typeof this.log === 'undefined') {
171
+ throw new Error('VanillaInterpreter should not be instantiated directly. Use VanillaInterpreter.newInstance() instead.');
172
+ }
173
+ }
174
+ static async newInstance(options = {}) {
175
+ const log = options.logger || new ConsoleLogger_js_1.ConsoleLogger('debug');
176
+ const compiler = options.compiler || new ObservableCompiler_js_1.ObservableCompiler();
177
+ const serviceName = Deno.env.get(constants_js_1.envVarProjectId) || 'example-service';
178
+ const environmentID = Deno.env.get(constants_js_1.envVarEnvId) || 'development';
179
+ const version = Deno.env.get(constants_js_1.envVarVersion) || '1.0.0';
180
+ const environment = Deno.env.get(constants_js_1.envVarEnvironmentName) || 'development';
181
+ const orgId = Deno.env.get(constants_js_1.envVarOrgId) || 'development';
182
+ const orgSlug = Deno.env.get(constants_js_1.envVarOrgSlug) || 'development';
183
+ const otelTracesURL = Deno.env.get(constants_js_1.envVarOtelTracesURL);
184
+ let otelSDK;
185
+ const configReader = configloader_js_1.VersoriConfigReader.fromEnv(log);
186
+ const runLocal = Deno.env.get(constants_js_1.envVarLocalRun) === 'true';
187
+ await waitForReady(log);
188
+ // Do NOT change these attributes, they are used by the API to filter on
189
+ const resource = (0, resources_1.resourceFromAttributes)({
190
+ 'service.id': serviceName,
191
+ 'service.environment': environment,
192
+ 'service.environment_id': environmentID,
193
+ 'service.version': version,
194
+ 'service.organisation_id': orgId,
195
+ 'service.organisation_slug': orgSlug,
196
+ });
197
+ if (otelTracesURL && serviceName) {
198
+ otelSDK = new sdk_node_1.NodeSDK({
199
+ traceExporter: new exporter_trace_otlp_proto_1.OTLPTraceExporter({
200
+ url: otelTracesURL,
201
+ }),
202
+ serviceName: serviceName,
203
+ resource: resource,
204
+ });
205
+ log.info('Starting OpenTelemetry SDK');
206
+ otelSDK.start();
207
+ }
208
+ const tracer = api_1.default.trace.getTracer(serviceName, version);
209
+ const queueProvider = await Queue_js_1.QueueImpl.fromEnv(log);
210
+ const connectionFactory = new VanillaConnectionFactory_js_1.DefaultConnectionFactory();
211
+ const issuesProvider = new Issues_js_1.IssueImpl(log);
212
+ if (options.contextProvider) {
213
+ return new VanillaInterpreter(log, compiler, options.contextProvider, express_1.default.Router(), express_1.default.Router(), new Map(), connectionFactory, cronapi_js_1.CronAPIClient.fromEnv(), tracer, configReader, queueProvider, otelSDK);
214
+ }
215
+ const kvp = await getKVProvider(runLocal);
216
+ const organisationId = Deno.env.get(constants_js_1.envVarOrgId) || 'development';
217
+ const environmentId = Deno.env.get(constants_js_1.envVarEnvId) || 'development';
218
+ const ctxProvider = new VanillaContext_js_1.VanillaContextProvider(log, kvp, organisationId, environmentId, issuesProvider);
219
+ return new VanillaInterpreter(log, compiler, ctxProvider, express_1.default.Router(), express_1.default.Router(), new Map(), connectionFactory, cronapi_js_1.CronAPIClient.fromEnv(), tracer, configReader, queueProvider, otelSDK);
220
+ }
221
+ register(workflow, options) {
222
+ const localAbortController = new AbortController();
223
+ const combinedSignal = options?.signal
224
+ ? AbortSignal.any([localAbortController.signal, options.signal])
225
+ : localAbortController.signal;
226
+ if (!(workflow instanceof Workflow_js_1.WorkflowImpl)) {
227
+ throw new Error('workflow is not an instance of WorkflowImpl');
228
+ }
229
+ const compilerContext = {
230
+ compiler: this.compiler,
231
+ log: this.log,
232
+ tracer: this.tracer,
233
+ contextProvider: this.contextProvider,
234
+ webhookRouter: this.webhookRouter,
235
+ queueProvider: this.queueProvider,
236
+ cronRouter: this.cronRouter,
237
+ cronRegistry: this.cronRegistry,
238
+ configReader: this.cfgReader,
239
+ cnxFactory: this.cnxFetchFactory,
240
+ organisationId: Deno.env.get(constants_js_1.envVarOrgId) || 'development',
241
+ };
242
+ const trigger$ = this.compiler.compileTrigger(compilerContext, workflow.trigger, combinedSignal);
243
+ const task$ = this.compiler.compileTask(compilerContext, workflow.task);
244
+ const registration = {
245
+ trigger$,
246
+ task$,
247
+ localAbortController,
248
+ sigintListener: () => {
249
+ this.log.info('Received SIGINT, shutting down workflow');
250
+ localAbortController.abort();
251
+ },
252
+ };
253
+ this.registeredWorkflows.push(registration);
254
+ return registration;
255
+ }
256
+ start() {
257
+ const port = Deno.env.get('PORT') || 3000;
258
+ const cronPort = Deno.env.get('CRON_PORT') || 3001;
259
+ const webhookApp = (0, express_1.default)();
260
+ const cronApp = (0, express_1.default)();
261
+ cronApp.use(express_1.default.json());
262
+ this.webhookRouter.get('/health', (_req, res) => {
263
+ res.json({ status: 'healthy' });
264
+ });
265
+ this.cronRouter.get('/health', (_req, res) => {
266
+ res.json({ status: 'healthy' });
267
+ });
268
+ webhookApp.use(this.webhookRouter);
269
+ cronApp.use(this.cronRouter);
270
+ for (const registration of this.registeredWorkflows) {
271
+ Deno.addSignalListener('SIGINT', registration.sigintListener);
272
+ registration.subscription = registration.trigger$
273
+ .pipe((0, rxjs_1.tap)((ctx) => {
274
+ ctx.log.info('VanillaInterpreter.executionStarted', { data: ctx.data });
275
+ }), (0, rxjs_1.mergeMap)((ctx) => (0, rxjs_1.of)(ctx).pipe(registration.task$, (0, rxjs_1.catchError)((err) => {
276
+ ctx.log.error('VanillaInterpreter.executionError', {
277
+ error: err instanceof Error ? err.toString() : err,
278
+ });
279
+ try {
280
+ ctx.options.onError?.(ctx.withData(err));
281
+ }
282
+ catch (err) {
283
+ ctx.log.error('VanillaInterpreter.onErrorError: failed to call onError handler', { error: err instanceof Error ? err.toString() : err });
284
+ ctx.options.onError?.(ctx.withData({
285
+ message: 'Internal server error',
286
+ error: err instanceof Error ? err.toString() : err,
287
+ }));
288
+ }
289
+ return rxjs_1.EMPTY;
290
+ }))))
291
+ .subscribe({
292
+ next: async (ctx) => {
293
+ const durationMs = Date.now() - ctx.startTime.getTime();
294
+ ctx.log.info('VanillaInterpreter.executionCompleted', {
295
+ durationMs,
296
+ });
297
+ try {
298
+ ctx.options.onSuccess?.(ctx);
299
+ }
300
+ catch (err) {
301
+ ctx.log.error('VanillaInterpreter.onSuccessError: failed to call onSuccess handler', { error: err instanceof Error ? err.toString() : err });
302
+ ctx.options.onSuccess?.(ctx.withData({
303
+ message: 'Internal server error',
304
+ error: err instanceof Error ? err.toString() : err,
305
+ }));
306
+ }
307
+ if (ctx.workflowId) {
308
+ this.log.info('Async workflow completed', {
309
+ workflowId: ctx.workflowId,
310
+ });
311
+ const output = ctx.data ? btoa(JSON.stringify(ctx.data)) : undefined;
312
+ await ctx.queue?.complete({
313
+ id: ctx.workflowId,
314
+ output,
315
+ status: 'completed',
316
+ });
317
+ }
318
+ this.contextProvider.destroy(ctx);
319
+ },
320
+ error: (err) => {
321
+ this.log.error('VanillaInterpreter.error', {
322
+ error: err instanceof Error ? err.toString() : err,
323
+ });
324
+ Deno.removeSignalListener('SIGINT', registration.sigintListener);
325
+ },
326
+ complete: () => {
327
+ this.log.info('VanillaInterpreter.workflowCompleted');
328
+ Deno.removeSignalListener('SIGINT', registration.sigintListener);
329
+ },
330
+ });
331
+ registration.subscription.add(() => {
332
+ registration.subscription = undefined;
333
+ });
334
+ }
335
+ try {
336
+ this.cronProvider.updateCrons(this.cronRegistry);
337
+ }
338
+ catch (err) {
339
+ this.log.error('VanillaInterpreter.updateCronsError', {
340
+ error: err instanceof Error ? err.toString() : err,
341
+ });
342
+ throw new Error('Unable to register scheduler tasks with central cron provider');
343
+ }
344
+ this.webhookServer = webhookApp.listen(port, () => {
345
+ this.log.info(`Express server listening on port ${port}`);
346
+ });
347
+ this.cronServer = cronApp.listen(cronPort, () => {
348
+ this.log.info(`Cron server listening on port ${cronPort}`);
349
+ });
350
+ this.shutdownServer = () => {
351
+ if (this.isShuttingDown) {
352
+ return;
353
+ }
354
+ this.isShuttingDown = true;
355
+ this.log.info('Shutting down server');
356
+ if (this.webhookServer) {
357
+ this.webhookServer.close();
358
+ }
359
+ if (this.cronServer) {
360
+ this.cronServer.close();
361
+ }
362
+ for (const registration of this.registeredWorkflows) {
363
+ Deno.removeSignalListener('SIGINT', registration.sigintListener);
364
+ if (registration.subscription) {
365
+ registration.subscription.unsubscribe();
366
+ }
367
+ registration.localAbortController.abort();
368
+ }
369
+ if (this.shutdownServer) {
370
+ Deno.removeSignalListener('SIGINT', this.shutdownServer);
371
+ }
372
+ };
373
+ Deno.addSignalListener('SIGINT', this.shutdownServer);
374
+ return new Promise((resolve) => {
375
+ let serversClosed = 0;
376
+ const totalServers = [this.webhookServer, this.cronServer].filter(Boolean).length;
377
+ const checkResolve = () => {
378
+ serversClosed++;
379
+ if (serversClosed === totalServers) {
380
+ this.log.info('All servers closed');
381
+ resolve();
382
+ }
383
+ };
384
+ if (this.webhookServer) {
385
+ this.webhookServer.on('close', () => {
386
+ this.log.info('Webhook server closed');
387
+ checkResolve();
388
+ });
389
+ }
390
+ if (this.cronServer) {
391
+ this.cronServer.on('close', () => {
392
+ this.log.info('Cron server closed');
393
+ checkResolve();
394
+ });
395
+ }
396
+ if (!this.webhookServer && !this.cronServer) {
397
+ resolve();
398
+ }
399
+ });
400
+ }
401
+ stop() {
402
+ this.otelSDK?.shutdown();
403
+ if (this.shutdownServer) {
404
+ this.shutdownServer();
405
+ }
406
+ return Promise.resolve();
407
+ }
408
+ }
409
+ exports.VanillaInterpreter = VanillaInterpreter;
410
+ async function waitForReady(log) {
411
+ const readyCheckUrl = Deno.env.get('READY_CHECK_URL');
412
+ if (!readyCheckUrl) {
413
+ return Promise.resolve();
414
+ }
415
+ const maxAttempts = 40;
416
+ const delay = 500;
417
+ log.info('VanillaInterpreter.waitForReady: waiting for network to be ready', { readyCheckUrl });
418
+ for (let i = 0; i < maxAttempts; i++) {
419
+ try {
420
+ const response = await fetch(readyCheckUrl);
421
+ if (response.ok) {
422
+ log.info('VanillaInterpreter.waitForReady: network is ready');
423
+ return Promise.resolve();
424
+ }
425
+ }
426
+ catch (err) {
427
+ log.error('VanillaInterpreter.waitForReadyError', {
428
+ error: err instanceof Error ? err.toString() : err,
429
+ });
430
+ }
431
+ log.info('VanillaInterpreter.waitForReady: retrying...', { attempt: i });
432
+ await new Promise((resolve) => setTimeout(resolve, delay));
433
+ }
434
+ throw new Error(`Network is not ready after ${maxAttempts * (delay / 1000)} seconds`);
435
+ }
@@ -0,0 +1,4 @@
1
+ import { BackgroundTask } from '../../../dsl/tasks/BackgroundTask.js';
2
+ import { TaskCompiler } from './types.js';
3
+ export declare const backgroundCompiler: TaskCompiler<any, any, BackgroundTask<any, any>>;
4
+ //# sourceMappingURL=background.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"background.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/vanilla/compilers/background.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAEtE,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AA2CnE,eAAO,MAAM,kBAAkB,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAG/E,CAAC"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Versori Group Inc
4
+ *
5
+ * Use of this software is governed by the Business Source License 1.1
6
+ * included in the LICENSE file at the root of this repository.
7
+ *
8
+ * Change Date: 2029-01-01
9
+ * Change License: Apache License, Version 2.0
10
+ *
11
+ * As of the Change Date, in accordance with the Business Source License,
12
+ * use of this software will be governed by the Apache License, Version 2.0.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.backgroundCompiler = void 0;
16
+ const rxjs_1 = require("rxjs");
17
+ const BackgroundTask_js_1 = require("../../../dsl/tasks/BackgroundTask.js");
18
+ function compileBackground(ctx, task) {
19
+ const base = ctx.compiler.compileTask(ctx, task._base);
20
+ return (src) => src.pipe((0, rxjs_1.connect)((shared$) => (0, rxjs_1.merge)(shared$.pipe((0, rxjs_1.mergeMap)((ctx) => base((0, rxjs_1.of)(ctx)).pipe((0, rxjs_1.subscribeOn)(rxjs_1.asyncScheduler), (0, rxjs_1.tap)({
21
+ next: (ctx) => ctx.log.debug('Background task emitted a value', {
22
+ data: ctx.data,
23
+ }),
24
+ complete: () => ctx.log.debug('Background task completed'),
25
+ }), (0, rxjs_1.catchError)((error) => {
26
+ ctx.log.error('Error in background task', {
27
+ error,
28
+ inputData: ctx.data,
29
+ executionId: ctx.executionId,
30
+ });
31
+ return rxjs_1.EMPTY;
32
+ }), (0, rxjs_1.ignoreElements)()))), shared$.pipe((0, rxjs_1.map)((ctx) => ctx.withData(void 0))))));
33
+ }
34
+ exports.backgroundCompiler = {
35
+ ctor: BackgroundTask_js_1.BackgroundTask,
36
+ compile: compileBackground,
37
+ };
@@ -0,0 +1,4 @@
1
+ import { CatchTask } from '../../../dsl/tasks/CatchTask.js';
2
+ import { TaskCompiler } from './types.js';
3
+ export declare const catchCompiler: TaskCompiler<any, any, CatchTask<any, any>>;
4
+ //# sourceMappingURL=catch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catch.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/vanilla/compilers/catch.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAG5D,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAwFnE,eAAO,MAAM,aAAa,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAGrE,CAAC"}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Versori Group Inc
4
+ *
5
+ * Use of this software is governed by the Business Source License 1.1
6
+ * included in the LICENSE file at the root of this repository.
7
+ *
8
+ * Change Date: 2029-01-01
9
+ * Change License: Apache License, Version 2.0
10
+ *
11
+ * As of the Change Date, in accordance with the Business Source License,
12
+ * use of this software will be governed by the Apache License, Version 2.0.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.catchCompiler = void 0;
16
+ const rxjs_1 = require("rxjs");
17
+ const CatchTask_js_1 = require("../../../dsl/tasks/CatchTask.js");
18
+ const ExecutionError_js_1 = require("../ExecutionError.js");
19
+ function compileCatch(compilerCtx, task) {
20
+ const baseOperator = compilerCtx.compiler.compileTask(compilerCtx, task._base);
21
+ const errorOperator = compilerCtx.compiler.compileTask(compilerCtx, task._errorHandler);
22
+ return (src) => {
23
+ return src.pipe((0, rxjs_1.mergeMap)((ctx) => {
24
+ return baseOperator((0, rxjs_1.of)(ctx)).pipe((0, rxjs_1.catchError)((error) => {
25
+ return compilerCtx.tracer.startActiveSpan(`catch`, (span) => {
26
+ span.setAttribute('execution.id', ctx.executionId);
27
+ span.setAttribute('task.type', 'catch');
28
+ if (error instanceof Error) {
29
+ span.recordException(error);
30
+ span.setAttribute('error.message', error.message);
31
+ span.setAttribute('error.stack', error.stack ?? '');
32
+ span.end();
33
+ ctx.log.error('execution has encountered an error', {
34
+ error: error.message,
35
+ stack: error.stack,
36
+ });
37
+ // TODO: Do we want to submit issues for the VanillaInterpreter or not?
38
+ // compilerCtx.issueProvider.submitIssue({
39
+ // annotations: {
40
+ // 'error': error.message,
41
+ // 'stack': error.stack || '',
42
+ // 'workflowId': ctx.options.workflowId || ctx.workflowId || '',
43
+ // 'executionId': ctx.executionId,
44
+ // 'activationId': ctx.activation.id,
45
+ // 'activationExternalId': ctx.activation?.user.externalId,
46
+ // },
47
+ // reason: 'error',
48
+ // severity: 'high',
49
+ // });
50
+ return errorOperator((0, rxjs_1.of)(ctx.withData(new ExecutionError_js_1.ExecutionError(ctx, error.message, { cause: error }))));
51
+ }
52
+ ctx.log.error('execution has encountered an error', {
53
+ error: error,
54
+ });
55
+ // compilerCtx.issueProvider.submitIssue({
56
+ // annotations: {
57
+ // 'error': error.message,
58
+ // 'stack': error.stack || '',
59
+ // 'workflowId': ctx.options.workflowId || ctx.workflowId || '',
60
+ // 'executionId': ctx.executionId,
61
+ // 'activationId': ctx.activation.id,
62
+ // 'activationExternalId': ctx.activation?.user.externalId,
63
+ // },
64
+ // reason: 'error',
65
+ // severity: 'low',
66
+ // });
67
+ span.setAttribute('error', `${error}`);
68
+ span.end();
69
+ return errorOperator((0, rxjs_1.of)(ctx.withData(new ExecutionError_js_1.ExecutionError(ctx, `${error}`, { cause: error }))));
70
+ });
71
+ }));
72
+ }));
73
+ };
74
+ }
75
+ exports.catchCompiler = {
76
+ ctor: CatchTask_js_1.CatchTask,
77
+ compile: compileCatch,
78
+ };
@@ -0,0 +1,3 @@
1
+ import { TaskCompiler } from './types.js';
2
+ export declare const chainCompiler: TaskCompiler<any, any, any>;
3
+ //# sourceMappingURL=chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/vanilla/compilers/chain.ts"],"names":[],"mappings":"AAgBA,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAanE,eAAO,MAAM,aAAa,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAGrD,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Versori Group Inc
4
+ *
5
+ * Use of this software is governed by the Business Source License 1.1
6
+ * included in the LICENSE file at the root of this repository.
7
+ *
8
+ * Change Date: 2029-01-01
9
+ * Change License: Apache License, Version 2.0
10
+ *
11
+ * As of the Change Date, in accordance with the Business Source License,
12
+ * use of this software will be governed by the Apache License, Version 2.0.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.chainCompiler = void 0;
16
+ const ChainTask_js_1 = require("../../../dsl/tasks/ChainTask.js");
17
+ function compileChain(ctx, task) {
18
+ const operators = task.tasks.map((t) => ctx.compiler.compileTask(ctx, t));
19
+ return (src) => operators.reduce((acc, curr) => curr(acc), src);
20
+ }
21
+ exports.chainCompiler = {
22
+ ctor: ChainTask_js_1.ChainTask,
23
+ compile: compileChain,
24
+ };
@@ -0,0 +1,8 @@
1
+ import { Observable } from 'rxjs';
2
+ import { DurableWorkflowData, DurableWorkflowTrigger } from '../../../dsl/triggers/DurableTrigger.js';
3
+ import { VanillaCompilerContext } from '../ObservableCompiler.js';
4
+ import { TriggerCompiler } from './mod.js';
5
+ import { VanillaContext } from '../../../context/VanillaContext.js';
6
+ export declare function compileDurableWorkflow(ctx: VanillaCompilerContext, trigger: DurableWorkflowTrigger, signal: AbortSignal): Observable<VanillaContext<DurableWorkflowData>>;
7
+ export declare const durableWorkflowCompiler: TriggerCompiler<DurableWorkflowData, DurableWorkflowTrigger>;
8
+ //# sourceMappingURL=durableworkflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"durableworkflow.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/vanilla/compilers/durableworkflow.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EACH,mBAAmB,EACnB,sBAAsB,EACzB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAqB,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,wBAAgB,sBAAsB,CAClC,GAAG,EAAE,sBAAsB,EAC3B,OAAO,EAAE,sBAAsB,EAC/B,MAAM,EAAE,WAAW,GACpB,UAAU,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC,CAqFjD;AAED,eAAO,MAAM,uBAAuB,EAAE,eAAe,CAAC,mBAAmB,EAAE,sBAAsB,CAI5F,CAAC"}