@openfn/language-magpi 1.2.3 → 1.2.5

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/ast.json CHANGED
@@ -364,7 +364,7 @@
364
364
  "operation"
365
365
  ],
366
366
  "docs": {
367
- "description": "Scopes an array of data based on a JSONPath.\nUseful when the source data has `n` items you would like to map to\nan operation.\nThe operation will receive a slice of the data based of each item\nof the JSONPath provided.\n\nIt also ensures the results of an operation make their way back into\nthe state's references.",
367
+ "description": "Iterates over an array of items and invokes an operation upon each one, where the state\nobject is _scoped_ so that state.data is the item under iteration.\nThe rest of the state object is untouched and can be referenced as usual.\nYou can pass an array directly, or use lazy state or a JSONPath string to\nreference a slice of state.",
368
368
  "tags": [
369
369
  {
370
370
  "title": "public",
@@ -378,7 +378,18 @@
378
378
  },
379
379
  {
380
380
  "title": "example",
381
- "description": "each(\"$.[*]\",\n create(\"SObject\",\n field(\"FirstName\", sourceValue(\"$.firstName\"))\n )\n)"
381
+ "description": "each(\n $.data,\n // Inside the callback operation, `$.data` is scoped to the item under iteration\n insert(\"patient\", {\n patient_name: $.data.properties.case_name,\n patient_id: $.data.case_id,\n })\n);",
382
+ "caption": "Using lazy state ($) to iterate over items in state.data and pass each into an \"insert\" operation"
383
+ },
384
+ {
385
+ "title": "example",
386
+ "description": "each(\n $.data,\n insert(\"patient\", (state) => ({\n patient_id: state.data.case_id,\n ...state.data\n }))\n);",
387
+ "caption": "Iterate over items in state.data and pass each one into an \"insert\" operation"
388
+ },
389
+ {
390
+ "title": "example",
391
+ "description": "each(\n \"$.data[*]\",\n insert(\"patient\", (state) => ({\n patient_name: state.data.properties.case_name,\n patient_id: state.data.case_id,\n }))\n);",
392
+ "caption": "Using JSON path to iterate over items in state.data and pass each one into an \"insert\" operation"
382
393
  },
383
394
  {
384
395
  "title": "param",
package/dist/index.cjs CHANGED
@@ -62,6 +62,7 @@ __export(Adaptor_exports, {
62
62
  submitRecord: () => submitRecord
63
63
  });
64
64
  var import_language_common = require("@openfn/language-common");
65
+ var import_util = require("@openfn/language-common/util");
65
66
  var import_url = require("url");
66
67
  var import_js2xmlparser = __toESM(require("js2xmlparser"), 1);
67
68
  var import_request = __toESM(require("request"), 1);
@@ -86,7 +87,8 @@ function fetchSurveyData(params) {
86
87
  return new Error(`Server responded with ${response.statusCode}`);
87
88
  }
88
89
  console.log(params.surveyId);
89
- const { surveyId, afterDate, beforeDate, postUrl } = (0, import_language_common.expandReferences)(params)(state);
90
+ const [resolvedParams] = (0, import_util.expandReferences)(state, params);
91
+ const { surveyId, afterDate, beforeDate, postUrl } = resolvedParams;
90
92
  console.log(surveyId);
91
93
  const { accessToken, username } = state.configuration;
92
94
  const enddate = beforeDate;
@@ -172,7 +174,7 @@ function fetchSurveyData(params) {
172
174
  }
173
175
  function submitRecord(jsonData) {
174
176
  return (state) => {
175
- const jsonBody = (0, import_language_common.expandReferences)(jsonData)(state);
177
+ const [jsonBody] = (0, import_util.expandReferences)(state, jsonData);
176
178
  const body = (0, import_js2xmlparser.default)("form", jsonBody);
177
179
  const { username, password, apiUrl } = state.configuration;
178
180
  const url = (0, import_url.resolve)(apiUrl + "/", "mobileApi/uploadData");
package/dist/index.js CHANGED
@@ -22,10 +22,8 @@ __export(Adaptor_exports, {
22
22
  sourceValue: () => sourceValue,
23
23
  submitRecord: () => submitRecord
24
24
  });
25
- import {
26
- execute as commonExecute,
27
- expandReferences
28
- } from "@openfn/language-common";
25
+ import { execute as commonExecute } from "@openfn/language-common";
26
+ import { expandReferences } from "@openfn/language-common/util";
29
27
  import { resolve as resolveUrl } from "url";
30
28
  import js2xmlparser from "js2xmlparser";
31
29
  import request from "request";
@@ -62,7 +60,8 @@ function fetchSurveyData(params) {
62
60
  return new Error(`Server responded with ${response.statusCode}`);
63
61
  }
64
62
  console.log(params.surveyId);
65
- const { surveyId, afterDate, beforeDate, postUrl } = expandReferences(params)(state);
63
+ const [resolvedParams] = expandReferences(state, params);
64
+ const { surveyId, afterDate, beforeDate, postUrl } = resolvedParams;
66
65
  console.log(surveyId);
67
66
  const { accessToken, username } = state.configuration;
68
67
  const enddate = beforeDate;
@@ -148,7 +147,7 @@ function fetchSurveyData(params) {
148
147
  }
149
148
  function submitRecord(jsonData) {
150
149
  return (state) => {
151
- const jsonBody = expandReferences(jsonData)(state);
150
+ const [jsonBody] = expandReferences(state, jsonData);
152
151
  const body = js2xmlparser("form", jsonBody);
153
152
  const { username, password, apiUrl } = state.configuration;
154
153
  const url = resolveUrl(apiUrl + "/", "mobileApi/uploadData");
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@openfn/language-magpi",
3
- "version": "1.2.3",
3
+ "label": "Magpi",
4
+ "version": "1.2.5",
4
5
  "description": "A Magpi Language Pack for OpenFn",
5
6
  "main": "dist/index.cjs",
6
7
  "author": "Open Function Group",
@@ -12,20 +13,18 @@
12
13
  "configuration-schema.json"
13
14
  ],
14
15
  "dependencies": {
15
- "@openfn/language-common": "^2.0.1",
16
16
  "JSONPath": "^0.10.0",
17
17
  "js2xmlparser": "^3.0.0",
18
18
  "lodash-fp": "^0.10.4",
19
19
  "request": "^2.88.2",
20
20
  "superagent": "^8.0.9",
21
- "xml2js": "0.5.0"
21
+ "xml2js": "0.5.0",
22
+ "@openfn/language-common": "3.0.0"
22
23
  },
23
24
  "devDependencies": {
24
- "@openfn/simple-ast": "0.4.1",
25
25
  "assertion-error": "^2.0.0",
26
26
  "chai": "^4.3.7",
27
27
  "deep-eql": "^4.1.3",
28
- "esno": "^0.16.3",
29
28
  "rimraf": "^3.0.2",
30
29
  "superagent-mock": "^4.0.0"
31
30
  },