From 37e9f33d3405bd0a39f70d4d9ef25baefa739556 Mon Sep 17 00:00:00 2001 From: Bentley Cook Date: Wed, 7 Feb 2024 14:58:00 -0600 Subject: [PATCH 1/3] getPosts.js code snippet amended Reformatted the code snippet for getPosts.js in CLI walkthrough to make it more copy-and-paste-able. --- docs/build-for-developers/cli-walkthrough.md | 27 +++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/docs/build-for-developers/cli-walkthrough.md b/docs/build-for-developers/cli-walkthrough.md index d3e31befa667..f755c2714710 100644 --- a/docs/build-for-developers/cli-walkthrough.md +++ b/docs/build-for-developers/cli-walkthrough.md @@ -342,16 +342,29 @@ by user id. The example below shows how we can: // Get all posts get('posts'); -// Group posts by user id fn(state => { const posts = state.data; +// Group posts by user id +fn(state => { + const posts = state.data; -// Group posts by userId const groupPostsByUserId = posts.reduce((acc, post) => -{ const existingValue = acc[post.userId] || []; return { ...acc, [post.userId]: -[...existingValue, post] }; }, {}); + // Group posts by userId + const groupPostsByUserId = posts.reduce((acc, post) => { + const existingValue = acc[post.userId] || []; + return { + ...acc, + [post.userId]:[...existingValue, post] + }; + }, {}); -// console.log(groupPostsByUserId); return { ...state, groupPostsByUserId }; }); + console.log(groupPostsByUserId); -// Log posts where userId = 1 fn(state => { const { groupPostsByUserId } = -state; console.log('Post with userId 1', groupPostsByUserId[1]); return state; + return { ...state, groupPostsByUserId }; +}); + +// Log posts where userId = 1 +fn(state => { + const { groupPostsByUserId } = state; + console.log('Post with userId 1', groupPostsByUserId[1]); + return state; }); ``` From e402b63a678fe534cb3e2656e7fd1d7e99176377 Mon Sep 17 00:00:00 2001 From: Bentley Cook Date: Wed, 7 Feb 2024 15:22:07 -0600 Subject: [PATCH 2/3] CLI log output amended Updating the bash output snippets so that code formatting is picked up by docusaurus. --- docs/build-for-developers/cli-walkthrough.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/build-for-developers/cli-walkthrough.md b/docs/build-for-developers/cli-walkthrough.md index f755c2714710..9441231f95df 100644 --- a/docs/build-for-developers/cli-walkthrough.md +++ b/docs/build-for-developers/cli-walkthrough.md @@ -458,6 +458,7 @@ fn(state => {
Expected CLI logs + ```bash [CLI] ✘ TypeError: path.match is not a function at dataPath (/tmp/openfn/repo/node_modules/@openfn/language-common/dist/index.cjs:258:26) @@ -470,6 +471,7 @@ fn(state => { at async run (file:///home/openfn/.asdf/installs/nodejs/18.12.0/lib/node_modules/@openfn/cli/node_modules/@openfn/runtime/dist/index.js:269:18) at async executeHandler (file:///home/openfn/.asdf/installs/nodejs/18.12.0/lib/node_modules/@openfn/cli/dist/process/runner.js:388:20) ``` +
As you can see from our logs that helper function `dataValue` has a TypeError, @@ -483,6 +485,7 @@ fix the error by passing a string in dataValue i.e `console.log(dataValue(“1
Expected CLI logs + ```bash [CLI] ✔ Compiled job from debug.js GET request succeeded with 200 ✓ @@ -492,6 +495,7 @@ fix the error by passing a string in dataValue i.e `console.log(dataValue(“1 [CLI] ✔ Writing output to tmp/output.json [CLI] ✔ Done in 1.102s ✨ ``` +
If you need more information for debugging you can pass -l debug which will give @@ -554,6 +558,7 @@ export many functions from `language-common`.
Expand to see expected CLI logs + ```bash [CLI] ✔ Compiled job from getPosts.js GET request succeeded with 200 ✓ @@ -567,6 +572,7 @@ export many functions from `language-common`. [CLI] ✔ Writing output to tmp/output.json [CLI] ✔ Done in 1.091s! ✨ ``` +
### 7. Running Workflows From 53d0471e2c5374b0c0d4f2e65956da358e290f59 Mon Sep 17 00:00:00 2001 From: Bentley Cook Date: Wed, 7 Feb 2024 15:27:02 -0600 Subject: [PATCH 3/3] Example getPosts.js run command amended --- docs/build-for-developers/cli-walkthrough.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/build-for-developers/cli-walkthrough.md b/docs/build-for-developers/cli-walkthrough.md index 9441231f95df..58fe4a2a22fa 100644 --- a/docs/build-for-developers/cli-walkthrough.md +++ b/docs/build-for-developers/cli-walkthrough.md @@ -554,7 +554,7 @@ Notice how this code uses the `each` function, a helper function defined in but accessed from this job that is using language-http. Most adaptors import and export many functions from `language-common`. -##### Run **openfn getPosts.js -a http -o tmp/output.json** +##### Run **openfn getPosts.js -a http -s tmp/state.json -o tmp/output.json**
Expand to see expected CLI logs