@versori/run 0.2.14 → 0.2.16

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 (157) hide show
  1. package/esm/src/context/AsyncWorkflow.d.ts +14 -0
  2. package/esm/src/context/AsyncWorkflow.d.ts.map +1 -0
  3. package/esm/src/context/AsyncWorkflow.js +89 -0
  4. package/esm/src/context/Context.d.ts +13 -1
  5. package/esm/src/context/Context.d.ts.map +1 -1
  6. package/esm/src/context/Context.js +44 -4
  7. package/esm/src/context/ContextProvider.d.ts +3 -1
  8. package/esm/src/context/ContextProvider.d.ts.map +1 -1
  9. package/esm/src/context/ContextProvider.js +9 -2
  10. package/esm/src/dsl/http/versori/constants.d.ts +1 -0
  11. package/esm/src/dsl/http/versori/constants.d.ts.map +1 -1
  12. package/esm/src/dsl/http/versori/constants.js +1 -0
  13. package/esm/src/dsl/tasks/HttpTask.d.ts +3 -0
  14. package/esm/src/dsl/tasks/HttpTask.d.ts.map +1 -1
  15. package/esm/src/dsl/tasks/HttpTask.js +3 -0
  16. package/esm/src/dsl/triggers/DurableTrigger.d.ts +18 -0
  17. package/esm/src/dsl/triggers/DurableTrigger.d.ts.map +1 -0
  18. package/esm/src/dsl/triggers/DurableTrigger.js +36 -0
  19. package/esm/src/dsl/triggers/mod.d.ts +1 -0
  20. package/esm/src/dsl/triggers/mod.d.ts.map +1 -1
  21. package/esm/src/dsl/triggers/mod.js +1 -0
  22. package/esm/src/interpreter/durable/DurableInterpreter.d.ts +52 -0
  23. package/esm/src/interpreter/durable/DurableInterpreter.d.ts.map +1 -0
  24. package/esm/src/interpreter/durable/DurableInterpreter.js +433 -0
  25. package/esm/src/interpreter/durable/ExecutionError.d.ts +6 -0
  26. package/esm/src/interpreter/durable/ExecutionError.d.ts.map +1 -0
  27. package/esm/src/interpreter/durable/ExecutionError.js +13 -0
  28. package/esm/src/interpreter/durable/ObservableCompiler.d.ts +35 -0
  29. package/esm/src/interpreter/durable/ObservableCompiler.d.ts.map +1 -0
  30. package/esm/src/interpreter/durable/ObservableCompiler.js +69 -0
  31. package/esm/src/interpreter/durable/Queue.d.ts +69 -0
  32. package/esm/src/interpreter/durable/Queue.d.ts.map +1 -0
  33. package/esm/src/interpreter/durable/Queue.js +149 -0
  34. package/esm/src/interpreter/durable/compilers/background.d.ts +4 -0
  35. package/esm/src/interpreter/durable/compilers/background.d.ts.map +1 -0
  36. package/esm/src/interpreter/durable/compilers/background.js +22 -0
  37. package/esm/src/interpreter/durable/compilers/catch.d.ts +4 -0
  38. package/esm/src/interpreter/durable/compilers/catch.d.ts.map +1 -0
  39. package/esm/src/interpreter/durable/compilers/catch.js +36 -0
  40. package/esm/src/interpreter/durable/compilers/chain.d.ts +3 -0
  41. package/esm/src/interpreter/durable/compilers/chain.d.ts.map +1 -0
  42. package/esm/src/interpreter/durable/compilers/chain.js +9 -0
  43. package/esm/src/interpreter/durable/compilers/durableworkflow.d.ts +8 -0
  44. package/esm/src/interpreter/durable/compilers/durableworkflow.d.ts.map +1 -0
  45. package/esm/src/interpreter/durable/compilers/durableworkflow.js +69 -0
  46. package/esm/src/interpreter/durable/compilers/fn.d.ts +4 -0
  47. package/esm/src/interpreter/durable/compilers/fn.d.ts.map +1 -0
  48. package/esm/src/interpreter/durable/compilers/fn.js +22 -0
  49. package/esm/src/interpreter/durable/compilers/http.d.ts +4 -0
  50. package/esm/src/interpreter/durable/compilers/http.d.ts.map +1 -0
  51. package/esm/src/interpreter/durable/compilers/http.js +44 -0
  52. package/esm/src/interpreter/durable/compilers/mod.d.ts +2 -0
  53. package/esm/src/interpreter/durable/compilers/mod.d.ts.map +1 -0
  54. package/esm/src/interpreter/durable/compilers/mod.js +1 -0
  55. package/esm/src/interpreter/durable/compilers/parallel.d.ts +4 -0
  56. package/esm/src/interpreter/durable/compilers/parallel.d.ts.map +1 -0
  57. package/esm/src/interpreter/durable/compilers/parallel.js +19 -0
  58. package/esm/src/interpreter/durable/compilers/schedule.d.ts +4 -0
  59. package/esm/src/interpreter/durable/compilers/schedule.d.ts.map +1 -0
  60. package/esm/src/interpreter/durable/compilers/schedule.js +94 -0
  61. package/esm/src/interpreter/durable/compilers/serial.d.ts +4 -0
  62. package/esm/src/interpreter/durable/compilers/serial.d.ts.map +1 -0
  63. package/esm/src/interpreter/durable/compilers/serial.js +16 -0
  64. package/esm/src/interpreter/durable/compilers/types.d.ts +15 -0
  65. package/esm/src/interpreter/durable/compilers/types.d.ts.map +1 -0
  66. package/esm/src/interpreter/durable/compilers/types.js +1 -0
  67. package/esm/src/interpreter/durable/compilers/unpack.d.ts +4 -0
  68. package/esm/src/interpreter/durable/compilers/unpack.d.ts.map +1 -0
  69. package/esm/src/interpreter/durable/compilers/unpack.js +22 -0
  70. package/esm/src/interpreter/durable/compilers/webhook.d.ts +4 -0
  71. package/esm/src/interpreter/durable/compilers/webhook.d.ts.map +1 -0
  72. package/esm/src/interpreter/durable/compilers/webhook.js +248 -0
  73. package/esm/src/interpreter/durable/mod.d.ts +5 -0
  74. package/esm/src/interpreter/durable/mod.d.ts.map +1 -0
  75. package/esm/src/interpreter/durable/mod.js +4 -0
  76. package/esm/src/interpreter/mod.d.ts +1 -0
  77. package/esm/src/interpreter/mod.d.ts.map +1 -1
  78. package/esm/src/interpreter/mod.js +1 -0
  79. package/package.json +1 -1
  80. package/script/src/context/AsyncWorkflow.d.ts +14 -0
  81. package/script/src/context/AsyncWorkflow.d.ts.map +1 -0
  82. package/script/src/context/AsyncWorkflow.js +93 -0
  83. package/script/src/context/Context.d.ts +13 -1
  84. package/script/src/context/Context.d.ts.map +1 -1
  85. package/script/src/context/Context.js +44 -4
  86. package/script/src/context/ContextProvider.d.ts +3 -1
  87. package/script/src/context/ContextProvider.d.ts.map +1 -1
  88. package/script/src/context/ContextProvider.js +9 -2
  89. package/script/src/dsl/http/versori/constants.d.ts +1 -0
  90. package/script/src/dsl/http/versori/constants.d.ts.map +1 -1
  91. package/script/src/dsl/http/versori/constants.js +2 -1
  92. package/script/src/dsl/tasks/HttpTask.d.ts +3 -0
  93. package/script/src/dsl/tasks/HttpTask.d.ts.map +1 -1
  94. package/script/src/dsl/tasks/HttpTask.js +3 -0
  95. package/script/src/dsl/triggers/DurableTrigger.d.ts +18 -0
  96. package/script/src/dsl/triggers/DurableTrigger.d.ts.map +1 -0
  97. package/script/src/dsl/triggers/DurableTrigger.js +41 -0
  98. package/script/src/dsl/triggers/mod.d.ts +1 -0
  99. package/script/src/dsl/triggers/mod.d.ts.map +1 -1
  100. package/script/src/dsl/triggers/mod.js +3 -1
  101. package/script/src/interpreter/durable/DurableInterpreter.d.ts +52 -0
  102. package/script/src/interpreter/durable/DurableInterpreter.d.ts.map +1 -0
  103. package/script/src/interpreter/durable/DurableInterpreter.js +440 -0
  104. package/script/src/interpreter/durable/ExecutionError.d.ts +6 -0
  105. package/script/src/interpreter/durable/ExecutionError.d.ts.map +1 -0
  106. package/script/src/interpreter/durable/ExecutionError.js +17 -0
  107. package/script/src/interpreter/durable/ObservableCompiler.d.ts +35 -0
  108. package/script/src/interpreter/durable/ObservableCompiler.d.ts.map +1 -0
  109. package/script/src/interpreter/durable/ObservableCompiler.js +73 -0
  110. package/script/src/interpreter/durable/Queue.d.ts +69 -0
  111. package/script/src/interpreter/durable/Queue.d.ts.map +1 -0
  112. package/script/src/interpreter/durable/Queue.js +154 -0
  113. package/script/src/interpreter/durable/compilers/background.d.ts +4 -0
  114. package/script/src/interpreter/durable/compilers/background.d.ts.map +1 -0
  115. package/script/src/interpreter/durable/compilers/background.js +25 -0
  116. package/script/src/interpreter/durable/compilers/catch.d.ts +4 -0
  117. package/script/src/interpreter/durable/compilers/catch.d.ts.map +1 -0
  118. package/script/src/interpreter/durable/compilers/catch.js +39 -0
  119. package/script/src/interpreter/durable/compilers/chain.d.ts +3 -0
  120. package/script/src/interpreter/durable/compilers/chain.d.ts.map +1 -0
  121. package/script/src/interpreter/durable/compilers/chain.js +12 -0
  122. package/script/src/interpreter/durable/compilers/durableworkflow.d.ts +8 -0
  123. package/script/src/interpreter/durable/compilers/durableworkflow.d.ts.map +1 -0
  124. package/script/src/interpreter/durable/compilers/durableworkflow.js +73 -0
  125. package/script/src/interpreter/durable/compilers/fn.d.ts +4 -0
  126. package/script/src/interpreter/durable/compilers/fn.d.ts.map +1 -0
  127. package/script/src/interpreter/durable/compilers/fn.js +25 -0
  128. package/script/src/interpreter/durable/compilers/http.d.ts +4 -0
  129. package/script/src/interpreter/durable/compilers/http.d.ts.map +1 -0
  130. package/script/src/interpreter/durable/compilers/http.js +47 -0
  131. package/script/src/interpreter/durable/compilers/mod.d.ts +2 -0
  132. package/script/src/interpreter/durable/compilers/mod.d.ts.map +1 -0
  133. package/script/src/interpreter/durable/compilers/mod.js +2 -0
  134. package/script/src/interpreter/durable/compilers/parallel.d.ts +4 -0
  135. package/script/src/interpreter/durable/compilers/parallel.d.ts.map +1 -0
  136. package/script/src/interpreter/durable/compilers/parallel.js +22 -0
  137. package/script/src/interpreter/durable/compilers/schedule.d.ts +4 -0
  138. package/script/src/interpreter/durable/compilers/schedule.d.ts.map +1 -0
  139. package/script/src/interpreter/durable/compilers/schedule.js +97 -0
  140. package/script/src/interpreter/durable/compilers/serial.d.ts +4 -0
  141. package/script/src/interpreter/durable/compilers/serial.d.ts.map +1 -0
  142. package/script/src/interpreter/durable/compilers/serial.js +19 -0
  143. package/script/src/interpreter/durable/compilers/types.d.ts +15 -0
  144. package/script/src/interpreter/durable/compilers/types.d.ts.map +1 -0
  145. package/script/src/interpreter/durable/compilers/types.js +2 -0
  146. package/script/src/interpreter/durable/compilers/unpack.d.ts +4 -0
  147. package/script/src/interpreter/durable/compilers/unpack.d.ts.map +1 -0
  148. package/script/src/interpreter/durable/compilers/unpack.js +25 -0
  149. package/script/src/interpreter/durable/compilers/webhook.d.ts +4 -0
  150. package/script/src/interpreter/durable/compilers/webhook.d.ts.map +1 -0
  151. package/script/src/interpreter/durable/compilers/webhook.js +254 -0
  152. package/script/src/interpreter/durable/mod.d.ts +5 -0
  153. package/script/src/interpreter/durable/mod.d.ts.map +1 -0
  154. package/script/src/interpreter/durable/mod.js +20 -0
  155. package/script/src/interpreter/mod.d.ts +1 -0
  156. package/script/src/interpreter/mod.d.ts.map +1 -1
  157. package/script/src/interpreter/mod.js +14 -0
