diff --git a/integration-tests/execute/CHANGELOG.md b/integration-tests/execute/CHANGELOG.md index 25a096473..a7d3f14d0 100644 --- a/integration-tests/execute/CHANGELOG.md +++ b/integration-tests/execute/CHANGELOG.md @@ -1,5 +1,12 @@ # @openfn/integration-tests-execute +## 1.0.2 + +### Patch Changes + +- Updated dependencies [4751c90] + - @openfn/compiler@0.3.0 + ## 1.0.1 ### Patch Changes diff --git a/integration-tests/execute/package.json b/integration-tests/execute/package.json index ed4bf550a..da148d707 100644 --- a/integration-tests/execute/package.json +++ b/integration-tests/execute/package.json @@ -1,7 +1,7 @@ { "name": "@openfn/integration-tests-execute", "private": true, - "version": "1.0.1", + "version": "1.0.2", "description": "Job execution tests", "author": "Open Function Group ", "license": "ISC", diff --git a/integration-tests/worker/CHANGELOG.md b/integration-tests/worker/CHANGELOG.md index bcfc5a864..ef7e3d44e 100644 --- a/integration-tests/worker/CHANGELOG.md +++ b/integration-tests/worker/CHANGELOG.md @@ -1,5 +1,14 @@ # @openfn/integration-tests-worker +## 1.0.52 + +### Patch Changes + +- Updated dependencies [2f5dc51] + - @openfn/ws-worker@1.4.1 + - @openfn/engine-multi@1.2.1 + - @openfn/lightning-mock@2.0.15 + ## 1.0.51 ### Patch Changes diff --git a/integration-tests/worker/package.json b/integration-tests/worker/package.json index 78e871557..e0ab1c019 100644 --- a/integration-tests/worker/package.json +++ b/integration-tests/worker/package.json @@ -1,7 +1,7 @@ { "name": "@openfn/integration-tests-worker", "private": true, - "version": "1.0.51", + "version": "1.0.52", "description": "Lightning WOrker integration tests", "author": "Open Function Group ", "license": "ISC", diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 5f725a5fc..a50bb8c03 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -1,5 +1,13 @@ # @openfn/cli +## 1.7.1 + +### Patch Changes + +- 2f5dc51: Update the compiler to treat method calls (http.get()) like operations +- Updated dependencies [4751c90] + - @openfn/compiler@0.3.0 + ## 1.7.0 ### Minor Changes diff --git a/packages/cli/package.json b/packages/cli/package.json index 748b95268..a160d256e 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@openfn/cli", - "version": "1.7.0", + "version": "1.7.1", "description": "CLI devtools for the openfn toolchain.", "engines": { "node": ">=18", diff --git a/packages/compiler/CHANGELOG.md b/packages/compiler/CHANGELOG.md index fbe2f4d99..78e08e40a 100644 --- a/packages/compiler/CHANGELOG.md +++ b/packages/compiler/CHANGELOG.md @@ -1,5 +1,11 @@ # @openfn/compiler +## 0.3.0 + +### Minor Changes + +- 4751c90: Treat method calls like http.get like operations + ## 0.2.0 ### Minor Changes diff --git a/packages/compiler/package.json b/packages/compiler/package.json index 9bca4763f..a0229ce97 100644 --- a/packages/compiler/package.json +++ b/packages/compiler/package.json @@ -1,6 +1,6 @@ { "name": "@openfn/compiler", - "version": "0.2.0", + "version": "0.3.0", "description": "Compiler and language tooling for openfn jobs.", "author": "Open Function Group ", "license": "ISC", diff --git a/packages/compiler/src/transforms/top-level-operations.ts b/packages/compiler/src/transforms/top-level-operations.ts index b6a68282e..50d7980a9 100644 --- a/packages/compiler/src/transforms/top-level-operations.ts +++ b/packages/compiler/src/transforms/top-level-operations.ts @@ -21,8 +21,9 @@ function visitor(path: NodePath) { // ie, the parent must be an ExpressionStatement, and the statement's parent must be a Program n.Program.check(root) && n.Statement.check(path.parent.node) && - // If it's an Operation call (ie, fn(() => {})), the callee will be an IdentifierExpression - n.Identifier.check(path.node.callee) + // An Operation could be an Identifier (fn()) or Member Expression (http.get()) + (n.Identifier.check(path.node.callee) || + n.MemberExpression.check(path.node.callee)) ) { // Now Find the top level exports array const target = root.body.at(-1); diff --git a/packages/compiler/test/compile.test.ts b/packages/compiler/test/compile.test.ts index 376902f64..9eca1efea 100644 --- a/packages/compiler/test/compile.test.ts +++ b/packages/compiler/test/compile.test.ts @@ -24,6 +24,21 @@ test('compile a single operation', (t) => { t.is(result, expected); }); +test('compile a single namespaced operation', (t) => { + const source = 'http.get();'; + const expected = 'export default [http.get()];'; + const result = compile(source); + t.is(result, expected); +}); + +test('compile a const assignment with single method call', (t) => { + const source = 'const x = dateFns.parse()'; + const expected = `const x = dateFns.parse() +export default [];`; + const result = compile(source); + t.is(result, expected); +}); + test('compile a single operation without being fussy about semicolons', (t) => { const source = 'fn()'; const expected = 'export default [fn()];'; diff --git a/packages/compiler/test/transforms/top-level-operations.test.ts b/packages/compiler/test/transforms/top-level-operations.test.ts index 75cdf58c9..720c59791 100644 --- a/packages/compiler/test/transforms/top-level-operations.test.ts +++ b/packages/compiler/test/transforms/top-level-operations.test.ts @@ -108,7 +108,7 @@ test('does not move a nested operation into the exports array', (t) => { t.assert(call.callee.name === 'fn'); }); -test('does not move method call into the exports array', (t) => { +test('moves a method call into the exports array', (t) => { const ast = createProgramWithExports([ b.expressionStatement( b.callExpression( @@ -119,17 +119,50 @@ test('does not move method call into the exports array', (t) => { ]); const { body } = transform(ast, [visitors]); - // should be two top level children - t.assert(body.length === 2); - // Those children should still be an expression and export statement - const [stmt, ex] = body; - t.assert(n.ExpressionStatement.check(stmt)); - t.assert(n.ExportDefaultDeclaration.check(ex)); + // should only be ony top level child + t.assert(body.length === 1); + + // That child should be a default declaration + t.assert(n.ExportDefaultDeclaration.check(body[0])); + + // The declaration should be an array of 1 + t.assert(n.ArrayExpression.check(body[0].declaration)); + t.assert(body[0].declaration.elements.length == 1); + + // And the one element should be a call to http.get + const call = body[0].declaration.elements[0]; + t.assert(n.CallExpression.check(call)); + t.assert(n.MemberExpression.check(call.callee)); + + t.is(call.callee.object.name, 'a'); + t.is(call.callee.property.name, 'b'); +}); + +test('does not move a method call inside an asisignment', (t) => { + const ast = createProgramWithExports([ + b.variableDeclaration('const', [ + b.variableDeclarator( + b.identifier('x'), + b.callExpression( + b.memberExpression(b.identifier('a'), b.identifier('b')), + [] + ) + ), + ]), + ]); + + const { body } = transform(ast, [visitors]); + console.log(body); + + // should add the export + t.is(body.length, 2); + + // The first child should be an variable declaration + t.true(n.VariableDeclaration.check(body[0])); - // The declaration should be an array of 0 - t.assert(n.ArrayExpression.check(ex.declaration)); - t.assert(ex.declaration.elements.length == 0); + // the exported array should be empty + t.is(body[1].declaration.elements.length, 0); }); test("does nothing if there's no export statement", (t) => { diff --git a/packages/engine-multi/CHANGELOG.md b/packages/engine-multi/CHANGELOG.md index 98fd0c5b3..394e3f69f 100644 --- a/packages/engine-multi/CHANGELOG.md +++ b/packages/engine-multi/CHANGELOG.md @@ -1,5 +1,12 @@ # engine-multi +## 1.2.1 + +### Patch Changes + +- Updated dependencies [4751c90] + - @openfn/compiler@0.3.0 + ## 1.2.0 ### Minor Changes diff --git a/packages/engine-multi/package.json b/packages/engine-multi/package.json index d4b6045ff..6755ad6f4 100644 --- a/packages/engine-multi/package.json +++ b/packages/engine-multi/package.json @@ -1,6 +1,6 @@ { "name": "@openfn/engine-multi", - "version": "1.2.0", + "version": "1.2.1", "description": "Multi-process runtime engine", "main": "dist/index.js", "type": "module", diff --git a/packages/lightning-mock/CHANGELOG.md b/packages/lightning-mock/CHANGELOG.md index 4d97a24f4..71d217307 100644 --- a/packages/lightning-mock/CHANGELOG.md +++ b/packages/lightning-mock/CHANGELOG.md @@ -1,5 +1,11 @@ # @openfn/lightning-mock +## 2.0.15 + +### Patch Changes + +- @openfn/engine-multi@1.2.1 + ## 2.0.14 ### Patch Changes diff --git a/packages/lightning-mock/package.json b/packages/lightning-mock/package.json index 2de385a0e..ec5564fac 100644 --- a/packages/lightning-mock/package.json +++ b/packages/lightning-mock/package.json @@ -1,6 +1,6 @@ { "name": "@openfn/lightning-mock", - "version": "2.0.14", + "version": "2.0.15", "private": true, "description": "A mock Lightning server", "main": "dist/index.js", diff --git a/packages/ws-worker/CHANGELOG.md b/packages/ws-worker/CHANGELOG.md index b660de64a..117e0a1ad 100644 --- a/packages/ws-worker/CHANGELOG.md +++ b/packages/ws-worker/CHANGELOG.md @@ -1,5 +1,12 @@ # ws-worker +## 1.4.1 + +### Patch Changes + +- 2f5dc51: Update the compiler to treat method calls (http.get()) like operations + - @openfn/engine-multi@1.2.1 + ## 1.4.0 ### Minor Changes diff --git a/packages/ws-worker/package.json b/packages/ws-worker/package.json index 33135a3b7..45bcd17f3 100644 --- a/packages/ws-worker/package.json +++ b/packages/ws-worker/package.json @@ -1,6 +1,6 @@ { "name": "@openfn/ws-worker", - "version": "1.4.0", + "version": "1.4.1", "description": "A Websocket Worker to connect Lightning to a Runtime Engine", "main": "dist/index.js", "type": "module",