ts2workflows 0.2.0 → 0.3.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.
@@ -1 +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;AAyDxB,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"}
1
+ {"version":3,"file":"statements.d.ts","sourceRoot":"","sources":["../../src/transpiler/statements.ts"],"names":[],"mappings":"AAEA,OAAO,EASL,QAAQ,EAMR,eAAe,EAEhB,MAAM,iBAAiB,CAAA;AAyDxB,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"}
@@ -179,10 +179,12 @@ function callExpressionToStep(node, ctx) {
179
179
  }
180
180
  function callExpressionAssignStep(functionName, argumentsNode) {
181
181
  const argumentExpressions = argumentsNode.map(convertExpression);
182
- const assignments = [
183
- ['', new FunctionInvocationExpression(functionName, argumentExpressions)],
184
- ];
185
- return new AssignStepAST(assignments);
182
+ return new AssignStepAST([
183
+ [
184
+ '__temp',
185
+ new FunctionInvocationExpression(functionName, argumentExpressions),
186
+ ],
187
+ ]);
186
188
  }
187
189
  function callExpressionToCallStep(functionName, argumentsNode) {
188
190
  if (argumentsNode.length < 1 || argumentsNode[0].type !== ObjectExpression) {
@@ -325,7 +327,7 @@ function parseParallelOptions(node) {
325
327
  };
326
328
  }
327
329
  function generalExpressionToAssignStep(node) {
328
- return new AssignStepAST([['', convertExpression(node)]]);
330
+ return new AssignStepAST([['__temp', convertExpression(node)]]);
329
331
  }
330
332
  function returnStatementToReturnStep(node) {
331
333
  assertType(node, ReturnStatement);
@@ -7,7 +7,7 @@ import { WorkflowStepAST } from '../ast/steps.js';
7
7
  */
8
8
  export declare function transformAST(steps: WorkflowStepAST[]): WorkflowStepAST[];
9
9
  /**
10
- * Flatten switch conditions that contain a single next step.
10
+ * Merge a next step to the previous step.
11
11
  *
12
12
  * For example, transforms this:
13
13
  *
@@ -1 +1 @@
1
- {"version":3,"file":"transformations.d.ts","sourceRoot":"","sources":["../../src/transpiler/transformations.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,eAAe,EAChB,MAAM,iBAAiB,CAAA;AAuBxB;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,eAAe,EAAE,CAUxE;AA0JD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,eAAe,EAAE,GACvB,eAAe,EAAE,CAEnB"}
1
+ {"version":3,"file":"transformations.d.ts","sourceRoot":"","sources":["../../src/transpiler/transformations.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,eAAe,EAChB,MAAM,iBAAiB,CAAA;AAuBxB;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,eAAe,EAAE,CAUxE;AA0JD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,eAAe,EAAE,GACvB,eAAe,EAAE,CAoBnB"}
@@ -124,7 +124,7 @@ function parseRetryPolicyNumber(record, keyName) {
124
124
  return primitiveValue;
125
125
  }
126
126
  /**
127
- * Flatten switch conditions that contain a single next step.
127
+ * Merge a next step to the previous step.
128
128
  *
129
129
  * For example, transforms this:
130
130
  *
@@ -142,6 +142,23 @@ function parseRetryPolicyNumber(record, keyName) {
142
142
  * next: target1
143
143
  */
144
144
  export function flattenPlainNextConditions(steps) {
145
+ /*
146
+ const res = steps.reduce((acc: WorkflowStepAST[], step: WorkflowStepAST) => {
147
+ if (acc.length > 0) {
148
+ if (step.tag === 'next') {
149
+ const prev = acc[-1]
150
+
151
+ if (prev.tag === 'assign') {
152
+
153
+ }
154
+
155
+ }
156
+ }
157
+
158
+ return acc
159
+ }, [])
160
+
161
+ */
145
162
  return steps.map((step) => (step.tag === 'switch' ? flattenNext(step) : step));
146
163
  }
147
164
  function flattenNext(step) {
@@ -145,7 +145,7 @@ is converted to an [assign step](https://cloud.google.com/workflows/docs/referen
145
145
  - projectId: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
146
146
  ```
147
147
 
148
- This syntax can be used to call [standard library functions](https://cloud.google.com/workflows/docs/reference/stdlib/overview), subworkflows or connectors.
148
+ This syntax can be used to call [standard library functions](https://cloud.google.com/workflows/docs/reference/stdlib/overview), subworkflows or connectors. Note that Javascript runtime functions (such as `fetch()`, `console.error()` or `new XMLHttpRequest()`) are not available on Workflows.
149
149
 
150
150
  GCP Workflows language has two ways of calling functions and subworkflows: as expression in an [assign step](https://cloud.google.com/workflows/docs/reference/syntax/variables#assign-step) 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. The transpiler tries to automatically output a call step when necessary.
151
151
 
@@ -175,7 +175,7 @@ main:
175
175
  severity: INFO
176
176
  ```
177
177
 
178
- Some Workflows standard library functions have names that are reserved keywords in Typescript. Those functions must be called with alternative names in ts2workflows source code:
178
+ Some Workflows standard library functions have names that are reserved keywords in Typescript. Those functions must be called with alternative syntax in ts2workflows source code:
179
179
 
180
180
  - To generate a call to `default()` in Workflows code, use the nullish coalescing operator `??`.
181
181
  - To generete a call to `if()` in Workflows code, use the ternary operator `a ? b : c`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts2workflows",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Transpile Typescript code to GCP Workflows programs",
5
5
  "homepage": "https://github.com/aajanki/ts2workflows",
6
6
  "repository": {
@@ -19,7 +19,17 @@
19
19
  "build:functionmetadata": "tsx scripts/generateBlockingFunctionMetadata.ts",
20
20
  "lint": "eslint src test scripts",
21
21
  "format": "prettier . --write",
22
- "test": "mocha"
22
+ "test": "mocha",
23
+ "prepare": "husky"
24
+ },
25
+ "lint-staged": {
26
+ "*.ts": [
27
+ "prettier --write",
28
+ "eslint"
29
+ ],
30
+ "*.md": [
31
+ "prettier --write"
32
+ ]
23
33
  },
24
34
  "bin": "./dist/cli.js",
25
35
  "files": [
@@ -46,6 +56,8 @@
46
56
  "@typescript-eslint/parser": "^8.0.0",
47
57
  "chai": "^5.1.1",
48
58
  "eslint": "^9.10.0",
59
+ "husky": "^9.1.6",
60
+ "lint-staged": "^15.2.10",
49
61
  "mocha": "^10.4.0",
50
62
  "prettier": "^3.2.5",
51
63
  "rimraf": "^5.0.10",
@@ -161,9 +161,15 @@ export declare namespace http {
161
161
  }
162
162
 
163
163
  export declare namespace json {
164
- function decode(data: bytes | string): object
164
+ function decode(data: bytes | string): unknown
165
165
  function encode(
166
- data: string | number | boolean | unknown[] | Record<string, unknown>,
166
+ data:
167
+ | string
168
+ | number
169
+ | boolean
170
+ | unknown[]
171
+ | Record<string, unknown>
172
+ | null,
167
173
  indent?:
168
174
  | boolean
169
175
  | {
@@ -172,7 +178,13 @@ export declare namespace json {
172
178
  },
173
179
  ): bytes
174
180
  function encode_to_string(
175
- data: string | number | boolean | unknown[] | Record<string, unknown>,
181
+ data:
182
+ | string
183
+ | number
184
+ | boolean
185
+ | unknown[]
186
+ | Record<string, unknown>
187
+ | null,
176
188
  indent?:
177
189
  | boolean
178
190
  | {
@@ -192,7 +204,7 @@ export declare namespace map {
192
204
  export function get<T, K extends string | string[]>(
193
205
  map: Record<string, T>,
194
206
  keys: K,
195
- ): K extends string ? T : unknown
207
+ ): K extends string ? T | null : unknown
196
208
  export function merge<T, U>(
197
209
  first: Record<string, T>,
198
210
  second: Record<string, U>,
@@ -245,7 +257,7 @@ export declare namespace text {
245
257
  index: number
246
258
  match: string
247
259
  }[]
248
- function match_regexp(source: string, regexp: string): boolean
260
+ function match_regex(source: string, regexp: string): boolean
249
261
  function replace_all(source: string, substr: string, repl: string): string
250
262
  function replace_all_regex(
251
263
  source: string,