-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #642 from OpenFn/compiler-release
Compiler release
- Loading branch information
Showing
22 changed files
with
229 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "@openfn/integration-tests-worker", | ||
"private": true, | ||
"version": "1.0.36", | ||
"version": "1.0.37", | ||
"description": "Lightning WOrker integration tests", | ||
"author": "Open Function Group <[email protected]>", | ||
"license": "ISC", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@openfn/compiler", | ||
"version": "0.0.41", | ||
"version": "0.1.0", | ||
"description": "Compiler and language tooling for openfn jobs.", | ||
"author": "Open Function Group <[email protected]>", | ||
"license": "ISC", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Convert $.a.b.c references into (state) => state.a.b.c | ||
* Should this only run at top level? | ||
* Ideally it would run on all arguments to operations - but we probably don't really know what an operation is | ||
* So for now, first pass, it's only top level. | ||
* (alternatively I guess it just dumbly converts everything and if it breaks, it breaks) | ||
* | ||
* TODO (maybe): | ||
* - only convert $-expressions which are arguments to operations (needs type defs) | ||
* - warn if converting a non-top-level $-expression | ||
* - if not top level, convert to state.a.b.c (ie don't wrap the function) | ||
*/ | ||
import { builders as b, namedTypes } from 'ast-types'; | ||
import type { NodePath } from 'ast-types/lib/node-path'; | ||
import type { Transformer } from '../transform'; | ||
|
||
function visitor(path: NodePath<namedTypes.MemberExpression>) { | ||
let first = path.node.object; | ||
while(first.hasOwnProperty('object')) { | ||
first = (first as namedTypes.MemberExpression).object; | ||
} | ||
|
||
let firstIdentifer = first as namedTypes.Identifier; | ||
|
||
if (first && firstIdentifer.name === "$") { | ||
// rename $ to state | ||
firstIdentifer.name = "state"; | ||
|
||
// Now nest the whole thing in an arrow | ||
const params = b.identifier('state') | ||
const arrow = b.arrowFunctionExpression( | ||
[params], | ||
path.node | ||
) | ||
path.replace(arrow) | ||
} | ||
|
||
// Stop parsing this member expression | ||
return; | ||
} | ||
|
||
export default { | ||
id: 'lazy-state', | ||
types: ['MemberExpression'], | ||
visitor, | ||
} as Transformer; |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"program":{"type":"Program","start":0,"end":5,"loc":{"start":{"line":1,"column":0,"token":0},"end":{"line":1,"column":5,"token":4},"lines":{"infos":[{"line":"fn();","indent":0,"locked":false,"sliceStart":0,"sliceEnd":5}],"mappings":[],"cachedSourceMap":null,"length":1,"name":null},"indent":0,"tokens":[{"type":"Identifier","value":"fn","loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}},{"type":"Punctuator","value":"(","loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":3}}},{"type":"Punctuator","value":")","loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4}}},{"type":"Punctuator","value":";","loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5}}}]},"body":[{"type":"ExpressionStatement","start":0,"end":5,"loc":{"start":{"line":1,"column":0,"token":0},"end":{"line":1,"column":5,"token":4},"lines":{"infos":[{"line":"fn();","indent":0,"locked":false,"sliceStart":0,"sliceEnd":5}],"mappings":[],"cachedSourceMap":null,"length":1,"name":null},"tokens":[{"type":"Identifier","value":"fn","loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}},{"type":"Punctuator","value":"(","loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":3}}},{"type":"Punctuator","value":")","loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4}}},{"type":"Punctuator","value":";","loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5}}}],"indent":0},"expression":{"type":"CallExpression","start":0,"end":4,"loc":{"start":{"line":1,"column":0,"token":0},"end":{"line":1,"column":4,"token":3},"lines":{"infos":[{"line":"fn();","indent":0,"locked":false,"sliceStart":0,"sliceEnd":5}],"mappings":[],"cachedSourceMap":null,"length":1,"name":null},"tokens":[{"type":"Identifier","value":"fn","loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}},{"type":"Punctuator","value":"(","loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":3}}},{"type":"Punctuator","value":")","loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4}}},{"type":"Punctuator","value":";","loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5}}}],"indent":0},"callee":{"type":"Identifier","start":0,"end":2,"loc":{"start":{"line":1,"column":0,"token":0},"end":{"line":1,"column":2,"token":1},"lines":{"infos":[{"line":"fn();","indent":0,"locked":false,"sliceStart":0,"sliceEnd":5}],"mappings":[],"cachedSourceMap":null,"length":1,"name":null},"tokens":[{"type":"Identifier","value":"fn","loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}},{"type":"Punctuator","value":"(","loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":3}}},{"type":"Punctuator","value":")","loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4}}},{"type":"Punctuator","value":";","loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5}}}],"indent":0},"name":"fn"},"arguments":[]}}],"sourceType":"module","errors":[]},"name":null,"loc":{"start":{"line":1,"column":0,"token":0},"end":{"line":1,"column":5,"token":4},"lines":{"infos":[{"line":"fn();","indent":0,"locked":false,"sliceStart":0,"sliceEnd":5}],"mappings":[],"cachedSourceMap":null,"length":1,"name":null},"indent":0,"tokens":[{"type":"Identifier","value":"fn","loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}},{"type":"Punctuator","value":"(","loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":3}}},{"type":"Punctuator","value":")","loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4}}},{"type":"Punctuator","value":";","loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5}}}]},"type":"File","comments":null,"tokens":[{"type":"Identifier","value":"fn","loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}},{"type":"Punctuator","value":"(","loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":3}}},{"type":"Punctuator","value":")","loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4}}},{"type":"Punctuator","value":";","loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5}}}]} | ||
{"program":{"type":"Program","start":0,"end":5,"loc":{"start":{"line":1,"column":0,"token":0},"end":{"line":1,"column":5,"token":4},"lines":{"infos":[{"line":"fn();","indent":0,"locked":false,"sliceStart":0,"sliceEnd":5}],"mappings":[],"cachedSourceMap":null,"length":1,"name":null},"indent":0,"tokens":[{"type":"Identifier","value":"fn","loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}},{"type":"Punctuator","value":"(","loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":3}}},{"type":"Punctuator","value":")","loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4}}},{"type":"Punctuator","value":";","loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5}}}]},"body":[{"type":"ExpressionStatement","start":0,"end":5,"loc":{"start":{"line":1,"column":0,"token":0},"end":{"line":1,"column":5,"token":4},"lines":{"infos":[{"line":"fn();","indent":0,"locked":false,"sliceStart":0,"sliceEnd":5}],"mappings":[],"cachedSourceMap":null,"length":1,"name":null},"tokens":[{"type":"Identifier","value":"fn","loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}},{"type":"Punctuator","value":"(","loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":3}}},{"type":"Punctuator","value":")","loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4}}},{"type":"Punctuator","value":";","loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5}}}],"indent":0},"expression":{"type":"CallExpression","start":0,"end":4,"loc":{"start":{"line":1,"column":0,"token":0},"end":{"line":1,"column":4,"token":3},"lines":{"infos":[{"line":"fn();","indent":0,"locked":false,"sliceStart":0,"sliceEnd":5}],"mappings":[],"cachedSourceMap":null,"length":1,"name":null},"tokens":[{"type":"Identifier","value":"fn","loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}},{"type":"Punctuator","value":"(","loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":3}}},{"type":"Punctuator","value":")","loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4}}},{"type":"Punctuator","value":";","loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5}}}],"indent":0},"callee":{"type":"Identifier","start":0,"end":2,"loc":{"start":{"line":1,"column":0,"token":0},"end":{"line":1,"column":2,"token":1},"lines":{"infos":[{"line":"fn();","indent":0,"locked":false,"sliceStart":0,"sliceEnd":5}],"mappings":[],"cachedSourceMap":null,"length":1,"name":null},"tokens":[{"type":"Identifier","value":"fn","loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}},{"type":"Punctuator","value":"(","loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":3}}},{"type":"Punctuator","value":")","loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4}}},{"type":"Punctuator","value":";","loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5}}}],"indent":0},"name":"fn"},"arguments":[],"optional":false}}],"sourceType":"module","errors":[]},"name":null,"loc":{"start":{"line":1,"column":0,"token":0},"end":{"line":1,"column":5,"token":4},"lines":{"infos":[{"line":"fn();","indent":0,"locked":false,"sliceStart":0,"sliceEnd":5}],"mappings":[],"cachedSourceMap":null,"length":1,"name":null},"indent":0,"tokens":[{"type":"Identifier","value":"fn","loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}},{"type":"Punctuator","value":"(","loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":3}}},{"type":"Punctuator","value":")","loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4}}},{"type":"Punctuator","value":";","loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5}}}]},"type":"File","comments":null,"tokens":[{"type":"Identifier","value":"fn","loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}},{"type":"Punctuator","value":"(","loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":3}}},{"type":"Punctuator","value":")","loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4}}},{"type":"Punctuator","value":";","loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5}}}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import test, { ExecutionContext } from 'ava'; | ||
import { print } from 'recast'; | ||
import { namedTypes, NodePath, builders as b } from 'ast-types'; | ||
|
||
import parse from '../../src/parse'; | ||
|
||
import transform from '../../src/transform'; | ||
import visitors from '../../src/transforms/lazy-state'; | ||
|
||
test('convert a simple dollar reference', (t) => { | ||
const ast = parse('get($.data)'); | ||
|
||
const transformed = transform(ast, [visitors]); | ||
const { code } = print(transformed) | ||
t.log(code) | ||
|
||
t.is(code, 'get(state => state.data)') | ||
}) | ||
|
||
test('convert a chained dollar reference', (t) => { | ||
const ast = parse('get($.a.b.c.d)'); | ||
|
||
const transformed = transform(ast, [visitors]); | ||
const { code } = print(transformed) | ||
t.log(code) | ||
|
||
t.is(code, 'get(state => state.a.b.c.d)') | ||
}) | ||
|
||
test('ignore a regular chain reference', (t) => { | ||
const ast = parse('get(a.b.c.d)'); | ||
|
||
const transformed = transform(ast, [visitors]); | ||
const { code } = print(transformed) | ||
t.log(code) | ||
|
||
t.is(code, 'get(a.b.c.d)') | ||
}) | ||
|
||
test('ignore a string', (t) => { | ||
const ast = parse('get("$.a.b")'); | ||
|
||
const transformed = transform(ast, [visitors]); | ||
const { code } = print(transformed) | ||
t.log(code) | ||
|
||
t.is(code, 'get("$.a.b")') | ||
}) | ||
|
||
// TODO do we want to support this? | ||
test('convert a nested dollar reference', (t) => { | ||
const ast = parse(`fn(() => { | ||
get($.data) | ||
})`); | ||
|
||
const transformed = transform(ast, [visitors]); | ||
const { code } = print(transformed) | ||
t.log(code) | ||
|
||
// syntax starts getting a but picky at this level, | ||
// better to do ast tests | ||
t.is(code, `fn(() => { | ||
get(state => state.data) | ||
})`) | ||
}) | ||
|
||
// TODO does our compiler not support optional chaining?? | ||
test.skip('convert an optional chained simple dollar reference', (t) => { | ||
const ast = parse('get($.a?.b.c.d)'); | ||
|
||
// const transformed = transform(ast, [visitors]); | ||
// const { code } = print(transformed) | ||
// t.log(code) | ||
|
||
// t.is(code, 'get(state => state.a?.b.c.d)') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# @openfn/lightning-mock | ||
|
||
## 2.0.2 | ||
|
||
### Patch Changes | ||
|
||
- @openfn/engine-multi@1.1.2 | ||
|
||
## 2.0.1 | ||
|
||
### Patch Changes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# ws-worker | ||
|
||
## 1.1.2 | ||
|
||
### Patch Changes | ||
|
||
- @openfn/engine-multi@1.1.2 | ||
|
||
## 1.1.1 | ||
|
||
### Patch Changes | ||
|
Oops, something went wrong.