ts2workflows 0.7.0 → 0.9.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/README.md +8 -2
- package/dist/ast/expressions.d.ts +9 -0
- package/dist/ast/expressions.d.ts.map +1 -1
- package/dist/ast/expressions.js +43 -19
- package/dist/ast/steps.d.ts +27 -7
- package/dist/ast/steps.d.ts.map +1 -1
- package/dist/ast/steps.js +104 -21
- package/dist/cli.js +85 -28
- package/dist/transpiler/expressions.d.ts +0 -1
- package/dist/transpiler/expressions.d.ts.map +1 -1
- package/dist/transpiler/expressions.js +52 -61
- package/dist/transpiler/index.d.ts +1 -1
- package/dist/transpiler/index.d.ts.map +1 -1
- package/dist/transpiler/index.js +16 -7
- package/dist/transpiler/statements.d.ts +4 -3
- package/dist/transpiler/statements.d.ts.map +1 -1
- package/dist/transpiler/statements.js +379 -103
- package/dist/transpiler/transformations.d.ts +0 -6
- package/dist/transpiler/transformations.d.ts.map +1 -1
- package/dist/transpiler/transformations.js +88 -148
- package/dist/utils.d.ts +1 -5
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +3 -16
- package/language_reference.md +120 -61
- package/package.json +9 -5
package/language_reference.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# Language reference
|
|
2
2
|
|
|
3
|
-
ts2workflow converts Typescript source code to GCP Workflows YAML syntax. Only a subset of Typescript language features are supported. This page documents supported Typescript features and shows examples of
|
|
3
|
+
ts2workflow converts Typescript source code to GCP Workflows YAML syntax. Only a subset of Typescript language features are supported. This page documents supported Typescript features and shows examples of how Typescript code snippets look when converted to Workflows YAML.
|
|
4
4
|
|
|
5
5
|
Most functions provided by a Javascript runtime (`console.log()`, `setInterval()`, etc) are not available.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
One of the benefits of writing workflows on Typescript is that the source code can be type checked and potential, and potential problems can be caught early. Type checking can be done with the standard Typescript compiler tsc. ts2workflows itself ignores all types, and types don't affect the generated Workflows YAML.
|
|
8
8
|
|
|
9
9
|
Semicolon can be used as optional statement delimitter.
|
|
10
10
|
|
|
11
|
-
⚠️ Semantics of certain operations are different from Typescript semantics. These differences are highlighted with the warning icon ⚠️ on this documentation.
|
|
11
|
+
⚠️ Semantics of certain operations in GCP Workflows are different from Typescript semantics. These differences are highlighted with the warning icon ⚠️ on this documentation.
|
|
12
12
|
|
|
13
13
|
## Data types
|
|
14
14
|
|
|
@@ -22,7 +22,7 @@ Semicolon can be used as optional statement delimitter.
|
|
|
22
22
|
|
|
23
23
|
### Array type
|
|
24
24
|
|
|
25
|
-
⚠️ Arrays are not objects. In particular, methods like `[].map()` and `[].concat()` are not available.
|
|
25
|
+
⚠️ Arrays are not objects in GCP Workflows. In particular, methods like `[].map()` and `[].concat()` are not available.
|
|
26
26
|
|
|
27
27
|
⚠️ Accessing out-of-bounds index will cause an IndexError at runtime unlike in Typescript where out-of-bounds access would return `undefined`.
|
|
28
28
|
|
|
@@ -34,19 +34,19 @@ Map keys can be identifiers or strings: `{temperature: -12}` or `{"temperature":
|
|
|
34
34
|
|
|
35
35
|
### Bytes type
|
|
36
36
|
|
|
37
|
-
A `bytes` object can only be constructed by calling a function that returns bytes (e.g. `base64.decode`). The only things that can be done with a `bytes` object is to assign it to variable and to pass the `bytes` object to one of the functions that take `bytes` type as input variable (e.g. `base64.encode`).
|
|
37
|
+
A `bytes` object can only be constructed by calling a function that returns `bytes` (e.g. `base64.decode`). The only things that can be done with a `bytes` object is to assign it to variable and to pass the `bytes` object to one of the functions that take `bytes` type as input variable (e.g. `base64.encode`).
|
|
38
38
|
|
|
39
39
|
### null type
|
|
40
40
|
|
|
41
|
-
In addition to the literal `null`, the Typescript `undefined`
|
|
41
|
+
`null` is used to signify absence of a value. In addition to the literal `null`, ts2workflows also translates the Typescript `undefined` to `null` in Workflows YAML output.
|
|
42
42
|
|
|
43
|
-
Note that
|
|
43
|
+
Note that `null` and `undefined` still are distinct types on the type checking step.
|
|
44
44
|
|
|
45
45
|
### Implicit type conversions
|
|
46
46
|
|
|
47
47
|
Expressions that combine variables with operators such as `+`, `>`, `==` perform implict type conversions according to the [rules listed on GCP Workflows documentation](https://cloud.google.com/workflows/docs/reference/syntax/datatypes#implicit-conversions). For example, applying `+` to a string and a number concatenates the values into a string.
|
|
48
48
|
|
|
49
|
-
⚠️ Checking if a variable is null or not must be done by an explicit comparison: `if (var != null) {...}`. Relying
|
|
49
|
+
⚠️ Checking if a variable is null or not must be done by an explicit comparison: `if (var != null) {...}`. Relying on an implicit conversion (`if (var) {...}` where `var` is not a boolean) results in a TypeError at runtime.
|
|
50
50
|
|
|
51
51
|
## Expressions
|
|
52
52
|
|
|
@@ -66,68 +66,68 @@ sys.get_env('GOOGLE_CLOUD_PROJECT_ID')
|
|
|
66
66
|
|
|
67
67
|
## Operators
|
|
68
68
|
|
|
69
|
-
| Operator | Description
|
|
70
|
-
| ------------ |
|
|
71
|
-
| + | arithmetic addition and string concatenation
|
|
72
|
-
| - | arithmetic subtraction or unary negation
|
|
73
|
-
| \* | multiplication
|
|
74
|
-
| / | float division
|
|
75
|
-
| % | remainder division
|
|
76
|
-
| ==, === | equal to (both mean strict equality)
|
|
77
|
-
| !=, !== | not equal to (both mean strict equality)
|
|
78
|
-
| <, >, <=, >= | inequality comparisons
|
|
79
|
-
| &&, \|\|, ! | logical
|
|
80
|
-
| in | check if a property is present in an object
|
|
81
|
-
| ?? | nullish coalescing
|
|
82
|
-
| ?. | optional chaining
|
|
83
|
-
| ? : | conditional operator
|
|
84
|
-
| typeof | return
|
|
69
|
+
| Operator | Description |
|
|
70
|
+
| ------------ | -------------------------------------------------- |
|
|
71
|
+
| + | arithmetic addition and string concatenation |
|
|
72
|
+
| - | arithmetic subtraction or unary negation |
|
|
73
|
+
| \* | multiplication |
|
|
74
|
+
| / | float division |
|
|
75
|
+
| % | remainder division |
|
|
76
|
+
| ==, === | equal to (both mean strict equality) |
|
|
77
|
+
| !=, !== | not equal to (both mean strict equality) |
|
|
78
|
+
| <, >, <=, >= | inequality comparisons |
|
|
79
|
+
| &&, \|\|, ! | logical and, or, not |
|
|
80
|
+
| in | check if a property is present in an object |
|
|
81
|
+
| ?? | nullish coalescing |
|
|
82
|
+
| ?. | optional chaining |
|
|
83
|
+
| ? : | conditional operator |
|
|
84
|
+
| typeof | return a string representation of the operand type |
|
|
85
85
|
|
|
86
86
|
The [precendence order of operators](https://cloud.google.com/workflows/docs/reference/syntax/datatypes#order-operations) is the same as in GCP Workflows.
|
|
87
87
|
|
|
88
|
-
See [
|
|
88
|
+
See [the GCP documentation about expressions](https://cloud.google.com/workflows/docs/reference/syntax/expressions) for more information.
|
|
89
89
|
|
|
90
90
|
### Conditional (ternary) operator
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
ts2workflows converts the Typescript expression
|
|
93
93
|
|
|
94
94
|
```javascript
|
|
95
95
|
x > 0 ? 'positive' : 'not positive'
|
|
96
96
|
```
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
to an [if() expression](https://cloud.google.com/workflows/docs/reference/stdlib/expression-helpers#conditional_functions):
|
|
99
99
|
|
|
100
100
|
```yaml
|
|
101
101
|
${if(x > 0, "positive", "not positive")}
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
⚠️ Workflows always evaluates both
|
|
104
|
+
⚠️ Workflows always evaluates both branches unlike Typescript which evaluates only the branch that gets executed.
|
|
105
105
|
|
|
106
106
|
### Nullish coalescing operator
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
ts2workflows converts, the Typescript expression
|
|
109
109
|
|
|
110
110
|
```javascript
|
|
111
111
|
x ?? 'default value'
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
to a [default() expression](https://cloud.google.com/workflows/docs/reference/stdlib/expression-helpers#conditional_functions):
|
|
115
115
|
|
|
116
116
|
```yaml
|
|
117
117
|
${default(x, "default value")}
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
-
⚠️ Workflows always evaluates the right-hand side expression
|
|
120
|
+
⚠️ Workflows always evaluates the right-hand side expression. This is different from Typescript, which evaluates the right-hand side only if the left-hand side is `null` or `undefined`.
|
|
121
121
|
|
|
122
122
|
### Optional chaining
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
ts2workflows converte the Typescript optional chaining expression
|
|
125
125
|
|
|
126
126
|
```javascript
|
|
127
127
|
data.user?.name
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
to a [map.get() expression](https://cloud.google.com/workflows/docs/reference/stdlib/map/get):
|
|
131
131
|
|
|
132
132
|
```yaml
|
|
133
133
|
${map.get(data, ["user", "name"])}
|
|
@@ -152,21 +152,21 @@ The typeof operator is useful as a type guard in Typescript (e.g. `typeof x ===
|
|
|
152
152
|
|
|
153
153
|
## Template literals
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
String literals can include interpolated variables. The syntax is same as in Typescript. For example, `Hello ${name}`.
|
|
156
156
|
|
|
157
157
|
⚠️ Interpolated values can (only) be numbers, strings, booleans or nulls. Other types will throw a TypeError at runtime.
|
|
158
158
|
|
|
159
159
|
## Subworkflow definitions
|
|
160
160
|
|
|
161
|
-
Typescript `function`s
|
|
161
|
+
ts2workflows converts Typescript `function`s to subworkflow definitions.
|
|
162
162
|
|
|
163
|
-
The program code must be written inside
|
|
163
|
+
The program code must be written inside functions. Only `function` and `import` declarations are allowed on the top level of a source code file. Functions can only be defined at the top level of a source file, not inside other functions.
|
|
164
164
|
|
|
165
165
|
The workflow execution starts from the subworkflow called "main".
|
|
166
166
|
|
|
167
167
|
```typescript
|
|
168
168
|
function main(): void {
|
|
169
|
-
const a =
|
|
169
|
+
const a = anotherWorkflow()
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
function anotherWorkflow(): number {
|
|
@@ -213,13 +213,13 @@ return firstFactor * secondFactor
|
|
|
213
213
|
|
|
214
214
|
## Calling functions and subworkflows
|
|
215
215
|
|
|
216
|
-
|
|
216
|
+
ts2workflows converts the Typescript statement
|
|
217
217
|
|
|
218
218
|
```typescript
|
|
219
219
|
const projectId = sys.get_env('GOOGLE_CLOUD_PROJECT_ID')
|
|
220
220
|
```
|
|
221
221
|
|
|
222
|
-
|
|
222
|
+
to an [assign step](https://cloud.google.com/workflows/docs/reference/syntax/variables#assign-step):
|
|
223
223
|
|
|
224
224
|
```yaml
|
|
225
225
|
- assign1:
|
|
@@ -227,11 +227,11 @@ is converted to an [assign step](https://cloud.google.com/workflows/docs/referen
|
|
|
227
227
|
- projectId: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
|
|
228
228
|
```
|
|
229
229
|
|
|
230
|
-
This syntax can be used to call [standard library functions](https://cloud.google.com/workflows/docs/reference/stdlib/overview)
|
|
230
|
+
This syntax can be used to call subworkflows (defined with the `function` keyword), [standard library functions](https://cloud.google.com/workflows/docs/reference/stdlib/overview) or connectors. Note that Javascript runtime functions (such as `fetch()`, `console.error()` or `new XMLHttpRequest()`) are not available on Workflows.
|
|
231
231
|
|
|
232
|
-
GCP Workflows language has two ways of calling functions and subworkflows: as
|
|
232
|
+
GCP Workflows language has two ways of calling functions and subworkflows: as an function call expression or as [call step](https://cloud.google.com/workflows/docs/reference/syntax/calls). They can mostly be used interchangeably. However, [blocking calls](https://cloud.google.com/workflows/docs/reference/syntax/expressions#blocking-calls) must be made as call steps. ts2workflows tries to automatically output a call step when necessary.
|
|
233
233
|
|
|
234
|
-
It is also possible to force a function to be called as call step. This might be useful, if
|
|
234
|
+
It is also possible to force a function to be called as call step. This might be useful, if ts2workflows fails to output call step when it should, or if you want to use named parameters. For example, the following Typescript program
|
|
235
235
|
|
|
236
236
|
```typescript
|
|
237
237
|
import { call_step, sys } from 'ts2workflows/types/workflowslib'
|
|
@@ -292,6 +292,62 @@ is converted to
|
|
|
292
292
|
- total: ${total + 1}
|
|
293
293
|
```
|
|
294
294
|
|
|
295
|
+
## Destructuring
|
|
296
|
+
|
|
297
|
+
Array destructuring unpacks values from an array or an array expression into variables. The following statements assign the first two values from `arr` to variables `a` and `b`, that is `a` will be `1` and `b` will be `2`.
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
const arr = [1, 2, 3]
|
|
301
|
+
const [a, b] = arr
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
Object destructuring unpacks property values from an object into variables. The following statements initializes the variable `person` to `"Bean"` and the variable `name` to the value `"Dreamland"`.
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
const data = { person: 'Bean', country: { name: 'Dreamland' } }
|
|
308
|
+
const {
|
|
309
|
+
person,
|
|
310
|
+
country: { name },
|
|
311
|
+
} = data
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
Array elements can be skipped:
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
const arr = [1, 2, 3]
|
|
318
|
+
const [a, , b] = arr
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
If there are more output variables than elements in the input array, the surplus variables are set to `null`. For example, in the following sample, `a` will be 1 and `b` will be `null`.
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
const arr = [1]
|
|
325
|
+
const [a, b] = arr
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
Assignments can have default values:
|
|
329
|
+
|
|
330
|
+
```typescript
|
|
331
|
+
const arr = [1]
|
|
332
|
+
const [a, b = 99] = arr
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
⚠️ Setting surplus variables to `null` is different from TypeScript in cases where an array is destructured to elements of itself. The snippet `let arr = [4]; [arr[1], arr[0]] = arr;` will set `arr` to `[null, 4]` in ts2workflows, whereas in TypeScript `arr` would be `[4, 4]`.
|
|
336
|
+
|
|
337
|
+
The destructuring pattern can end with a rest property `...rest`. The unreferenced array elements are collected to an array called `rest`. The following sample code initializes the variable `rest` to `[3, 4, 5]`.
|
|
338
|
+
|
|
339
|
+
```typescript
|
|
340
|
+
const arr = [1, 2, 3, 4, 5]
|
|
341
|
+
const [a, b, ...rest] = arr
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
The rest element can be used also in object destructuring to capture unreferenced properties.
|
|
345
|
+
|
|
346
|
+
```typescript
|
|
347
|
+
const data = { person: 'Bean', country: { name: 'Dreamland' } }
|
|
348
|
+
const { person, ...otherProperties } = data
|
|
349
|
+
```
|
|
350
|
+
|
|
295
351
|
## Conditional statements
|
|
296
352
|
|
|
297
353
|
The statement
|
|
@@ -337,7 +393,7 @@ is converted to a [switch step](https://cloud.google.com/workflows/docs/referenc
|
|
|
337
393
|
|
|
338
394
|
## Switch statements
|
|
339
395
|
|
|
340
|
-
Typescript switch statements are
|
|
396
|
+
Typescript switch statements are converted to chains of conditions. For example, this statement
|
|
341
397
|
|
|
342
398
|
```typescript
|
|
343
399
|
let b
|
|
@@ -470,7 +526,7 @@ for (i of [1, 2, 3, 4]) {
|
|
|
470
526
|
|
|
471
527
|
## Parallel branches
|
|
472
528
|
|
|
473
|
-
|
|
529
|
+
A special intrinsic `parallel` can be used to execute code branches in parallel. The code blocks to be executed in parallel are given as an array of `() => void` functions. For example, the following code
|
|
474
530
|
|
|
475
531
|
```javascript
|
|
476
532
|
parallel([
|
|
@@ -518,7 +574,7 @@ The branches can also be subworkflow names:
|
|
|
518
574
|
parallel([my_subworkflow1, my_subworkflow2, my_subworklfow3])
|
|
519
575
|
```
|
|
520
576
|
|
|
521
|
-
An optional second parameter is an object that can define shared variables and concurrency limits
|
|
577
|
+
An optional second parameter is an object that can define shared variables and concurrency limits. See the GCP documentation for more information.
|
|
522
578
|
|
|
523
579
|
```javascript
|
|
524
580
|
let numPosts = 0
|
|
@@ -601,7 +657,7 @@ try {
|
|
|
601
657
|
}
|
|
602
658
|
```
|
|
603
659
|
|
|
604
|
-
is
|
|
660
|
+
is converted to the following [try/except structure](https://cloud.google.com/workflows/docs/reference/syntax/catching-errors)
|
|
605
661
|
|
|
606
662
|
```yaml
|
|
607
663
|
- try1:
|
|
@@ -632,15 +688,17 @@ try {
|
|
|
632
688
|
}
|
|
633
689
|
```
|
|
634
690
|
|
|
635
|
-
If an exception gets thrown inside a try block, the stack trace in Workflows logs will misleadingly show the exception originating from inside the finally block. This happens because the
|
|
691
|
+
If an exception gets thrown inside a try block, the stack trace in Workflows logs will misleadingly show the exception originating from inside the finally block. This happens because the finally block is implemented by catching and re-throwing the original exception. The original source location of the exception is lost while re-throwing the exception.
|
|
636
692
|
|
|
637
693
|
⚠️ At the moment, break and continue are not supported in a try or a catch block if there is a related finally block.
|
|
638
694
|
|
|
639
695
|
## Retrying on errors
|
|
640
696
|
|
|
641
|
-
It is possible to set a retry policy for a try-catch statement. Because Typescript does not have `retry` keyword, the retry is implemented by a special `retry_policy` function. It must be called immediately after a try-catch block.
|
|
697
|
+
It is possible to set a retry policy for a try-catch statement. Because Typescript does not have `retry` keyword, the retry is implemented by a special `retry_policy` intrinsic function. It must be called immediately after a try-catch block. `retry_policy` is ignored elsewhere.
|
|
642
698
|
|
|
643
|
-
|
|
699
|
+
The arguments of `retry_policy` specify which errors are retried and how many times. The arguments can be either a policy provided by GCP Workflows or a custom retry policy as explained in the next sections.
|
|
700
|
+
|
|
701
|
+
If an exception gets thrown in a try block and the retry policy covers the exception, the try block is executed again. Finally and catch blocks are run after possible retry attempts. The following sample retries `http.get()` if it throws an HTTP error and executes `sys.log('Error!')` and `closeConnection()` after retry attempts.
|
|
644
702
|
|
|
645
703
|
```javascript
|
|
646
704
|
import { http, retry_policy, sys } from 'ts2workflows/types/workflowslib'
|
|
@@ -657,11 +715,9 @@ function main() {
|
|
|
657
715
|
}
|
|
658
716
|
```
|
|
659
717
|
|
|
660
|
-
The `retry_policy` function must be called with a parameter that defines the retry policy. It can be either a policy provided by GCP Workflows or a custom retry policy.
|
|
661
|
-
|
|
662
718
|
### GCP-provided retry policy
|
|
663
719
|
|
|
664
|
-
GCP retry policy
|
|
720
|
+
GCP provides some retry policies. A GCP policy can be set by `retry_policy(http.default_retry)` or by `retry_policy(http.default_retry_non_idempotent)`. Their effects are described in the [GCP documentation](https://cloud.google.com/workflows/docs/reference/syntax/retrying#default-retry-policy).
|
|
665
721
|
|
|
666
722
|
```javascript
|
|
667
723
|
import { http, retry_policy } from 'ts2workflows/types/workflowslib'
|
|
@@ -703,7 +759,7 @@ function main() {
|
|
|
703
759
|
}
|
|
704
760
|
```
|
|
705
761
|
|
|
706
|
-
|
|
762
|
+
ts2workflows converts the above to the following [try step](https://cloud.google.com/workflows/docs/reference/syntax/catching-errors)
|
|
707
763
|
|
|
708
764
|
```yaml
|
|
709
765
|
main:
|
|
@@ -737,7 +793,7 @@ The statement
|
|
|
737
793
|
throw 'Error!'
|
|
738
794
|
```
|
|
739
795
|
|
|
740
|
-
is
|
|
796
|
+
is converted to the following [raise block](https://cloud.google.com/workflows/docs/reference/syntax/raising-errors)
|
|
741
797
|
|
|
742
798
|
```yaml
|
|
743
799
|
- raise1:
|
|
@@ -750,7 +806,7 @@ Thrown errors can be handled by a try statement.
|
|
|
750
806
|
|
|
751
807
|
## Labeled steps
|
|
752
808
|
|
|
753
|
-
|
|
809
|
+
ts2workflows labels output steps with the step type and sequential numbering by default: e.g. `assign1`, `assign2`, etc. The automatic labels can be overridden by using Typescript labeled statements.
|
|
754
810
|
|
|
755
811
|
```typescript
|
|
756
812
|
setName: const name = 'Bean'
|
|
@@ -788,11 +844,11 @@ This section describes the few standard Javascript runtime functions that are av
|
|
|
788
844
|
Array.isArray(arg: any): arg is any[]
|
|
789
845
|
```
|
|
790
846
|
|
|
791
|
-
Gets converted to the comparison `get_type(arg) == "list"`. Unlike a direct call to `get_type()`, `Array.isArray()`
|
|
847
|
+
Gets converted to the comparison `get_type(arg) == "list"`. Unlike a direct call to `get_type()`, `Array.isArray()` acts a type guard and allows narrowing the `arg` type to an array.
|
|
792
848
|
|
|
793
|
-
##
|
|
849
|
+
## Compiler intrinsics
|
|
794
850
|
|
|
795
|
-
ts2workflows
|
|
851
|
+
ts2workflows has some special intrinsic functions that are implemented directly by the ts2workflows transpiler instead of converting to Workflows code using the usual semantics. These are needed for implementing features that are not directly supported by Typescript language features. The type annotations for these functions can be imported from ts2workflows/types/workflowslib:
|
|
796
852
|
|
|
797
853
|
```typescript
|
|
798
854
|
import {
|
|
@@ -802,6 +858,8 @@ import {
|
|
|
802
858
|
} from 'ts2workflows/types/workflowslib'
|
|
803
859
|
```
|
|
804
860
|
|
|
861
|
+
The compiler intrinsics are documented below.
|
|
862
|
+
|
|
805
863
|
### call_step()
|
|
806
864
|
|
|
807
865
|
```typescript
|
|
@@ -826,7 +884,7 @@ function parallel(
|
|
|
826
884
|
): void
|
|
827
885
|
```
|
|
828
886
|
|
|
829
|
-
The `parallel` function executes code blocks in parallel
|
|
887
|
+
The `parallel` function executes code blocks in parallel using a [parallel step](https://cloud.google.com/workflows/docs/reference/syntax/parallel-steps). See the previous sections covering parallel branches and iteration.
|
|
830
888
|
|
|
831
889
|
### retry_policy()
|
|
832
890
|
|
|
@@ -846,7 +904,9 @@ function retry_policy(
|
|
|
846
904
|
): void
|
|
847
905
|
```
|
|
848
906
|
|
|
849
|
-
|
|
907
|
+
A retry policy can be attached to a `try`-`catch` block be calling `retry_policy` as the next statement after the `try`-`catch`. ts2workflows ignores `retry_policy` everywhere else except after a `try`-`catch`.
|
|
908
|
+
|
|
909
|
+
See the section on [retrying errors](#retrying-on-errors).
|
|
850
910
|
|
|
851
911
|
## Source code comments
|
|
852
912
|
|
|
@@ -867,7 +927,6 @@ ts2workflows supports only a subset of all Typescript language features. Some ex
|
|
|
867
927
|
- Arrays and maps are not objects. In particular, arrays don't have methods such as `[].push()`, `[].map()`, etc.
|
|
868
928
|
- Functions (subworkflows) are not first-class objects. Functions can not be assigned to a variable or passed to other functions
|
|
869
929
|
- Update expressions (`x++` and similar) are not supported
|
|
870
|
-
- Destructuring (`[a, b] = func()`) is not supported
|
|
871
930
|
- and many other Typescript language features are not supported
|
|
872
931
|
|
|
873
932
|
Some of these might be implemented later, but the goal of ts2workflows project is not to implement the full Typescript compatibility.
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts2workflows",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Transpile Typescript code to GCP Workflows programs",
|
|
5
5
|
"homepage": "https://github.com/aajanki/ts2workflows",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/aajanki/ts2workflows.git"
|
|
8
|
+
"url": "git+https://github.com/aajanki/ts2workflows.git"
|
|
9
9
|
},
|
|
10
10
|
"bugs": "https://github.com/aajanki/ts2workflows/issues",
|
|
11
11
|
"main": "dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"lint": "eslint src test scripts",
|
|
21
21
|
"format": "prettier . --write",
|
|
22
22
|
"test": "mocha",
|
|
23
|
-
"prepare": "husky"
|
|
23
|
+
"prepare": "husky && npm run build"
|
|
24
24
|
},
|
|
25
25
|
"lint-staged": {
|
|
26
26
|
"src/**/*.ts": [
|
|
@@ -39,7 +39,9 @@
|
|
|
39
39
|
"prettier --write"
|
|
40
40
|
]
|
|
41
41
|
},
|
|
42
|
-
"bin":
|
|
42
|
+
"bin": {
|
|
43
|
+
"ts2workflows": "./dist/cli.js"
|
|
44
|
+
},
|
|
43
45
|
"files": [
|
|
44
46
|
"dist",
|
|
45
47
|
"types",
|
|
@@ -60,6 +62,7 @@
|
|
|
60
62
|
"@types/chai": "^5.0.1",
|
|
61
63
|
"@types/mocha": "^10.0.6",
|
|
62
64
|
"@types/node": "^18",
|
|
65
|
+
"@types/ramda": "^0.30.2",
|
|
63
66
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
64
67
|
"@typescript-eslint/parser": "^8.0.0",
|
|
65
68
|
"chai": "^5.1.1",
|
|
@@ -74,7 +77,8 @@
|
|
|
74
77
|
},
|
|
75
78
|
"dependencies": {
|
|
76
79
|
"@typescript-eslint/typescript-estree": "^8.0.0",
|
|
77
|
-
"commander": "^
|
|
80
|
+
"commander": "^13.1.0",
|
|
81
|
+
"ramda": "^0.30.1",
|
|
78
82
|
"typescript": "^5.0.0",
|
|
79
83
|
"yaml": "^2.4.2"
|
|
80
84
|
}
|