ts2workflows 0.1.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/LICENSE +22 -0
- package/README.md +82 -0
- package/dist/ast/expressions.d.ts +57 -0
- package/dist/ast/expressions.d.ts.map +1 -0
- package/dist/ast/expressions.js +300 -0
- package/dist/ast/stepnames.d.ts +9 -0
- package/dist/ast/stepnames.d.ts.map +1 -0
- package/dist/ast/stepnames.js +268 -0
- package/dist/ast/steps.d.ts +176 -0
- package/dist/ast/steps.d.ts.map +1 -0
- package/dist/ast/steps.js +534 -0
- package/dist/ast/validation.d.ts +20 -0
- package/dist/ast/validation.d.ts.map +1 -0
- package/dist/ast/validation.js +214 -0
- package/dist/ast/workflows.d.ts +28 -0
- package/dist/ast/workflows.d.ts.map +1 -0
- package/dist/ast/workflows.js +74 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +114 -0
- package/dist/errors.d.ts +18 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +12 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/transpiler/asserts.d.ts +7 -0
- package/dist/transpiler/asserts.d.ts.map +1 -0
- package/dist/transpiler/asserts.js +11 -0
- package/dist/transpiler/expressions.d.ts +6 -0
- package/dist/transpiler/expressions.d.ts.map +1 -0
- package/dist/transpiler/expressions.js +223 -0
- package/dist/transpiler/generated/functionMetadata.d.ts +2 -0
- package/dist/transpiler/generated/functionMetadata.d.ts.map +1 -0
- package/dist/transpiler/generated/functionMetadata.js +324 -0
- package/dist/transpiler/index.d.ts +2 -0
- package/dist/transpiler/index.d.ts.map +1 -0
- package/dist/transpiler/index.js +74 -0
- package/dist/transpiler/statements.d.ts +7 -0
- package/dist/transpiler/statements.d.ts.map +1 -0
- package/dist/transpiler/statements.js +533 -0
- package/dist/transpiler/transformations.d.ts +28 -0
- package/dist/transpiler/transformations.d.ts.map +1 -0
- package/dist/transpiler/transformations.js +461 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +3 -0
- package/language_reference.md +771 -0
- package/package.json +62 -0
- package/types/workflowslib.d.ts +714 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument */
|
|
2
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
3
|
+
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;
|
|
7
|
+
export function convertExpression(instance) {
|
|
8
|
+
const expOrPrimitive = convertExpressionOrPrimitive(instance);
|
|
9
|
+
if (isExpression(expOrPrimitive)) {
|
|
10
|
+
return expOrPrimitive;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return new PrimitiveExpression(expOrPrimitive);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function convertObjectExpression(node) {
|
|
17
|
+
assertType(node, ObjectExpression);
|
|
18
|
+
const properties = node.properties;
|
|
19
|
+
return Object.fromEntries(properties.map(({ key, value }) => {
|
|
20
|
+
let keyPrimitive;
|
|
21
|
+
if (key.type === Identifier) {
|
|
22
|
+
keyPrimitive = key.name;
|
|
23
|
+
}
|
|
24
|
+
else if (key.type === Literal) {
|
|
25
|
+
if (typeof key.value === 'string') {
|
|
26
|
+
keyPrimitive = key.value;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
throw new WorkflowSyntaxError(`Map keys must be identifiers or strings, encountered: ${typeof key.value}`, key.loc);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
throw new WorkflowSyntaxError(`Not implemented object key type: ${key.type}`, key.loc);
|
|
34
|
+
}
|
|
35
|
+
return [keyPrimitive, convertExpressionOrPrimitive(value)];
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
export function convertObjectAsExpressionValues(node) {
|
|
39
|
+
const primitiveOrExpArguments = convertObjectExpression(node);
|
|
40
|
+
// Convert Primitive values to PrimitiveExpressions
|
|
41
|
+
return Object.fromEntries(Object.entries(primitiveOrExpArguments).map(([key, val]) => {
|
|
42
|
+
const valEx = isExpression(val) ? val : new PrimitiveExpression(val);
|
|
43
|
+
return [key, valEx];
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
function convertExpressionOrPrimitive(instance) {
|
|
47
|
+
switch (instance.type) {
|
|
48
|
+
case ArrayExpression:
|
|
49
|
+
return instance.elements.map(convertExpressionOrPrimitive);
|
|
50
|
+
case ObjectExpression:
|
|
51
|
+
return convertObjectExpression(instance);
|
|
52
|
+
case Literal:
|
|
53
|
+
return instance.value;
|
|
54
|
+
case TemplateLiteral:
|
|
55
|
+
return convertTemplateLiteralToExpression(instance);
|
|
56
|
+
case Identifier:
|
|
57
|
+
if (instance.name === 'null' || instance.name === 'undefined') {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
else if (instance.name === 'True' || instance.name === 'TRUE') {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
else if (instance.name === 'False' || instance.name === 'FALSE') {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
return new VariableReferenceExpression(instance.name);
|
|
68
|
+
}
|
|
69
|
+
case AST_NODE_TYPES.UnaryExpression:
|
|
70
|
+
return convertUnaryExpression(instance);
|
|
71
|
+
case AST_NODE_TYPES.BinaryExpression:
|
|
72
|
+
case LogicalExpression:
|
|
73
|
+
return convertBinaryExpression(instance);
|
|
74
|
+
case AST_NODE_TYPES.MemberExpression:
|
|
75
|
+
return convertMemberExpression(instance);
|
|
76
|
+
case CallExpression:
|
|
77
|
+
return convertCallExpression(instance);
|
|
78
|
+
case ConditionalExpression:
|
|
79
|
+
return convertConditionalExpression(instance);
|
|
80
|
+
case TSAsExpression:
|
|
81
|
+
return convertExpressionOrPrimitive(instance.expression);
|
|
82
|
+
case AwaitExpression:
|
|
83
|
+
return convertExpressionOrPrimitive(instance.argument);
|
|
84
|
+
default:
|
|
85
|
+
throw new WorkflowSyntaxError(`Not implemented expression type: ${instance.type}`, instance.loc);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function convertBinaryExpression(instance) {
|
|
89
|
+
assertOneOfManyTypes(instance, [
|
|
90
|
+
AST_NODE_TYPES.BinaryExpression,
|
|
91
|
+
LogicalExpression,
|
|
92
|
+
]);
|
|
93
|
+
// Special case for nullish coalescing becuase the result is a function call
|
|
94
|
+
// expression, not a binary expression
|
|
95
|
+
if (instance.operator === '??') {
|
|
96
|
+
return nullishCoalescingExpression(instance.left, instance.right);
|
|
97
|
+
}
|
|
98
|
+
let op;
|
|
99
|
+
switch (instance.operator) {
|
|
100
|
+
case '+':
|
|
101
|
+
case '-':
|
|
102
|
+
case '*':
|
|
103
|
+
case '/':
|
|
104
|
+
case '%':
|
|
105
|
+
case '==':
|
|
106
|
+
case '!=':
|
|
107
|
+
case '>':
|
|
108
|
+
case '>=':
|
|
109
|
+
case '<':
|
|
110
|
+
case '<=':
|
|
111
|
+
case 'in':
|
|
112
|
+
op = instance.operator;
|
|
113
|
+
break;
|
|
114
|
+
case '===':
|
|
115
|
+
op = '==';
|
|
116
|
+
break;
|
|
117
|
+
case '!==':
|
|
118
|
+
op = '!=';
|
|
119
|
+
break;
|
|
120
|
+
case '&&':
|
|
121
|
+
op = 'and';
|
|
122
|
+
break;
|
|
123
|
+
case '||':
|
|
124
|
+
op = 'or';
|
|
125
|
+
break;
|
|
126
|
+
default:
|
|
127
|
+
throw new WorkflowSyntaxError(`Unsupported binary operator: ${instance.operator}`, instance.loc);
|
|
128
|
+
}
|
|
129
|
+
return new BinaryExpression(convertExpression(instance.left), op, convertExpression(instance.right));
|
|
130
|
+
}
|
|
131
|
+
function nullishCoalescingExpression(left, right) {
|
|
132
|
+
return new FunctionInvocationExpression('default', [
|
|
133
|
+
convertExpression(left),
|
|
134
|
+
convertExpression(right),
|
|
135
|
+
]);
|
|
136
|
+
}
|
|
137
|
+
function convertUnaryExpression(instance) {
|
|
138
|
+
assertType(instance, AST_NODE_TYPES.UnaryExpression);
|
|
139
|
+
if (instance.prefix === false) {
|
|
140
|
+
throw new WorkflowSyntaxError('only prefix unary operators are supported', instance.loc);
|
|
141
|
+
}
|
|
142
|
+
let op;
|
|
143
|
+
switch (instance.operator) {
|
|
144
|
+
case '+':
|
|
145
|
+
op = '+';
|
|
146
|
+
break;
|
|
147
|
+
case '-':
|
|
148
|
+
op = '-';
|
|
149
|
+
break;
|
|
150
|
+
case '!':
|
|
151
|
+
op = 'not';
|
|
152
|
+
break;
|
|
153
|
+
case 'void':
|
|
154
|
+
// Just evalute the side-effecting expression.
|
|
155
|
+
// This is wrong: the return value should be ignored.
|
|
156
|
+
op = undefined;
|
|
157
|
+
break;
|
|
158
|
+
case undefined:
|
|
159
|
+
op = undefined;
|
|
160
|
+
break;
|
|
161
|
+
default:
|
|
162
|
+
throw new WorkflowSyntaxError(`Unsupported unary operator: ${instance.operator}`, instance.loc);
|
|
163
|
+
}
|
|
164
|
+
const ex = convertExpression(instance.argument);
|
|
165
|
+
return op ? new UnaryExpression(op, ex) : ex;
|
|
166
|
+
}
|
|
167
|
+
export function convertMemberExpression(node) {
|
|
168
|
+
assertType(node, AST_NODE_TYPES.MemberExpression);
|
|
169
|
+
const object = convertExpression(node.object);
|
|
170
|
+
return new MemberExpression(object, convertExpression(node.property), node.computed);
|
|
171
|
+
}
|
|
172
|
+
function convertCallExpression(node) {
|
|
173
|
+
assertType(node, CallExpression);
|
|
174
|
+
const calleeExpression = convertExpression(node.callee);
|
|
175
|
+
if (isFullyQualifiedName(calleeExpression)) {
|
|
176
|
+
const nodeArguments = node.arguments;
|
|
177
|
+
const argumentExpressions = nodeArguments.map(convertExpression);
|
|
178
|
+
return new FunctionInvocationExpression(calleeExpression.toString(), argumentExpressions);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
throw new WorkflowSyntaxError('Callee should be a qualified name', node.loc);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function convertConditionalExpression(node) {
|
|
185
|
+
assertType(node, ConditionalExpression);
|
|
186
|
+
const test = convertExpression(node.test);
|
|
187
|
+
const consequent = convertExpression(node.consequent);
|
|
188
|
+
const alternate = convertExpression(node.alternate);
|
|
189
|
+
return new FunctionInvocationExpression('if', [test, consequent, alternate]);
|
|
190
|
+
}
|
|
191
|
+
function convertTemplateLiteralToExpression(node) {
|
|
192
|
+
assertType(node, TemplateLiteral);
|
|
193
|
+
const elements = node.quasis;
|
|
194
|
+
const stringTerms = elements
|
|
195
|
+
.map((x) => x.value.cooked)
|
|
196
|
+
.map((x) => new PrimitiveExpression(x));
|
|
197
|
+
const expressionNodes = node.expressions;
|
|
198
|
+
const templateTerms = expressionNodes.map(convertExpression);
|
|
199
|
+
// interleave string parts and the expression parts starting with strings
|
|
200
|
+
const interleavedTerms = stringTerms
|
|
201
|
+
.slice(0, stringTerms.length - 1)
|
|
202
|
+
.flatMap((stringTerm, i) => {
|
|
203
|
+
const combined = [stringTerm];
|
|
204
|
+
if (i < templateTerms.length) {
|
|
205
|
+
combined.push(templateTerms[i]);
|
|
206
|
+
}
|
|
207
|
+
return combined;
|
|
208
|
+
});
|
|
209
|
+
if (stringTerms[stringTerms.length - 1].value !== '') {
|
|
210
|
+
interleavedTerms.push(stringTerms[stringTerms.length - 1]);
|
|
211
|
+
}
|
|
212
|
+
if (interleavedTerms.length === 0) {
|
|
213
|
+
return new PrimitiveExpression('');
|
|
214
|
+
}
|
|
215
|
+
else if (interleavedTerms.length === 1) {
|
|
216
|
+
return interleavedTerms[0];
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
return interleavedTerms.reduce((previous, current) => {
|
|
220
|
+
return new BinaryExpression(previous, '+', current);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functionMetadata.d.ts","sourceRoot":"","sources":["../../../src/transpiler/generated/functionMetadata.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,iBAAiB,uBAiU5B,CAAA"}
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
// This is a generated file, do not modify!
|
|
2
|
+
// Blocking function names and argument names
|
|
3
|
+
export const blockingFunctions = new Map([
|
|
4
|
+
[
|
|
5
|
+
"events.await_callback",
|
|
6
|
+
[
|
|
7
|
+
"callback",
|
|
8
|
+
"timeout"
|
|
9
|
+
]
|
|
10
|
+
],
|
|
11
|
+
[
|
|
12
|
+
"http.delete",
|
|
13
|
+
[
|
|
14
|
+
"url",
|
|
15
|
+
"timeout",
|
|
16
|
+
"body",
|
|
17
|
+
"headers",
|
|
18
|
+
"query",
|
|
19
|
+
"auth",
|
|
20
|
+
"private_service_name",
|
|
21
|
+
"ca_certificate"
|
|
22
|
+
]
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
"http.get",
|
|
26
|
+
[
|
|
27
|
+
"url",
|
|
28
|
+
"timeout",
|
|
29
|
+
"headers",
|
|
30
|
+
"query",
|
|
31
|
+
"auth",
|
|
32
|
+
"private_service_name",
|
|
33
|
+
"ca_certificate"
|
|
34
|
+
]
|
|
35
|
+
],
|
|
36
|
+
[
|
|
37
|
+
"http.patch",
|
|
38
|
+
[
|
|
39
|
+
"url",
|
|
40
|
+
"timeout",
|
|
41
|
+
"body",
|
|
42
|
+
"headers",
|
|
43
|
+
"query",
|
|
44
|
+
"auth",
|
|
45
|
+
"private_service_name",
|
|
46
|
+
"ca_certificate"
|
|
47
|
+
]
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
"http.post",
|
|
51
|
+
[
|
|
52
|
+
"url",
|
|
53
|
+
"timeout",
|
|
54
|
+
"body",
|
|
55
|
+
"headers",
|
|
56
|
+
"query",
|
|
57
|
+
"auth",
|
|
58
|
+
"private_service_name",
|
|
59
|
+
"ca_certificate"
|
|
60
|
+
]
|
|
61
|
+
],
|
|
62
|
+
[
|
|
63
|
+
"http.put",
|
|
64
|
+
[
|
|
65
|
+
"url",
|
|
66
|
+
"timeout",
|
|
67
|
+
"body",
|
|
68
|
+
"headers",
|
|
69
|
+
"query",
|
|
70
|
+
"auth",
|
|
71
|
+
"private_service_name",
|
|
72
|
+
"ca_certificate"
|
|
73
|
+
]
|
|
74
|
+
],
|
|
75
|
+
[
|
|
76
|
+
"http.request",
|
|
77
|
+
[
|
|
78
|
+
"method",
|
|
79
|
+
"url",
|
|
80
|
+
"timeout",
|
|
81
|
+
"body",
|
|
82
|
+
"headers",
|
|
83
|
+
"query",
|
|
84
|
+
"auth",
|
|
85
|
+
"private_service_name",
|
|
86
|
+
"ca_certificate"
|
|
87
|
+
]
|
|
88
|
+
],
|
|
89
|
+
[
|
|
90
|
+
"sys.log",
|
|
91
|
+
[
|
|
92
|
+
"data",
|
|
93
|
+
"severity",
|
|
94
|
+
"text",
|
|
95
|
+
"json",
|
|
96
|
+
"timeout"
|
|
97
|
+
]
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
"sys.sleep",
|
|
101
|
+
[
|
|
102
|
+
"seconds"
|
|
103
|
+
]
|
|
104
|
+
],
|
|
105
|
+
[
|
|
106
|
+
"sys.sleep_until",
|
|
107
|
+
[
|
|
108
|
+
"time"
|
|
109
|
+
]
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
"googleapis.firestore.v1.projects.databases.exportDocuments",
|
|
113
|
+
[
|
|
114
|
+
"name",
|
|
115
|
+
"body"
|
|
116
|
+
]
|
|
117
|
+
],
|
|
118
|
+
[
|
|
119
|
+
"googleapis.firestore.v1.projects.databases.importDocuments",
|
|
120
|
+
[
|
|
121
|
+
"name",
|
|
122
|
+
"body"
|
|
123
|
+
]
|
|
124
|
+
],
|
|
125
|
+
[
|
|
126
|
+
"googleapis.firestore.v1.projects.databases.collectionGroups.fields.get",
|
|
127
|
+
[
|
|
128
|
+
"name"
|
|
129
|
+
]
|
|
130
|
+
],
|
|
131
|
+
[
|
|
132
|
+
"googleapis.firestore.v1.projects.databases.collectionGroups.fields.list",
|
|
133
|
+
[
|
|
134
|
+
"parent",
|
|
135
|
+
"filter",
|
|
136
|
+
"pageSize",
|
|
137
|
+
"pageToken"
|
|
138
|
+
]
|
|
139
|
+
],
|
|
140
|
+
[
|
|
141
|
+
"googleapis.firestore.v1.projects.databases.collectionGroups.fields.patch",
|
|
142
|
+
[
|
|
143
|
+
"name",
|
|
144
|
+
"updateMask",
|
|
145
|
+
"body"
|
|
146
|
+
]
|
|
147
|
+
],
|
|
148
|
+
[
|
|
149
|
+
"googleapis.firestore.v1.projects.databases.collectionGroups.indexes.create",
|
|
150
|
+
[
|
|
151
|
+
"parent",
|
|
152
|
+
"body"
|
|
153
|
+
]
|
|
154
|
+
],
|
|
155
|
+
[
|
|
156
|
+
"googleapis.firestore.v1.projects.databases.collectionGroups.indexes.delete",
|
|
157
|
+
[
|
|
158
|
+
"name"
|
|
159
|
+
]
|
|
160
|
+
],
|
|
161
|
+
[
|
|
162
|
+
"googleapis.firestore.v1.projects.databases.collectionGroups.indexes.get",
|
|
163
|
+
[
|
|
164
|
+
"name"
|
|
165
|
+
]
|
|
166
|
+
],
|
|
167
|
+
[
|
|
168
|
+
"googleapis.firestore.v1.projects.databases.collectionGroups.indexes.list",
|
|
169
|
+
[
|
|
170
|
+
"parent",
|
|
171
|
+
"filter",
|
|
172
|
+
"pageSize",
|
|
173
|
+
"pageToken"
|
|
174
|
+
]
|
|
175
|
+
],
|
|
176
|
+
[
|
|
177
|
+
"googleapis.firestore.v1.projects.databases.documents.batchGet",
|
|
178
|
+
[
|
|
179
|
+
"database",
|
|
180
|
+
"body"
|
|
181
|
+
]
|
|
182
|
+
],
|
|
183
|
+
[
|
|
184
|
+
"googleapis.firestore.v1.projects.databases.documents.batchWrite",
|
|
185
|
+
[
|
|
186
|
+
"database",
|
|
187
|
+
"body"
|
|
188
|
+
]
|
|
189
|
+
],
|
|
190
|
+
[
|
|
191
|
+
"googleapis.firestore.v1.projects.databases.documents.beginTransaction",
|
|
192
|
+
[
|
|
193
|
+
"database",
|
|
194
|
+
"body"
|
|
195
|
+
]
|
|
196
|
+
],
|
|
197
|
+
[
|
|
198
|
+
"googleapis.firestore.v1.projects.databases.documents.commit",
|
|
199
|
+
[
|
|
200
|
+
"database",
|
|
201
|
+
"body"
|
|
202
|
+
]
|
|
203
|
+
],
|
|
204
|
+
[
|
|
205
|
+
"googleapis.firestore.v1.projects.databases.documents.createDocument",
|
|
206
|
+
[
|
|
207
|
+
"collectionId",
|
|
208
|
+
"parent",
|
|
209
|
+
"body",
|
|
210
|
+
"documentId",
|
|
211
|
+
"mask"
|
|
212
|
+
]
|
|
213
|
+
],
|
|
214
|
+
[
|
|
215
|
+
"googleapis.firestore.v1.projects.databases.documents.delete",
|
|
216
|
+
[
|
|
217
|
+
"name",
|
|
218
|
+
"currentDocument"
|
|
219
|
+
]
|
|
220
|
+
],
|
|
221
|
+
[
|
|
222
|
+
"googleapis.firestore.v1.projects.databases.documents.get",
|
|
223
|
+
[
|
|
224
|
+
"name",
|
|
225
|
+
"mask",
|
|
226
|
+
"readTime",
|
|
227
|
+
"transaction"
|
|
228
|
+
]
|
|
229
|
+
],
|
|
230
|
+
[
|
|
231
|
+
"googleapis.firestore.v1.projects.databases.documents.list",
|
|
232
|
+
[
|
|
233
|
+
"collectionId",
|
|
234
|
+
"parent",
|
|
235
|
+
"mask",
|
|
236
|
+
"orderBy",
|
|
237
|
+
"pageSize",
|
|
238
|
+
"pageToken",
|
|
239
|
+
"readTime",
|
|
240
|
+
"showMissing",
|
|
241
|
+
"transaction"
|
|
242
|
+
]
|
|
243
|
+
],
|
|
244
|
+
[
|
|
245
|
+
"googleapis.firestore.v1.projects.databases.documents.listCollectionIds",
|
|
246
|
+
[
|
|
247
|
+
"parent",
|
|
248
|
+
"body"
|
|
249
|
+
]
|
|
250
|
+
],
|
|
251
|
+
[
|
|
252
|
+
"googleapis.firestore.v1.projects.databases.documents.partitionQuery",
|
|
253
|
+
[
|
|
254
|
+
"parent",
|
|
255
|
+
"body"
|
|
256
|
+
]
|
|
257
|
+
],
|
|
258
|
+
[
|
|
259
|
+
"googleapis.firestore.v1.projects.databases.documents.patch",
|
|
260
|
+
[
|
|
261
|
+
"name",
|
|
262
|
+
"currentDocument",
|
|
263
|
+
"mask",
|
|
264
|
+
"updateMask",
|
|
265
|
+
"body"
|
|
266
|
+
]
|
|
267
|
+
],
|
|
268
|
+
[
|
|
269
|
+
"googleapis.firestore.v1.projects.databases.documents.rollback",
|
|
270
|
+
[
|
|
271
|
+
"database",
|
|
272
|
+
"body"
|
|
273
|
+
]
|
|
274
|
+
],
|
|
275
|
+
[
|
|
276
|
+
"googleapis.firestore.v1.projects.databases.documents.runQuery",
|
|
277
|
+
[
|
|
278
|
+
"parent",
|
|
279
|
+
"body"
|
|
280
|
+
]
|
|
281
|
+
],
|
|
282
|
+
[
|
|
283
|
+
"googleapis.firestore.v1.projects.databases.operations.cancel",
|
|
284
|
+
[
|
|
285
|
+
"name"
|
|
286
|
+
]
|
|
287
|
+
],
|
|
288
|
+
[
|
|
289
|
+
"googleapis.firestore.v1.projects.databases.operations.delete",
|
|
290
|
+
[
|
|
291
|
+
"name"
|
|
292
|
+
]
|
|
293
|
+
],
|
|
294
|
+
[
|
|
295
|
+
"googleapis.firestore.v1.projects.databases.operations.get",
|
|
296
|
+
[
|
|
297
|
+
"name"
|
|
298
|
+
]
|
|
299
|
+
],
|
|
300
|
+
[
|
|
301
|
+
"googleapis.firestore.v1.projects.databases.operations.list",
|
|
302
|
+
[
|
|
303
|
+
"name",
|
|
304
|
+
"filter",
|
|
305
|
+
"pageSize",
|
|
306
|
+
"pageToken"
|
|
307
|
+
]
|
|
308
|
+
],
|
|
309
|
+
[
|
|
310
|
+
"googleapis.firestore.v1.projects.locations.get",
|
|
311
|
+
[
|
|
312
|
+
"name"
|
|
313
|
+
]
|
|
314
|
+
],
|
|
315
|
+
[
|
|
316
|
+
"googleapis.firestore.v1.projects.locations.list",
|
|
317
|
+
[
|
|
318
|
+
"name",
|
|
319
|
+
"filter",
|
|
320
|
+
"pageSize",
|
|
321
|
+
"pageToken"
|
|
322
|
+
]
|
|
323
|
+
]
|
|
324
|
+
]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transpiler/index.ts"],"names":[],"mappings":"AAyBA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAa9C"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument */
|
|
2
|
+
import * as parser from '@typescript-eslint/typescript-estree';
|
|
3
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
4
|
+
import * as YAML from 'yaml';
|
|
5
|
+
import { SubworkflowAST } from '../ast/steps.js';
|
|
6
|
+
import { WorkflowSyntaxError } from '../errors.js';
|
|
7
|
+
import { generateStepNames } from '../ast/stepnames.js';
|
|
8
|
+
import { assertType } from './asserts.js';
|
|
9
|
+
import { parseBlockStatement } from './statements.js';
|
|
10
|
+
const { AssignmentPattern, ExportNamedDeclaration, FunctionDeclaration, Identifier, ImportDeclaration, ImportDefaultSpecifier, ImportNamespaceSpecifier, Literal, Program, TSTypeAliasDeclaration, TSInterfaceDeclaration, } = AST_NODE_TYPES;
|
|
11
|
+
export function transpile(code) {
|
|
12
|
+
const parserOptions = {
|
|
13
|
+
jsDocParsingMode: 'none',
|
|
14
|
+
loc: true,
|
|
15
|
+
range: false,
|
|
16
|
+
};
|
|
17
|
+
const ast = parser.parse(code, parserOptions);
|
|
18
|
+
assertType(ast, Program);
|
|
19
|
+
const workflowAst = { subworkflows: ast.body.flatMap(parseTopLevelStatement) };
|
|
20
|
+
const workflow = generateStepNames(workflowAst);
|
|
21
|
+
return YAML.stringify(workflow.render(), { lineWidth: 100 });
|
|
22
|
+
}
|
|
23
|
+
function parseTopLevelStatement(node) {
|
|
24
|
+
switch (node?.type) {
|
|
25
|
+
case FunctionDeclaration:
|
|
26
|
+
return [parseSubworkflows(node)];
|
|
27
|
+
case ImportDeclaration:
|
|
28
|
+
if (node.specifiers.some((spec) => spec.type === ImportNamespaceSpecifier ||
|
|
29
|
+
spec.type === ImportDefaultSpecifier)) {
|
|
30
|
+
throw new WorkflowSyntaxError('Only named imports are allowed', node.loc);
|
|
31
|
+
}
|
|
32
|
+
return [];
|
|
33
|
+
case ExportNamedDeclaration:
|
|
34
|
+
// "export" keyword is ignored, but a possible function declaration is transpiled.
|
|
35
|
+
if (node?.declaration) {
|
|
36
|
+
return parseTopLevelStatement(node.declaration);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
case TSInterfaceDeclaration:
|
|
42
|
+
case TSTypeAliasDeclaration:
|
|
43
|
+
// Ignore "type" and "interface" declarations at the top-level
|
|
44
|
+
return [];
|
|
45
|
+
default:
|
|
46
|
+
throw new WorkflowSyntaxError(`Only function declarations, imports and type aliases allowed at the top level, encountered ${node?.type}`, node?.loc);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function parseSubworkflows(node) {
|
|
50
|
+
assertType(node, FunctionDeclaration);
|
|
51
|
+
if (node.id.type !== Identifier) {
|
|
52
|
+
throw new WorkflowSyntaxError('Expected Identifier as a function name', node.id.loc);
|
|
53
|
+
}
|
|
54
|
+
const nodeParams = node.params;
|
|
55
|
+
const workflowParams = nodeParams.map((param) => {
|
|
56
|
+
switch (param.type) {
|
|
57
|
+
case Identifier:
|
|
58
|
+
return { name: param.name };
|
|
59
|
+
case AssignmentPattern:
|
|
60
|
+
assertType(param.left, Identifier);
|
|
61
|
+
if (param.right.type !== Literal) {
|
|
62
|
+
throw new WorkflowSyntaxError('The default value must be a literal', param.right.loc);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
name: param.left.name,
|
|
66
|
+
default: param.right.value,
|
|
67
|
+
};
|
|
68
|
+
default:
|
|
69
|
+
throw new WorkflowSyntaxError('Function parameter must be an identifier or an assignment', param.loc);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const steps = parseBlockStatement(node.body, {});
|
|
73
|
+
return new SubworkflowAST(node.id.name, steps, workflowParams);
|
|
74
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { StepName, WorkflowStepAST } from '../ast/steps.js';
|
|
2
|
+
export interface ParsingContext {
|
|
3
|
+
breakTarget?: StepName;
|
|
4
|
+
continueTarget?: StepName;
|
|
5
|
+
}
|
|
6
|
+
export declare function parseBlockStatement(node: any, ctx: ParsingContext): WorkflowStepAST[];
|
|
7
|
+
//# sourceMappingURL=statements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statements.d.ts","sourceRoot":"","sources":["../../src/transpiler/statements.ts"],"names":[],"mappings":"AAEA,OAAO,EASL,QAAQ,EAOR,eAAe,EAEhB,MAAM,iBAAiB,CAAA;AAwDxB,MAAM,WAAW,cAAc;IAE7B,WAAW,CAAC,EAAE,QAAQ,CAAA;IAEtB,cAAc,CAAC,EAAE,QAAQ,CAAA;CAC1B;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,GAAG,EACT,GAAG,EAAE,cAAc,GAClB,eAAe,EAAE,CAKnB"}
|