ts2workflows 0.2.0 → 0.4.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/dist/ast/stepnames.d.ts.map +1 -1
- package/dist/ast/stepnames.js +11 -1
- package/dist/ast/steps.d.ts +24 -13
- package/dist/ast/steps.d.ts.map +1 -1
- package/dist/ast/steps.js +42 -27
- package/dist/transpiler/expressions.d.ts +7 -4
- package/dist/transpiler/expressions.d.ts.map +1 -1
- package/dist/transpiler/expressions.js +156 -37
- package/dist/transpiler/index.d.ts.map +1 -1
- package/dist/transpiler/index.js +29 -28
- package/dist/transpiler/statements.d.ts +2 -1
- package/dist/transpiler/statements.d.ts.map +1 -1
- package/dist/transpiler/statements.js +135 -158
- package/dist/transpiler/transformations.d.ts +1 -1
- package/dist/transpiler/transformations.d.ts.map +1 -1
- package/dist/transpiler/transformations.js +27 -6
- package/language_reference.md +57 -35
- package/package.json +22 -3
- package/types/global.d.ts +116 -0
- package/types/workflowslib.d.ts +17 -5
- package/dist/transpiler/asserts.d.ts +0 -7
- package/dist/transpiler/asserts.d.ts.map +0 -1
- package/dist/transpiler/asserts.js +0 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stepnames.d.ts","sourceRoot":"","sources":["../../src/ast/stepnames.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"stepnames.d.ts","sourceRoot":"","sources":["../../src/ast/stepnames.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,WAAW,EAGZ,MAAM,YAAY,CAAA;AACnB,OAAO,EAAe,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAQzD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAqB;;IAMrC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAMjC;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,WAAW,GAAG,WAAW,CAS/D"}
|
package/dist/ast/stepnames.js
CHANGED
|
@@ -168,12 +168,13 @@ function relabelNextLabels(steps, replacements) {
|
|
|
168
168
|
*/
|
|
169
169
|
function renameJumpTargets(step, replaceLabels) {
|
|
170
170
|
switch (step.tag) {
|
|
171
|
-
case 'assign':
|
|
172
171
|
case 'call':
|
|
173
172
|
case 'raise':
|
|
174
173
|
case 'return':
|
|
175
174
|
case 'jumptarget':
|
|
176
175
|
return step;
|
|
176
|
+
case 'assign':
|
|
177
|
+
return renameJumpTargetsAssign(step, replaceLabels);
|
|
177
178
|
case 'next':
|
|
178
179
|
return renameJumpTargetsNext(step, replaceLabels);
|
|
179
180
|
case 'for':
|
|
@@ -188,6 +189,15 @@ function renameJumpTargets(step, replaceLabels) {
|
|
|
188
189
|
return renameJumpTargetsTry(step, replaceLabels);
|
|
189
190
|
}
|
|
190
191
|
}
|
|
192
|
+
function renameJumpTargetsAssign(step, replaceLabels) {
|
|
193
|
+
if (step.next) {
|
|
194
|
+
const newLabel = replaceLabels.get(step.next);
|
|
195
|
+
if (newLabel) {
|
|
196
|
+
return step.withNext(newLabel);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return step;
|
|
200
|
+
}
|
|
191
201
|
function renameJumpTargetsFor(step, replaceLabels) {
|
|
192
202
|
const transformedSteps = step.steps.map(({ name, step: nested }) => ({
|
|
193
203
|
name,
|
package/dist/ast/steps.d.ts
CHANGED
|
@@ -37,17 +37,21 @@ export interface NamedWorkflowStep {
|
|
|
37
37
|
export declare class AssignStepAST {
|
|
38
38
|
readonly tag = "assign";
|
|
39
39
|
readonly assignments: VariableAssignment[];
|
|
40
|
-
readonly label
|
|
41
|
-
|
|
40
|
+
readonly label?: string;
|
|
41
|
+
readonly next?: string;
|
|
42
|
+
constructor(assignments: VariableAssignment[], next?: string, label?: string);
|
|
43
|
+
withNext(newNext?: string): AssignStepAST;
|
|
44
|
+
withLabel(newLabel?: string): AssignStepAST;
|
|
42
45
|
}
|
|
43
46
|
export declare class CallStepAST {
|
|
44
47
|
readonly tag = "call";
|
|
45
48
|
readonly call: string;
|
|
46
49
|
readonly args?: WorkflowParameters;
|
|
47
50
|
readonly result?: VariableName;
|
|
48
|
-
readonly label
|
|
51
|
+
readonly label?: string;
|
|
49
52
|
constructor(call: string, args?: WorkflowParameters, result?: VariableName, label?: string);
|
|
50
53
|
labelPrefix(): string;
|
|
54
|
+
withLabel(newLabel?: string): CallStepAST;
|
|
51
55
|
}
|
|
52
56
|
export declare class ForStepAST {
|
|
53
57
|
readonly tag = "for";
|
|
@@ -57,8 +61,9 @@ export declare class ForStepAST {
|
|
|
57
61
|
readonly listExpression: Expression;
|
|
58
62
|
readonly rangeStart?: number;
|
|
59
63
|
readonly rangeEnd?: number;
|
|
60
|
-
readonly label
|
|
64
|
+
readonly label?: string;
|
|
61
65
|
constructor(steps: WorkflowStepAST[], loopVariableName: VariableName, listExpression: Expression, indexVariable?: VariableName, rangeStart?: number, rangeEnd?: number, label?: string);
|
|
66
|
+
withLabel(newLabel?: string): ForStepAST;
|
|
62
67
|
}
|
|
63
68
|
export declare class ForStepASTNamed {
|
|
64
69
|
readonly tag = "for";
|
|
@@ -73,8 +78,9 @@ export declare class ForStepASTNamed {
|
|
|
73
78
|
export declare class NextStepAST {
|
|
74
79
|
readonly tag = "next";
|
|
75
80
|
readonly target: string;
|
|
76
|
-
readonly label
|
|
81
|
+
readonly label?: string;
|
|
77
82
|
constructor(target: string, label?: string);
|
|
83
|
+
withLabel(newLabel?: string): NextStepAST;
|
|
78
84
|
}
|
|
79
85
|
export declare class ParallelStepAST {
|
|
80
86
|
readonly tag = "parallel";
|
|
@@ -82,8 +88,9 @@ export declare class ParallelStepAST {
|
|
|
82
88
|
readonly shared?: VariableName[];
|
|
83
89
|
readonly concurrencyLimit?: number;
|
|
84
90
|
readonly exceptionPolicy?: string;
|
|
85
|
-
readonly label
|
|
91
|
+
readonly label?: string;
|
|
86
92
|
constructor(steps: Record<StepName, StepsStepAST> | ForStepAST, shared?: VariableName[], concurrencyLimit?: number, exceptionPolicy?: string, label?: string);
|
|
93
|
+
withLabel(newLabel?: string): ParallelStepAST;
|
|
87
94
|
}
|
|
88
95
|
export declare class ParallelStepASTNamed {
|
|
89
96
|
readonly tag = "parallel";
|
|
@@ -97,20 +104,23 @@ export declare class ParallelStepASTNamed {
|
|
|
97
104
|
export declare class RaiseStepAST {
|
|
98
105
|
readonly tag = "raise";
|
|
99
106
|
readonly value: Expression;
|
|
100
|
-
readonly label
|
|
107
|
+
readonly label?: string;
|
|
101
108
|
constructor(value: Expression, label?: string);
|
|
109
|
+
withLabel(newLabel?: string): RaiseStepAST;
|
|
102
110
|
}
|
|
103
111
|
export declare class ReturnStepAST {
|
|
104
112
|
readonly tag = "return";
|
|
105
|
-
readonly value
|
|
106
|
-
readonly label
|
|
113
|
+
readonly value?: Expression;
|
|
114
|
+
readonly label?: string;
|
|
107
115
|
constructor(value: Expression | undefined, label?: string);
|
|
116
|
+
withLabel(newLabel?: string): ReturnStepAST;
|
|
108
117
|
}
|
|
109
118
|
export declare class StepsStepAST {
|
|
110
119
|
readonly tag = "steps";
|
|
111
120
|
readonly steps: WorkflowStepAST[];
|
|
112
|
-
readonly label
|
|
121
|
+
readonly label?: string;
|
|
113
122
|
constructor(steps: WorkflowStepAST[], label?: string);
|
|
123
|
+
withLabel(newLabel?: string): StepsStepAST;
|
|
114
124
|
}
|
|
115
125
|
export declare class StepsStepASTNamed {
|
|
116
126
|
readonly tag = "steps";
|
|
@@ -120,8 +130,9 @@ export declare class StepsStepASTNamed {
|
|
|
120
130
|
export declare class SwitchStepAST {
|
|
121
131
|
readonly tag = "switch";
|
|
122
132
|
readonly branches: SwitchConditionAST<WorkflowStepAST>[];
|
|
123
|
-
readonly label
|
|
133
|
+
readonly label?: string;
|
|
124
134
|
constructor(branches: SwitchConditionAST<WorkflowStepAST>[], label?: string);
|
|
135
|
+
withLabel(newLabel?: string): SwitchStepAST;
|
|
125
136
|
}
|
|
126
137
|
export declare class SwitchStepASTNamed {
|
|
127
138
|
readonly tag = "switch";
|
|
@@ -140,8 +151,9 @@ export declare class TryStepAST {
|
|
|
140
151
|
readonly exceptSteps: WorkflowStepAST[];
|
|
141
152
|
readonly retryPolicy?: string | CustomRetryPolicy;
|
|
142
153
|
readonly errorMap?: VariableName;
|
|
143
|
-
readonly label
|
|
154
|
+
readonly label?: string;
|
|
144
155
|
constructor(trySteps: WorkflowStepAST[], exceptSteps: WorkflowStepAST[], retryPolicy?: string | CustomRetryPolicy, errorMap?: VariableName, label?: string);
|
|
156
|
+
withLabel(newLabel?: string): TryStepAST;
|
|
145
157
|
}
|
|
146
158
|
export declare class TryStepASTNamed {
|
|
147
159
|
readonly tag = "try";
|
|
@@ -172,5 +184,4 @@ export declare function nestedSteps(step: WorkflowStepASTWithNamedNested): Named
|
|
|
172
184
|
* Returns an GCP Workflows object representation of a step.
|
|
173
185
|
*/
|
|
174
186
|
export declare function renderStep(step: WorkflowStepASTWithNamedNested): Record<string, unknown>;
|
|
175
|
-
export declare function stepWithLabel(step: WorkflowStepAST, label: string): WorkflowStepAST;
|
|
176
187
|
//# sourceMappingURL=steps.d.ts.map
|
package/dist/ast/steps.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"steps.d.ts","sourceRoot":"","sources":["../../src/ast/steps.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,YAAY,EAEb,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAE/D,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAA;AAC7B,MAAM,MAAM,kBAAkB,GAAG,SAAS,CAAC,YAAY,EAAE,UAAU,CAAC,CAAA;AACpE,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAAA;AAEjE,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,OA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BAAiB,EAAE,CAAA;gBAGvC,KAAK,EAAE,iBAAiB,EAAE,EAC1B,WAAW,EAAE,iBAAiB,EAAE,EAChC,WAAW,CAAC,EAAE,MAAM,GAAG,iBAAiB,EACxC,QAAQ,CAAC,EAAE,YAAY;CAO1B;AAKD,qBAAa,aAAa;IACxB,QAAQ,CAAC,GAAG,gBAAe;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;;CAKvB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,eAAe,EACrB,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GACvC,iBAAiB,CAsCnB;AAqGD;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,8BAA8B,GACnC,iBAAiB,EAAE,EAAE,CAuBvB;AA6BD;;GAEG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,8BAA8B,GACnC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA+DzB"}
|
package/dist/ast/steps.js
CHANGED
|
@@ -20,10 +20,23 @@ export class AssignStepAST {
|
|
|
20
20
|
tag = 'assign';
|
|
21
21
|
assignments;
|
|
22
22
|
label;
|
|
23
|
-
|
|
23
|
+
next;
|
|
24
|
+
constructor(assignments, next, label) {
|
|
24
25
|
this.assignments = assignments;
|
|
26
|
+
this.next = next;
|
|
25
27
|
this.label = label;
|
|
26
28
|
}
|
|
29
|
+
withNext(newNext) {
|
|
30
|
+
if (newNext === this.next) {
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return new AssignStepAST(this.assignments, newNext, this.label);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
withLabel(newLabel) {
|
|
38
|
+
return new AssignStepAST(this.assignments, newLabel);
|
|
39
|
+
}
|
|
27
40
|
}
|
|
28
41
|
// https://cloud.google.com/workflows/docs/reference/syntax/calls
|
|
29
42
|
export class CallStepAST {
|
|
@@ -41,6 +54,9 @@ export class CallStepAST {
|
|
|
41
54
|
labelPrefix() {
|
|
42
55
|
return 'call_' + this.call.replaceAll(/[^a-zA-Z0-9]/g, '_') + '_';
|
|
43
56
|
}
|
|
57
|
+
withLabel(newLabel) {
|
|
58
|
+
return new CallStepAST(this.call, this.args, this.result, newLabel);
|
|
59
|
+
}
|
|
44
60
|
}
|
|
45
61
|
// https://cloud.google.com/workflows/docs/reference/syntax/iteration
|
|
46
62
|
export class ForStepAST {
|
|
@@ -61,6 +77,9 @@ export class ForStepAST {
|
|
|
61
77
|
this.rangeEnd = rangeEnd;
|
|
62
78
|
this.label = label;
|
|
63
79
|
}
|
|
80
|
+
withLabel(newLabel) {
|
|
81
|
+
return new ForStepAST(this.steps, this.loopVariableName, this.listExpression, this.indexVariableName, this.rangeStart, this.rangeEnd, newLabel);
|
|
82
|
+
}
|
|
64
83
|
}
|
|
65
84
|
export class ForStepASTNamed {
|
|
66
85
|
tag = 'for';
|
|
@@ -87,6 +106,9 @@ export class NextStepAST {
|
|
|
87
106
|
this.target = target;
|
|
88
107
|
this.label = label;
|
|
89
108
|
}
|
|
109
|
+
withLabel(newLabel) {
|
|
110
|
+
return new NextStepAST(this.target, newLabel);
|
|
111
|
+
}
|
|
90
112
|
}
|
|
91
113
|
// https://cloud.google.com/workflows/docs/reference/syntax/parallel-steps
|
|
92
114
|
export class ParallelStepAST {
|
|
@@ -103,6 +125,9 @@ export class ParallelStepAST {
|
|
|
103
125
|
this.exceptionPolicy = exceptionPolicy;
|
|
104
126
|
this.label = label;
|
|
105
127
|
}
|
|
128
|
+
withLabel(newLabel) {
|
|
129
|
+
return new ParallelStepAST(this.steps, this.shared, this.concurrencyLimit, this.exceptionPolicy, newLabel);
|
|
130
|
+
}
|
|
106
131
|
}
|
|
107
132
|
export class ParallelStepASTNamed {
|
|
108
133
|
tag = 'parallel';
|
|
@@ -134,6 +159,9 @@ export class RaiseStepAST {
|
|
|
134
159
|
this.value = value;
|
|
135
160
|
this.label = label;
|
|
136
161
|
}
|
|
162
|
+
withLabel(newLabel) {
|
|
163
|
+
return new RaiseStepAST(this.value, newLabel);
|
|
164
|
+
}
|
|
137
165
|
}
|
|
138
166
|
// https://cloud.google.com/workflows/docs/reference/syntax/completing
|
|
139
167
|
export class ReturnStepAST {
|
|
@@ -144,6 +172,9 @@ export class ReturnStepAST {
|
|
|
144
172
|
this.value = value;
|
|
145
173
|
this.label = label;
|
|
146
174
|
}
|
|
175
|
+
withLabel(newLabel) {
|
|
176
|
+
return new ReturnStepAST(this.value, newLabel);
|
|
177
|
+
}
|
|
147
178
|
}
|
|
148
179
|
// https://cloud.google.com/workflows/docs/reference/syntax/steps#embedded-steps
|
|
149
180
|
export class StepsStepAST {
|
|
@@ -154,6 +185,9 @@ export class StepsStepAST {
|
|
|
154
185
|
this.steps = steps;
|
|
155
186
|
this.label = label;
|
|
156
187
|
}
|
|
188
|
+
withLabel(newLabel) {
|
|
189
|
+
return new StepsStepAST(this.steps, newLabel);
|
|
190
|
+
}
|
|
157
191
|
}
|
|
158
192
|
export class StepsStepASTNamed {
|
|
159
193
|
tag = 'steps';
|
|
@@ -171,6 +205,9 @@ export class SwitchStepAST {
|
|
|
171
205
|
this.branches = branches;
|
|
172
206
|
this.label = label;
|
|
173
207
|
}
|
|
208
|
+
withLabel(newLabel) {
|
|
209
|
+
return new SwitchStepAST(this.branches, newLabel);
|
|
210
|
+
}
|
|
174
211
|
}
|
|
175
212
|
export class SwitchStepASTNamed {
|
|
176
213
|
tag = 'switch';
|
|
@@ -196,6 +233,9 @@ export class TryStepAST {
|
|
|
196
233
|
this.errorMap = errorMap;
|
|
197
234
|
this.label = label;
|
|
198
235
|
}
|
|
236
|
+
withLabel(newLabel) {
|
|
237
|
+
return new TryStepAST(this.trySteps, this.exceptSteps, this.retryPolicy, this.errorMap, newLabel);
|
|
238
|
+
}
|
|
199
239
|
}
|
|
200
240
|
export class TryStepASTNamed {
|
|
201
241
|
tag = 'try';
|
|
@@ -366,6 +406,7 @@ export function renderStep(step) {
|
|
|
366
406
|
assign: step.assignments.map(([key, val]) => {
|
|
367
407
|
return { [key]: expressionToLiteralValueOrLiteralExpression(val) };
|
|
368
408
|
}),
|
|
409
|
+
...(step.next && { next: step.next }),
|
|
369
410
|
};
|
|
370
411
|
case 'call':
|
|
371
412
|
return renderCallStep(step);
|
|
@@ -506,29 +547,3 @@ function renderSteps(steps) {
|
|
|
506
547
|
return { [x.name]: renderStep(x.step) };
|
|
507
548
|
});
|
|
508
549
|
}
|
|
509
|
-
export function stepWithLabel(step, label) {
|
|
510
|
-
switch (step.tag) {
|
|
511
|
-
case 'assign':
|
|
512
|
-
return new AssignStepAST(step.assignments, label);
|
|
513
|
-
case 'call':
|
|
514
|
-
return new CallStepAST(step.call, step.args, step.result, label);
|
|
515
|
-
case 'for':
|
|
516
|
-
return new ForStepAST(step.steps, step.loopVariableName, step.listExpression, step.indexVariableName, step.rangeStart, step.rangeEnd, label);
|
|
517
|
-
case 'next':
|
|
518
|
-
return new NextStepAST(step.target, label);
|
|
519
|
-
case 'parallel':
|
|
520
|
-
return new ParallelStepAST(step.steps, step.shared, step.concurrencyLimit, step.exceptionPolicy, label);
|
|
521
|
-
case 'raise':
|
|
522
|
-
return new RaiseStepAST(step.value, label);
|
|
523
|
-
case 'return':
|
|
524
|
-
return new ReturnStepAST(step.value, label);
|
|
525
|
-
case 'steps':
|
|
526
|
-
return new StepsStepAST(step.steps, label);
|
|
527
|
-
case 'switch':
|
|
528
|
-
return new SwitchStepAST(step.branches, label);
|
|
529
|
-
case 'try':
|
|
530
|
-
return new TryStepAST(step.trySteps, step.exceptSteps, step.retryPolicy, step.errorMap, label);
|
|
531
|
-
case 'jumptarget':
|
|
532
|
-
return step;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/typescript-estree';
|
|
1
2
|
import { Expression, Primitive } from '../ast/expressions.js';
|
|
2
|
-
export declare function convertExpression(instance:
|
|
3
|
-
export declare function convertObjectExpression(node:
|
|
4
|
-
export declare function convertObjectAsExpressionValues(node:
|
|
5
|
-
export declare function convertMemberExpression(node:
|
|
3
|
+
export declare function convertExpression(instance: TSESTree.Expression): Expression;
|
|
4
|
+
export declare function convertObjectExpression(node: TSESTree.ObjectExpression): Record<string, Primitive | Expression>;
|
|
5
|
+
export declare function convertObjectAsExpressionValues(node: TSESTree.ObjectExpression): Record<string, Expression>;
|
|
6
|
+
export declare function convertMemberExpression(node: TSESTree.MemberExpression): Expression;
|
|
7
|
+
export declare function isMagicFunction(calleeName: string): boolean;
|
|
8
|
+
export declare function throwIfSpread<T extends TSESTree.Expression | TSESTree.Property | TSESTree.SpreadElement | null>(nodes: T[]): Exclude<T, TSESTree.SpreadElement>[];
|
|
6
9
|
//# sourceMappingURL=expressions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expressions.d.ts","sourceRoot":"","sources":["../../src/transpiler/expressions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"expressions.d.ts","sourceRoot":"","sources":["../../src/transpiler/expressions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,sCAAsC,CAAA;AAC/E,OAAO,EAGL,UAAU,EAGV,SAAS,EAMV,MAAM,uBAAuB,CAAA;AAG9B,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,CAAC,UAAU,GAAG,UAAU,CAO3E;AAED,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,QAAQ,CAAC,gBAAgB,GAC9B,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,UAAU,CAAC,CAgCxC;AAED,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,QAAQ,CAAC,gBAAgB,GAC9B,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAU5B;AAsMD,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,QAAQ,CAAC,gBAAgB,GAC9B,UAAU,CAcZ;AA0JD,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAG3D;AA8CD,wBAAgB,aAAa,CAC3B,CAAC,SACG,QAAQ,CAAC,UAAU,GACnB,QAAQ,CAAC,QAAQ,GACjB,QAAQ,CAAC,aAAa,GACtB,IAAI,EACR,KAAK,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAC,EAAE,CAgBlD"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
|
|
3
2
|
import { BinaryExpression, FunctionInvocationExpression, MemberExpression, PrimitiveExpression, UnaryExpression, VariableReferenceExpression, isExpression, isFullyQualifiedName, } from '../ast/expressions.js';
|
|
4
|
-
import { WorkflowSyntaxError } from '../errors.js';
|
|
5
|
-
import { assertOneOfManyTypes, assertType } from './asserts.js';
|
|
6
|
-
const { ArrayExpression, AwaitExpression, CallExpression, ConditionalExpression, Identifier, Literal, LogicalExpression, ObjectExpression, TemplateLiteral, TSAsExpression, } = AST_NODE_TYPES;
|
|
3
|
+
import { InternalTranspilingError, WorkflowSyntaxError } from '../errors.js';
|
|
7
4
|
export function convertExpression(instance) {
|
|
8
5
|
const expOrPrimitive = convertExpressionOrPrimitive(instance);
|
|
9
6
|
if (isExpression(expOrPrimitive)) {
|
|
@@ -14,14 +11,12 @@ export function convertExpression(instance) {
|
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
13
|
export function convertObjectExpression(node) {
|
|
17
|
-
|
|
18
|
-
const properties = node.properties;
|
|
19
|
-
return Object.fromEntries(properties.map(({ key, value }) => {
|
|
14
|
+
return Object.fromEntries(throwIfSpread(node.properties).map(({ key, value }) => {
|
|
20
15
|
let keyPrimitive;
|
|
21
|
-
if (key.type === Identifier) {
|
|
16
|
+
if (key.type === AST_NODE_TYPES.Identifier) {
|
|
22
17
|
keyPrimitive = key.name;
|
|
23
18
|
}
|
|
24
|
-
else if (key.type === Literal) {
|
|
19
|
+
else if (key.type === AST_NODE_TYPES.Literal) {
|
|
25
20
|
if (typeof key.value === 'string') {
|
|
26
21
|
keyPrimitive = key.value;
|
|
27
22
|
}
|
|
@@ -32,6 +27,10 @@ export function convertObjectExpression(node) {
|
|
|
32
27
|
else {
|
|
33
28
|
throw new WorkflowSyntaxError(`Not implemented object key type: ${key.type}`, key.loc);
|
|
34
29
|
}
|
|
30
|
+
if (value.type === AST_NODE_TYPES.AssignmentPattern ||
|
|
31
|
+
value.type === AST_NODE_TYPES.TSEmptyBodyFunctionExpression) {
|
|
32
|
+
throw new WorkflowSyntaxError('Value not supported', value.loc);
|
|
33
|
+
}
|
|
35
34
|
return [keyPrimitive, convertExpressionOrPrimitive(value)];
|
|
36
35
|
}));
|
|
37
36
|
}
|
|
@@ -45,15 +44,21 @@ export function convertObjectAsExpressionValues(node) {
|
|
|
45
44
|
}
|
|
46
45
|
function convertExpressionOrPrimitive(instance) {
|
|
47
46
|
switch (instance.type) {
|
|
48
|
-
case ArrayExpression:
|
|
49
|
-
return instance
|
|
50
|
-
case ObjectExpression:
|
|
47
|
+
case AST_NODE_TYPES.ArrayExpression:
|
|
48
|
+
return convertArrayExpression(instance);
|
|
49
|
+
case AST_NODE_TYPES.ObjectExpression:
|
|
51
50
|
return convertObjectExpression(instance);
|
|
52
|
-
case Literal:
|
|
51
|
+
case AST_NODE_TYPES.Literal:
|
|
52
|
+
if (instance.value instanceof RegExp) {
|
|
53
|
+
throw new WorkflowSyntaxError('RegExp is not supported', instance.loc);
|
|
54
|
+
}
|
|
55
|
+
if (typeof instance.value === 'bigint') {
|
|
56
|
+
throw new WorkflowSyntaxError('BigInt in not supported', instance.loc);
|
|
57
|
+
}
|
|
53
58
|
return instance.value;
|
|
54
|
-
case TemplateLiteral:
|
|
59
|
+
case AST_NODE_TYPES.TemplateLiteral:
|
|
55
60
|
return convertTemplateLiteralToExpression(instance);
|
|
56
|
-
case Identifier:
|
|
61
|
+
case AST_NODE_TYPES.Identifier:
|
|
57
62
|
if (instance.name === 'null' || instance.name === 'undefined') {
|
|
58
63
|
return null;
|
|
59
64
|
}
|
|
@@ -69,27 +74,32 @@ function convertExpressionOrPrimitive(instance) {
|
|
|
69
74
|
case AST_NODE_TYPES.UnaryExpression:
|
|
70
75
|
return convertUnaryExpression(instance);
|
|
71
76
|
case AST_NODE_TYPES.BinaryExpression:
|
|
72
|
-
case LogicalExpression:
|
|
77
|
+
case AST_NODE_TYPES.LogicalExpression:
|
|
73
78
|
return convertBinaryExpression(instance);
|
|
74
79
|
case AST_NODE_TYPES.MemberExpression:
|
|
75
80
|
return convertMemberExpression(instance);
|
|
76
|
-
case
|
|
81
|
+
case AST_NODE_TYPES.ChainExpression:
|
|
82
|
+
return convertChainExpression(instance);
|
|
83
|
+
case AST_NODE_TYPES.CallExpression:
|
|
77
84
|
return convertCallExpression(instance);
|
|
78
|
-
case ConditionalExpression:
|
|
85
|
+
case AST_NODE_TYPES.ConditionalExpression:
|
|
79
86
|
return convertConditionalExpression(instance);
|
|
80
|
-
case TSAsExpression:
|
|
87
|
+
case AST_NODE_TYPES.TSAsExpression:
|
|
81
88
|
return convertExpressionOrPrimitive(instance.expression);
|
|
82
|
-
case
|
|
89
|
+
case AST_NODE_TYPES.TSNonNullExpression:
|
|
90
|
+
return convertExpressionOrPrimitive(instance.expression);
|
|
91
|
+
case AST_NODE_TYPES.AwaitExpression:
|
|
83
92
|
return convertExpressionOrPrimitive(instance.argument);
|
|
84
93
|
default:
|
|
85
94
|
throw new WorkflowSyntaxError(`Not implemented expression type: ${instance.type}`, instance.loc);
|
|
86
95
|
}
|
|
87
96
|
}
|
|
97
|
+
function convertArrayExpression(instance) {
|
|
98
|
+
return throwIfSpread(instance.elements).map((e) => e === null
|
|
99
|
+
? new PrimitiveExpression(null)
|
|
100
|
+
: convertExpressionOrPrimitive(e));
|
|
101
|
+
}
|
|
88
102
|
function convertBinaryExpression(instance) {
|
|
89
|
-
assertOneOfManyTypes(instance, [
|
|
90
|
-
AST_NODE_TYPES.BinaryExpression,
|
|
91
|
-
LogicalExpression,
|
|
92
|
-
]);
|
|
93
103
|
// Special case for nullish coalescing becuase the result is a function call
|
|
94
104
|
// expression, not a binary expression
|
|
95
105
|
if (instance.operator === '??') {
|
|
@@ -126,6 +136,9 @@ function convertBinaryExpression(instance) {
|
|
|
126
136
|
default:
|
|
127
137
|
throw new WorkflowSyntaxError(`Unsupported binary operator: ${instance.operator}`, instance.loc);
|
|
128
138
|
}
|
|
139
|
+
if (instance.left.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
140
|
+
throw new WorkflowSyntaxError('Private identifier not supported', instance.left.loc);
|
|
141
|
+
}
|
|
129
142
|
return new BinaryExpression(convertExpression(instance.left), op, convertExpression(instance.right));
|
|
130
143
|
}
|
|
131
144
|
function nullishCoalescingExpression(left, right) {
|
|
@@ -135,7 +148,6 @@ function nullishCoalescingExpression(left, right) {
|
|
|
135
148
|
]);
|
|
136
149
|
}
|
|
137
150
|
function convertUnaryExpression(instance) {
|
|
138
|
-
assertType(instance, AST_NODE_TYPES.UnaryExpression);
|
|
139
151
|
if (instance.prefix === false) {
|
|
140
152
|
throw new WorkflowSyntaxError('only prefix unary operators are supported', instance.loc);
|
|
141
153
|
}
|
|
@@ -165,37 +177,136 @@ function convertUnaryExpression(instance) {
|
|
|
165
177
|
return op ? new UnaryExpression(op, ex) : ex;
|
|
166
178
|
}
|
|
167
179
|
export function convertMemberExpression(node) {
|
|
168
|
-
|
|
180
|
+
if (node.property.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
181
|
+
throw new WorkflowSyntaxError('Private identifier not supported', node.property.loc);
|
|
182
|
+
}
|
|
169
183
|
const object = convertExpression(node.object);
|
|
170
184
|
return new MemberExpression(object, convertExpression(node.property), node.computed);
|
|
171
185
|
}
|
|
186
|
+
function convertChainExpression(node) {
|
|
187
|
+
const properties = chainExpressionToFlatArray(node.expression);
|
|
188
|
+
const args = optinalChainToMapGetArguments(properties);
|
|
189
|
+
return new FunctionInvocationExpression('map.get', args);
|
|
190
|
+
}
|
|
191
|
+
function chainExpressionToFlatArray(node) {
|
|
192
|
+
if (node.type === AST_NODE_TYPES.MemberExpression) {
|
|
193
|
+
if (node.property.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
194
|
+
throw new WorkflowSyntaxError('Private identifier not supported', node.property.loc);
|
|
195
|
+
}
|
|
196
|
+
const data = {
|
|
197
|
+
property: node.property,
|
|
198
|
+
optional: node.optional,
|
|
199
|
+
computed: node.computed,
|
|
200
|
+
};
|
|
201
|
+
return chainExpressionToFlatArray(node.object).concat([data]);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
return [
|
|
205
|
+
{
|
|
206
|
+
property: node,
|
|
207
|
+
optional: false,
|
|
208
|
+
computed: false,
|
|
209
|
+
},
|
|
210
|
+
];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function optinalChainToMapGetArguments(properties) {
|
|
214
|
+
if (properties.length <= 0) {
|
|
215
|
+
// this shouldn't happen
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
let base;
|
|
219
|
+
let optionalSliceStart;
|
|
220
|
+
const firstOptional = properties.findIndex((p) => p.optional);
|
|
221
|
+
if (firstOptional > 2) {
|
|
222
|
+
const baseProperties = properties.slice(0, firstOptional - 1);
|
|
223
|
+
base = memberExpressionFromList(baseProperties);
|
|
224
|
+
optionalSliceStart = firstOptional - 1;
|
|
225
|
+
}
|
|
226
|
+
else if (firstOptional >= 0) {
|
|
227
|
+
base = convertExpression(properties[0].property);
|
|
228
|
+
optionalSliceStart = 1;
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
// firstOptional < 0, this shouldn't happen
|
|
232
|
+
base = memberExpressionFromList(properties);
|
|
233
|
+
optionalSliceStart = properties.length;
|
|
234
|
+
}
|
|
235
|
+
const optionals = properties.slice(optionalSliceStart).map((opt) => {
|
|
236
|
+
const propertyExp = convertExpression(opt.property);
|
|
237
|
+
if (opt.computed) {
|
|
238
|
+
return propertyExp;
|
|
239
|
+
}
|
|
240
|
+
else if (isFullyQualifiedName(propertyExp)) {
|
|
241
|
+
return new PrimitiveExpression(propertyExp.toString());
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
throw new WorkflowSyntaxError('Unexpected property in an optional chain', opt.property.loc);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
const args = [base];
|
|
248
|
+
if (optionals.length > 1) {
|
|
249
|
+
args.push(new PrimitiveExpression(optionals));
|
|
250
|
+
}
|
|
251
|
+
else if (optionals.length === 1) {
|
|
252
|
+
args.push(optionals[0]);
|
|
253
|
+
}
|
|
254
|
+
return args;
|
|
255
|
+
}
|
|
256
|
+
function memberExpressionFromList(properties) {
|
|
257
|
+
if (properties.length >= 2) {
|
|
258
|
+
const base = new MemberExpression(convertExpression(properties[0].property), convertExpression(properties[1].property), properties[1].computed);
|
|
259
|
+
return properties
|
|
260
|
+
.slice(2)
|
|
261
|
+
.reduce((exp, current) => new MemberExpression(exp, convertExpression(current.property), current.computed), base);
|
|
262
|
+
}
|
|
263
|
+
else if (properties.length === 1) {
|
|
264
|
+
return convertExpression(properties[0].property);
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
throw new InternalTranspilingError('Empty array in memberExpressionFromList()');
|
|
268
|
+
}
|
|
269
|
+
}
|
|
172
270
|
function convertCallExpression(node) {
|
|
173
|
-
|
|
271
|
+
if (node.optional) {
|
|
272
|
+
throw new WorkflowSyntaxError('Optional call expressions are not supported', node.loc);
|
|
273
|
+
}
|
|
174
274
|
const calleeExpression = convertExpression(node.callee);
|
|
175
275
|
if (isFullyQualifiedName(calleeExpression)) {
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
276
|
+
const calleeName = calleeExpression.toString();
|
|
277
|
+
if (isMagicFunction(calleeName)) {
|
|
278
|
+
let msg;
|
|
279
|
+
if (calleeName === 'call_step') {
|
|
280
|
+
msg =
|
|
281
|
+
'Calling call_step as part of an expression is not yet implemented';
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
msg = `"${calleeName}" can't be called as part of an expression`;
|
|
285
|
+
}
|
|
286
|
+
throw new WorkflowSyntaxError(msg, node.callee.loc);
|
|
287
|
+
}
|
|
288
|
+
const argumentExpressions = throwIfSpread(node.arguments).map(convertExpression);
|
|
289
|
+
return new FunctionInvocationExpression(calleeName, argumentExpressions);
|
|
179
290
|
}
|
|
180
291
|
else {
|
|
181
292
|
throw new WorkflowSyntaxError('Callee should be a qualified name', node.loc);
|
|
182
293
|
}
|
|
183
294
|
}
|
|
295
|
+
export function isMagicFunction(calleeName) {
|
|
296
|
+
const magicFunctions = ['parallel', 'retry_policy', 'call_step'];
|
|
297
|
+
return magicFunctions.includes(calleeName);
|
|
298
|
+
}
|
|
184
299
|
function convertConditionalExpression(node) {
|
|
185
|
-
assertType(node, ConditionalExpression);
|
|
186
300
|
const test = convertExpression(node.test);
|
|
187
301
|
const consequent = convertExpression(node.consequent);
|
|
188
302
|
const alternate = convertExpression(node.alternate);
|
|
189
303
|
return new FunctionInvocationExpression('if', [test, consequent, alternate]);
|
|
190
304
|
}
|
|
191
305
|
function convertTemplateLiteralToExpression(node) {
|
|
192
|
-
|
|
193
|
-
const elements = node.quasis;
|
|
194
|
-
const stringTerms = elements
|
|
306
|
+
const stringTerms = node.quasis
|
|
195
307
|
.map((x) => x.value.cooked)
|
|
196
308
|
.map((x) => new PrimitiveExpression(x));
|
|
197
|
-
const
|
|
198
|
-
const templateTerms = expressionNodes.map(convertExpression);
|
|
309
|
+
const templateTerms = node.expressions.map(convertExpression);
|
|
199
310
|
// interleave string parts and the expression parts starting with strings
|
|
200
311
|
const interleavedTerms = stringTerms
|
|
201
312
|
.slice(0, stringTerms.length - 1)
|
|
@@ -221,3 +332,11 @@ function convertTemplateLiteralToExpression(node) {
|
|
|
221
332
|
});
|
|
222
333
|
}
|
|
223
334
|
}
|
|
335
|
+
export function throwIfSpread(nodes) {
|
|
336
|
+
const unsupported = nodes.find((x) => x?.type === AST_NODE_TYPES.SpreadElement);
|
|
337
|
+
if (unsupported) {
|
|
338
|
+
throw new WorkflowSyntaxError('The spread syntax is not supported', unsupported.loc);
|
|
339
|
+
}
|
|
340
|
+
const argumentExpressions = nodes.filter((x) => x?.type !== AST_NODE_TYPES.SpreadElement);
|
|
341
|
+
return argumentExpressions;
|
|
342
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transpiler/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transpiler/index.ts"],"names":[],"mappings":"AAYA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAW9C"}
|