@@ -0,0 +1,149 @@
1
+ import { ConsoleLogger } from '../../mod.js';
2
+ import { envVarWorkflowApiBaseURL, envVarProjectId } from '../../dsl/http/versori/constants.js';
3
+ export class QueueImpl {
4
+ constructor(baseUrl, projectId, log) {
5
+ Object.defineProperty(this, "baseUrl", {
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true,
9
+ value: void 0
10
+ });
11
+ Object.defineProperty(this, "log", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: void 0
16
+ });
17
+ Object.defineProperty(this, "projectId", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: void 0
22
+ });
23
+ this.baseUrl = baseUrl;
24
+ this.log = log;
25
+ this.projectId = projectId;
26
+ }
27
+ static fromEnv(log) {
28
+ // TODO make these environment variables configurable in constants/ts
29
+ const baseUrl = Deno.env.get(envVarWorkflowApiBaseURL);
30
+ const _log = log || new ConsoleLogger('debug');
31
+ const projectId = Deno.env.get(envVarProjectId) || 'default-project';
32
+ if (!baseUrl) {
33
+ throw new Error('Missing required environment variables');
34
+ }
35
+ return new QueueImpl(baseUrl, projectId, _log);
36
+ }
37
+ async complete(request) {
38
+ const resp = await fetch(`${this.baseUrl}/v1/workflows/complete`, {
39
+ method: 'POST',
40
+ body: JSON.stringify({
41
+ id: request.id,
42
+ output: request.output,
43
+ status: request.status,
44
+ }),
45
+ });
46
+ if (!resp.ok) {
47
+ this.log.error('Failed to complete workflow', {
48
+ id: request.id,
49
+ output: request.output,
50
+ status: request.status,
51
+ });
52
+ throw new Error('Failed to complete workflow');
53
+ }
54
+ return;
55
+ }
56
+ async submit(request) {
57
+ // Ensure all workflows have the projectId set
58
+ const workflows = request.workflows.map((w) => ({
59
+ ...w,
60
+ projectId: this.projectId || w.projectId,
61
+ }));
62
+ const resp = await fetch(`${this.baseUrl}/v1/workflows/submit`, {
63
+ method: 'POST',
64
+ body: JSON.stringify({
65
+ workflows: workflows,
66
+ }),
67
+ });
68
+ if (!resp.ok) {
69
+ this.log.error('Failed to submit workflows', {
70
+ workflows: workflows,
71
+ });
72
+ throw new Error('Failed to submit workflows');
73
+ }
74
+ const result = (await resp.json());
75
+ return result;
76
+ }
77
+ async fetchWorkflows(request) {
78
+ const resp = await fetch(`${this.baseUrl}/v1/workflows/fetch`, {
79
+ method: 'POST',
80
+ body: JSON.stringify({
81
+ ttl: request.ttl,
82
+ limit: request.limit,
83
+ group: request.group,
84
+ projectId: this.projectId || request.projectId,
85
+ }),
86
+ });
87
+ if (!resp.ok) {
88
+ this.log.error('Failed to fetch workflows', {
89
+ ttl: request.ttl,
90
+ limit: request.limit,
91
+ group: request.group,
92
+ projectId: this.projectId || request.projectId,
93
+ });
94
+ throw new Error('Failed to fetch workflows');
95
+ }
96
+ if (resp.status === 204) {
97
+ return undefined;
98
+ }
99
+ const result = (await resp.json());
100
+ return result;
101
+ }
102
+ async reschedule(request) {
103
+ const resp = await fetch(`${this.baseUrl}/v1/workflows/reschedule`, {
104
+ method: 'POST',
105
+ body: JSON.stringify({
106
+ id: request.id,
107
+ after: request.after,
108
+ }),
109
+ });
110
+ if (!resp.ok) {
111
+ this.log.error('Failed to reschedule workflow', {
112
+ id: request.id,
113
+ after: request.after,
114
+ });
115
+ throw new Error('Failed to reschedule workflow');
116
+ }
117
+ return;
118
+ }
119
+ async poll(workflowId) {
120
+ // this endpoint returns a 404 if the workflow is not completed
121
+ const resp = await fetch(`${this.baseUrl}/v1/workflows/fetch/${workflowId}`, {
122
+ method: 'GET',
123
+ });
124
+ if (!resp.ok) {
125
+ this.log.error('Failed to poll workflow', { workflowId });
126
+ throw new Error('Failed to poll workflow');
127
+ }
128
+ const result = (await resp.json());
129
+ return result;
130
+ }
131
+ }
132
+ export class MockQueue {
133
+ constructor() { }
134
+ complete(request) {
135
+ throw new Error('Method not implemented.');
136
+ }
137
+ submit(request) {
138
+ throw new Error('Method not implemented.');
139
+ }
140
+ fetchWorkflows(request) {
141
+ throw new Error('Method not implemented.');
142
+ }
143
+ reschedule(request) {
144
+ throw new Error('Method not implemented.');
145
+ }
146
+ poll(workflowId) {
147
+ throw new Error('Method not implemented.');
148
+ }
149
+ }
@@ -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/durable/compilers/background.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAEtE,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AA0CnE,eAAO,MAAM,kBAAkB,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAG/E,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { asyncScheduler, catchError, connect, EMPTY, ignoreElements, map, merge, mergeMap, of, subscribeOn, tap, } from 'rxjs';
2
+ import { BackgroundTask } from '../../../dsl/tasks/BackgroundTask.js';
3
+ function compileBackground(ctx, task) {
4
+ const base = ctx.compiler.compileTask(ctx, task._base);
5
+ return (src) => src.pipe(connect((shared$) => merge(shared$.pipe(mergeMap((ctx) => base(of(ctx)).pipe(subscribeOn(asyncScheduler), tap({
6
+ next: (ctx) => ctx.log.debug('Background task emitted a value', {
7
+ data: ctx.data,
8
+ }),
9
+ complete: () => ctx.log.debug('Background task completed'),
10
+ }), catchError((error) => {
11
+ ctx.log.error('Error in background task', {
12
+ error,
13
+ inputData: ctx.data,
14
+ executionId: ctx.executionId,
15
+ });
16
+ return EMPTY;
17
+ }), ignoreElements()))), shared$.pipe(map((ctx) => ctx.withData(void 0))))));
18
+ }
19
+ export const backgroundCompiler = {
20
+ ctor: BackgroundTask,
21
+ compile: compileBackground,
22
+ };
@@ -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/durable/compilers/catch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAG5D,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAmDnE,eAAO,MAAM,aAAa,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAGrE,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { catchError, mergeMap, of } from 'rxjs';
2
+ import { CatchTask } from '../../../dsl/tasks/CatchTask.js';
3
+ import { ExecutionError } from '../ExecutionError.js';
4
+ function compileCatch(compilerCtx, task) {
5
+ const baseOperator = compilerCtx.compiler.compileTask(compilerCtx, task._base);
6
+ const errorOperator = compilerCtx.compiler.compileTask(compilerCtx, task._errorHandler);
7
+ return (src) => src.pipe(mergeMap((ctx) => {
8
+ return baseOperator(of(ctx)).pipe(catchError((error) => {
9
+ return compilerCtx.tracer.startActiveSpan(`catch`, (span) => {
10
+ span.setAttribute('execution.id', ctx.executionId);
11
+ span.setAttribute('task.type', 'catch');
12
+ if (error instanceof Error) {
13
+ span.recordException(error);
14
+ span.setAttribute('error.message', error.message);
15
+ span.setAttribute('error.stack', error.stack ?? '');
16
+ span.end();
17
+ ctx.log.error('execution has encountered an error', {
18
+ error: error.message,
19
+ stack: error.stack,
20
+ });
21
+ return errorOperator(of(ctx.withData(new ExecutionError(ctx, error.message, { cause: error }))));
22
+ }
23
+ ctx.log.error('execution has encountered an error', {
24
+ error: error,
25
+ });
26
+ span.setAttribute('error', `${error}`);
27
+ span.end();
28
+ return errorOperator(of(ctx.withData(new ExecutionError(ctx, `${error}`, { cause: error }))));
29
+ });
30
+ }));
31
+ }));
32
+ }
33
+ export const catchCompiler = {
34
+ ctor: CatchTask,
35
+ compile: compileCatch,
36
+ };
@@ -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/durable/compilers/chain.ts"],"names":[],"mappings":"AAIA,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAYnE,eAAO,MAAM,aAAa,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAGrD,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { ChainTask } from '../../../dsl/tasks/ChainTask.js';
2
+ function compileChain(ctx, task) {
3
+ const operators = task.tasks.map((t) => ctx.compiler.compileTask(ctx, t));
4
+ return (src) => operators.reduce((acc, curr) => curr(acc), src);
5
+ }
6
+ export const chainCompiler = {
7
+ ctor: ChainTask,
8
+ compile: compileChain,
9
+ };
@@ -0,0 +1,8 @@
1
+ import { Observable } from 'rxjs';
2
+ import { DurableCompilerContext } from '../mod.js';
3
+ import { ContextImpl } from '../../../mod.js';
4
+ import { DurableWorkflowData, DurableWorkflowTrigger } from '../../../dsl/triggers/DurableTrigger.js';
5
+ import { TriggerCompiler } from './mod.js';
6
+ export declare function compileDurableWorkflow(ctx: DurableCompilerContext, trigger: DurableWorkflowTrigger, signal: AbortSignal): Observable<ContextImpl<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/durable/compilers/durableworkflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EACH,mBAAmB,EACnB,sBAAsB,EACzB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAG3C,wBAAgB,sBAAsB,CAClC,GAAG,EAAE,sBAAsB,EAC3B,OAAO,EAAE,sBAAsB,EAC/B,MAAM,EAAE,WAAW,GACpB,UAAU,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC,CA8E9C;AAED,eAAO,MAAM,uBAAuB,EAAE,eAAe,CAAC,mBAAmB,EAAE,sBAAsB,CAI5F,CAAC"}
@@ -0,0 +1,69 @@
1
+ import { Observable } from 'rxjs';
2
+ import { DurableWorkflowTrigger, } from '../../../dsl/triggers/DurableTrigger.js';
3
+ export function compileDurableWorkflow(ctx, trigger, signal) {
4
+ return new Observable((subscriber) => {
5
+ function cleanup() {
6
+ ctx.log.debug('webhook trigger stopped');
7
+ subscriber.complete();
8
+ }
9
+ signal.addEventListener('abort', cleanup, { once: true });
10
+ (async () => {
11
+ while (true) {
12
+ if (signal.aborted) {
13
+ cleanup();
14
+ break;
15
+ }
16
+ try {
17
+ // Right now the API itself will hang for a period of time if no workflows are available.
18
+ // so we don't need to add a delay here.
19
+ const wfs = await ctx.queueProvider.fetchWorkflows({
20
+ group: trigger.id,
21
+ ttl: trigger.options.ttl,
22
+ limit: trigger.options.limit,
23
+ });
24
+ if (!wfs) {
25
+ continue; // No workflows found, continue polling
26
+ }
27
+ for (const wf of wfs.workflows) {
28
+ if (wf.id && // this is for type safety
29
+ wf.attempt !== undefined &&
30
+ trigger.options.maxAttempts &&
31
+ wf.attempt > trigger.options.maxAttempts) {
32
+ ctx.log.error('Workflow exceeded max attempts failing', {
33
+ workflowId: wf.id,
34
+ attempts: wf.attempt,
35
+ });
36
+ await ctx.queueProvider.complete({
37
+ id: wf.id,
38
+ output: wf.output,
39
+ status: 'failed',
40
+ });
41
+ continue;
42
+ }
43
+ const data = JSON.parse(atob(wf.payload ?? '{}'));
44
+ let activation;
45
+ if (wf.metadata?.activationId) {
46
+ activation = await ctx.connectionProvider.getActivation(wf.metadata.activationId);
47
+ }
48
+ const newContext = ctx.contextProvider.create(data, {
49
+ activation: activation,
50
+ workflowId: wf.id,
51
+ });
52
+ subscriber.next(newContext);
53
+ }
54
+ }
55
+ catch (error) {
56
+ ctx.log.error('Error fetching workflows', { error });
57
+ }
58
+ }
59
+ })();
60
+ return () => {
61
+ signal.removeEventListener('abort', cleanup);
62
+ ctx.log.debug('durable workflow cleanup');
63
+ };
64
+ });
65
+ }
66
+ export const durableWorkflowCompiler = {
67
+ ctor: DurableWorkflowTrigger,
68
+ compile: compileDurableWorkflow,
69
+ };
@@ -0,0 +1,4 @@
1
+ import { FnTask } from '../../../dsl/tasks/FnTask.js';
2
+ import { TaskCompiler } from './types.js';
3
+ export declare const fnCompiler: TaskCompiler<any, any, FnTask<any, any>>;
4
+ //# sourceMappingURL=fn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fn.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/fn.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEtD,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AA4BnE,eAAO,MAAM,UAAU,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAG/D,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { mergeMap, tap } from 'rxjs';
2
+ import { FnTask } from '../../../dsl/tasks/FnTask.js';
3
+ function compileFn(compilerCtx, task) {
4
+ return (src) => src.pipe(tap({
5
+ complete: () => compilerCtx.log.debug('fn.complete')
6
+ }), mergeMap(async (ctx) => {
7
+ return await compilerCtx.tracer.startActiveSpan(`fn-${task.id}`, async (span) => {
8
+ span.setAttribute('task.id', task.id);
9
+ span.setAttribute('execution.id', ctx.executionId);
10
+ if (typeof ctx.idx === 'number') {
11
+ span.end();
12
+ return ctx.withData(await task._fn(ctx, ctx.idx));
13
+ }
14
+ span.end();
15
+ return ctx.withData(await task._fn(ctx));
16
+ });
17
+ }));
18
+ }
19
+ export const fnCompiler = {
20
+ ctor: FnTask,
21
+ compile: compileFn,
22
+ };
@@ -0,0 +1,4 @@
1
+ import { HttpTaskImpl } from '../../../dsl/tasks/HttpTask.js';
2
+ import { TaskCompiler } from './types.js';
3
+ export declare const httpCompiler: TaskCompiler<any, any, HttpTaskImpl<any, any, any>>;
4
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/http.ts"],"names":[],"mappings":"AAIA,OAAO,EAAmB,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAE/E,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAyDnE,eAAO,MAAM,YAAY,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAG5E,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { mergeMap } from 'rxjs';
2
+ import { tap } from 'rxjs/operators';
3
+ import { HttpContextImpl, HttpTaskImpl } from '../../../dsl/tasks/HttpTask.js';
4
+ function compileHttp(compilerCtx, task) {
5
+ const roundtripper = compilerCtx.roundTripperFactory.create(task.opts.connection);
6
+ const dynamicFetcher = compilerCtx.roundTripperFactory.createDynamic(task.opts.connection);
7
+ async function http(ctx) {
8
+ const _fetch = await roundtripper;
9
+ const _dynamicFetcher = await dynamicFetcher;
10
+ const httpContext = new HttpContextImpl(ctx, {}, _fetch, _dynamicFetcher);
11
+ const result = await task.fn(httpContext);
12
+ return ctx.withData(result);
13
+ }
14
+ return (src) => src.pipe(tap({
15
+ complete: () => compilerCtx.log.debug('http.complete'),
16
+ }), mergeMap(async (ctx) => {
17
+ return compilerCtx.tracer.startActiveSpan(`http-${task.id}`, async (span) => {
18
+ span.setAttribute('task.id', task.id);
19
+ span.setAttribute('task.type', 'http');
20
+ span.setAttribute('execution.id', ctx.executionId);
21
+ span.setAttribute('connection.name', task.opts.connection);
22
+ try {
23
+ let result = await http(ctx);
24
+ return result;
25
+ }
26
+ catch (error) {
27
+ if (error instanceof Error) {
28
+ span.recordException(error);
29
+ }
30
+ else {
31
+ span.recordException(new Error(String(error)));
32
+ }
33
+ throw error;
34
+ }
35
+ finally {
36
+ span.end();
37
+ }
38
+ });
39
+ }));
40
+ }
41
+ export const httpCompiler = {
42
+ ctor: HttpTaskImpl,
43
+ compile: compileHttp,
44
+ };
@@ -0,0 +1,2 @@
1
+ export type * from './types.js';
2
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/mod.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import { ParallelTask } from '../../../dsl/tasks/ParallelTask.js';
2
+ import { TaskCompiler } from './types.js';
3
+ export declare const parallelCompiler: TaskCompiler<any, any, ParallelTask<any, any, any, any>>;
4
+ //# sourceMappingURL=parallel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parallel.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/parallel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAElE,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAqCnE,eAAO,MAAM,gBAAgB,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAGrF,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { from, map, mergeMap, of, toArray } from 'rxjs';
2
+ import { ParallelTask } from '../../../dsl/tasks/ParallelTask.js';
3
+ function compileParallel(ctx, task) {
4
+ const baseOperator = ctx.compiler.compileTask(ctx, task._base);
5
+ const eachOperator = ctx.compiler.compileTask(ctx, task._each);
6
+ return (src) => src.pipe(baseOperator, mergeMap((ctx) => {
7
+ return from(ctx.data).pipe(map((data, idx) => ctx.withData(data).setIndex(idx)),
8
+ // Process items in parallel using mergeMap
9
+ mergeMap((item) => eachOperator(of(item)).pipe(map((result) => result.setIndex(item.idx)))), toArray(), map((results) => {
10
+ // Sort by original index to maintain order
11
+ results.sort((a, b) => a.idx - b.idx);
12
+ return ctx.withData(results.map((r) => r.data));
13
+ }));
14
+ }));
15
+ }
16
+ export const parallelCompiler = {
17
+ ctor: ParallelTask,
18
+ compile: compileParallel,
19
+ };
@@ -0,0 +1,4 @@
1
+ import { ScheduleData, ScheduleTrigger } from '../../../dsl/triggers/ScheduleTrigger.js';
2
+ import { TriggerCompiler } from './types.js';
3
+ export declare const scheduleCompiler: TriggerCompiler<ScheduleData, ScheduleTrigger>;
4
+ //# sourceMappingURL=schedule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/schedule.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAEzF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA0H7C,eAAO,MAAM,gBAAgB,EAAE,eAAe,CAAC,YAAY,EAAE,eAAe,CAG3E,CAAC"}
@@ -0,0 +1,94 @@
1
+ import { Observable } from 'rxjs';
2
+ import { envVarEnvId, envVarEnvironmentName, envVarOrgId, envVarProjectId, } from '../../../dsl/http/versori/constants.js';
3
+ import { ScheduleTrigger } from '../../../dsl/triggers/ScheduleTrigger.js';
4
+ function compileSchedule(ctx, trigger, signal) {
5
+ return new Observable((subscriber) => {
6
+ // Add HTTP endpoint for manual triggering
7
+ if (!ctx.cronRouter) {
8
+ throw new Error('Router not available in compiler context');
9
+ }
10
+ const projectId = Deno.env.get(envVarProjectId) || 'example-service';
11
+ const environmentId = Deno.env.get(envVarEnvId) || 'example-environment';
12
+ const environmentName = Deno.env.get(envVarEnvironmentName) || 'example-environment';
13
+ const orgId = Deno.env.get(envVarOrgId) || 'example-org';
14
+ const client = ctx.connectionProvider;
15
+ ctx.cronRegistry.set(trigger.id, trigger.schedule);
16
+ async function handleSchedule(req, res, span) {
17
+ try {
18
+ if (trigger.activationPredicate === undefined) {
19
+ const activation = await client.getStaticActivation();
20
+ const executionCtx = ctx.contextProvider.create({}, { activation });
21
+ span.setAttribute('execution.id', executionCtx.executionId);
22
+ try {
23
+ subscriber.next(executionCtx);
24
+ }
25
+ catch (error) {
26
+ executionCtx.log.error('execution error inside schedule', { error });
27
+ }
28
+ res.status(200).json({
29
+ status: 'triggered',
30
+ executionId: executionCtx.executionId,
31
+ });
32
+ return;
33
+ }
34
+ const activations = await client.listActivations();
35
+ if (!activations || activations.length === 0) {
36
+ const executionCtx = ctx.contextProvider.create({}, undefined);
37
+ span.setAttribute('execution.id', executionCtx.executionId);
38
+ executionCtx.log.info('no activations found, continuing');
39
+ try {
40
+ subscriber.next(executionCtx);
41
+ }
42
+ catch (error) {
43
+ executionCtx.log.error('execution error inside schedule', { error });
44
+ }
45
+ res.status(200).json({
46
+ status: 'triggered',
47
+ executionId: executionCtx.executionId,
48
+ });
49
+ return;
50
+ }
51
+ activations.forEach((activation) => {
52
+ const executionCtx = ctx.contextProvider.create({}, { activation });
53
+ try {
54
+ subscriber.next(executionCtx);
55
+ }
56
+ catch (error) {
57
+ executionCtx.log.error('execution error inside schedule', { error });
58
+ }
59
+ });
60
+ res.status(200).json({ status: 'triggered' });
61
+ }
62
+ catch (error) {
63
+ ctx.log.error('execution error inside schedule', { error });
64
+ res.status(500).json({ error: 'Failed to trigger schedule' });
65
+ }
66
+ }
67
+ ctx.cronRouter.post(`/cron/${trigger.id}`, async (req, res) => {
68
+ await ctx.tracer.startActiveSpan(`schedule-${trigger.id}`, async (span) => {
69
+ span.setAttribute('task.id', trigger.id);
70
+ span.setAttribute('task.type', 'schedule');
71
+ span.setAttribute('schedule', trigger.schedule);
72
+ span.setAttribute('project.id', projectId);
73
+ span.setAttribute('environment.id', environmentId);
74
+ span.setAttribute('environment.name', environmentName);
75
+ span.setAttribute('org.id', orgId);
76
+ await handleSchedule(req, res, span);
77
+ span.end();
78
+ });
79
+ });
80
+ function cleanup() {
81
+ ctx.log.debug('scheduler trigger stopped');
82
+ subscriber.complete();
83
+ }
84
+ signal.addEventListener('abort', cleanup, { once: true });
85
+ return () => {
86
+ signal.removeEventListener('abort', cleanup);
87
+ ctx.log.debug('scheduler execution unsubscribed');
88
+ };
89
+ });
90
+ }
91
+ export const scheduleCompiler = {
92
+ ctor: ScheduleTrigger,
93
+ compile: compileSchedule,
94
+ };
@@ -0,0 +1,4 @@
1
+ import { SerialTask } from '../../../dsl/tasks/SerialTask.js';
2
+ import { TaskCompiler } from './types.js';
3
+ export declare const serialCompiler: TaskCompiler<any, any, SerialTask<any, any, any, any>>;
4
+ //# sourceMappingURL=serial.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serial.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/serial.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAE9D,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AA4BnE,eAAO,MAAM,cAAc,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAGjF,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { concat, map, mergeMap, of, toArray, tap } from 'rxjs';
2
+ import { SerialTask } from '../../../dsl/tasks/SerialTask.js';
3
+ function compileSerial(ctx, task) {
4
+ const baseOperator = ctx.compiler.compileTask(ctx, task._base);
5
+ const eachOperator = ctx.compiler.compileTask(ctx, task._each);
6
+ return (src) => src.pipe(tap({
7
+ complete: () => ctx.log.debug('serial.complete'),
8
+ }), baseOperator, mergeMap((ctx) => {
9
+ const tasks = ctx.data.map((d, idx) => eachOperator(of(ctx.withData(d).setIndex(idx))));
10
+ return concat(...tasks).pipe(map((result) => result.data), toArray(), map((results) => ctx.withData(results)));
11
+ }));
12
+ }
13
+ export const serialCompiler = {
14
+ ctor: SerialTask,
15
+ compile: compileSerial,
16
+ };
@@ -0,0 +1,15 @@
1
+ import { Observable, OperatorFunction } from "rxjs";
2
+ import { ContextImpl } from '../../../context/Context.js';
3
+ import { Task } from "../../../dsl/Task.js";
4
+ import { Trigger } from '../../../dsl/Trigger.js';
5
+ import { DurableCompilerContext } from '../ObservableCompiler.js';
6
+ export interface TaskCompiler<In, Out, T extends Task<In, Out>> {
7
+ ctor: new (...args: any[]) => T;
8
+ compile: <Index = void>(ctx: DurableCompilerContext, task: T) => ContextOperatorFunction<In, Out, Index>;
9
+ }
10
+ export interface TriggerCompiler<Out, T extends Trigger<Out>> {
11
+ compile: (ctx: DurableCompilerContext, trigger: T, signal: AbortSignal) => Observable<ContextImpl<Out, void>>;
12
+ ctor: new (...args: any[]) => T;
13
+ }
14
+ export type ContextOperatorFunction<In, Out, Index = void> = OperatorFunction<ContextImpl<In, Index>, ContextImpl<Out, Index>>;
15
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,WAAW,YAAY,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,SAAS,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC;IAC1D,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAChC,OAAO,EAAE,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,sBAAsB,EAAE,IAAI,EAAE,CAAC,KAAK,uBAAuB,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;CAC5G;AAED,MAAM,WAAW,eAAe,CAAC,GAAG,EAAE,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC;IACxD,OAAO,EAAE,CAAC,GAAG,EAAE,sBAAsB,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,KAAK,UAAU,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;IAC9G,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;CACnC;AAED,MAAM,MAAM,uBAAuB,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI,IAAI,gBAAgB,CAAC,WAAW,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import { UnpackTask } from '../../../dsl/tasks/UnpackTask.js';
2
+ import { TaskCompiler } from './types.js';
3
+ export declare const unpackCompiler: TaskCompiler<any, any, UnpackTask<any, any, any>>;
4
+ //# sourceMappingURL=unpack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unpack.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/unpack.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAE9D,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AA6BnE,eAAO,MAAM,cAAc,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAG5E,CAAC"}