@openfn/language-openhim 0.1.3 → 0.2.1

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
@@ -2,6 +2,49 @@
2
2
  "operations": [],
3
3
  "exports": [],
4
4
  "common": [
5
+ {
6
+ "name": "fn",
7
+ "params": [
8
+ "func"
9
+ ],
10
+ "docs": {
11
+ "description": "Creates a custom step (or operation) for more flexible job writing.",
12
+ "tags": [
13
+ {
14
+ "title": "public",
15
+ "description": null,
16
+ "type": null
17
+ },
18
+ {
19
+ "title": "example",
20
+ "description": "fn(state => {\n // do some things to state\n return state;\n});"
21
+ },
22
+ {
23
+ "title": "function",
24
+ "description": null,
25
+ "name": null
26
+ },
27
+ {
28
+ "title": "param",
29
+ "description": "is the function",
30
+ "type": {
31
+ "type": "NameExpression",
32
+ "name": "Function"
33
+ },
34
+ "name": "func"
35
+ },
36
+ {
37
+ "title": "returns",
38
+ "description": null,
39
+ "type": {
40
+ "type": "NameExpression",
41
+ "name": "Operation"
42
+ }
43
+ }
44
+ ]
45
+ },
46
+ "valid": true
47
+ },
5
48
  {
6
49
  "name": "sourceValue",
7
50
  "params": [
@@ -32,6 +75,14 @@
32
75
  "name": "String"
33
76
  },
34
77
  "name": "path"
78
+ },
79
+ {
80
+ "title": "returns",
81
+ "description": null,
82
+ "type": {
83
+ "type": "NameExpression",
84
+ "name": "Operation"
85
+ }
35
86
  }
36
87
  ]
37
88
  },
@@ -110,6 +161,14 @@
110
161
  "name": "String"
111
162
  },
112
163
  "name": "path"
164
+ },
165
+ {
166
+ "title": "returns",
167
+ "description": null,
168
+ "type": {
169
+ "type": "NameExpression",
170
+ "name": "Operation"
171
+ }
113
172
  }
114
173
  ]
115
174
  },
@@ -145,6 +204,14 @@
145
204
  "name": "String"
146
205
  },
147
206
  "name": "path"
207
+ },
208
+ {
209
+ "title": "returns",
210
+ "description": null,
211
+ "type": {
212
+ "type": "NameExpression",
213
+ "name": "Operation"
214
+ }
148
215
  }
149
216
  ]
150
217
  },
@@ -190,6 +257,14 @@
190
257
  "name": "Value"
191
258
  },
192
259
  "name": "value"
260
+ },
261
+ {
262
+ "title": "returns",
263
+ "description": null,
264
+ "type": {
265
+ "type": "NameExpression",
266
+ "name": "Field"
267
+ }
193
268
  }
194
269
  ]
195
270
  },
package/dist/index.cjs ADDED
@@ -0,0 +1,111 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+
25
+ // src/index.js
26
+ var src_exports = {};
27
+ __export(src_exports, {
28
+ dataPath: () => import_language_common2.dataPath,
29
+ dataValue: () => import_language_common2.dataValue,
30
+ default: () => src_default,
31
+ encounter: () => encounter,
32
+ execute: () => execute,
33
+ field: () => import_language_common2.field,
34
+ fields: () => import_language_common2.fields,
35
+ fn: () => import_language_common2.fn,
36
+ lastReferenceValue: () => import_language_common2.lastReferenceValue,
37
+ merge: () => import_language_common2.merge,
38
+ sourceValue: () => import_language_common2.sourceValue
39
+ });
40
+ module.exports = __toCommonJS(src_exports);
41
+
42
+ // src/Adaptor.js
43
+ var Adaptor_exports = {};
44
+ __export(Adaptor_exports, {
45
+ dataPath: () => import_language_common2.dataPath,
46
+ dataValue: () => import_language_common2.dataValue,
47
+ encounter: () => encounter,
48
+ execute: () => execute,
49
+ field: () => import_language_common2.field,
50
+ fields: () => import_language_common2.fields,
51
+ fn: () => import_language_common2.fn,
52
+ lastReferenceValue: () => import_language_common2.lastReferenceValue,
53
+ merge: () => import_language_common2.merge,
54
+ sourceValue: () => import_language_common2.sourceValue
55
+ });
56
+ var import_language_common = require("@openfn/language-common");
57
+
58
+ // src/Client.js
59
+ var import_superagent = __toESM(require("superagent"), 1);
60
+ function post({ username, password, body, url }) {
61
+ return new Promise((resolve, reject) => {
62
+ import_superagent.default.post(url).type("json").accept("json").auth(username, password).send(JSON.stringify(body)).end((error, res) => {
63
+ if (!!error || !res.ok) {
64
+ reject(error);
65
+ }
66
+ resolve(res);
67
+ });
68
+ });
69
+ }
70
+
71
+ // src/Adaptor.js
72
+ var import_url = require("url");
73
+ var import_language_common2 = require("@openfn/language-common");
74
+ function execute(...operations) {
75
+ const initialState = {
76
+ references: [],
77
+ data: null
78
+ };
79
+ return (state) => {
80
+ return (0, import_language_common.execute)(...operations)({ ...initialState, ...state });
81
+ };
82
+ }
83
+ function encounter(encounterData) {
84
+ return (state) => {
85
+ const body = (0, import_language_common.expandReferences)(encounterData)(state);
86
+ const { username, password, apiUrl } = state.configuration;
87
+ const url = (0, import_url.resolve)(apiUrl + "/", "chw/encounter");
88
+ console.log("Posting encounter:");
89
+ console.log(JSON.stringify(body, null, 2));
90
+ return post({ username, password, body, url }).then((result) => {
91
+ console.log("Success:", result);
92
+ return { ...state, references: [result, ...state.references] };
93
+ });
94
+ };
95
+ }
96
+
97
+ // src/index.js
98
+ var src_default = Adaptor_exports;
99
+ // Annotate the CommonJS export names for ESM import in node:
100
+ 0 && (module.exports = {
101
+ dataPath,
102
+ dataValue,
103
+ encounter,
104
+ execute,
105
+ field,
106
+ fields,
107
+ fn,
108
+ lastReferenceValue,
109
+ merge,
110
+ sourceValue
111
+ });
package/dist/index.js ADDED
@@ -0,0 +1,88 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/Adaptor.js
8
+ var Adaptor_exports = {};
9
+ __export(Adaptor_exports, {
10
+ dataPath: () => dataPath,
11
+ dataValue: () => dataValue,
12
+ encounter: () => encounter,
13
+ execute: () => execute,
14
+ field: () => field,
15
+ fields: () => fields,
16
+ fn: () => fn,
17
+ lastReferenceValue: () => lastReferenceValue,
18
+ merge: () => merge,
19
+ sourceValue: () => sourceValue
20
+ });
21
+ import {
22
+ execute as commonExecute,
23
+ expandReferences
24
+ } from "@openfn/language-common";
25
+
26
+ // src/Client.js
27
+ import request from "superagent";
28
+ function post({ username, password, body, url }) {
29
+ return new Promise((resolve, reject) => {
30
+ request.post(url).type("json").accept("json").auth(username, password).send(JSON.stringify(body)).end((error, res) => {
31
+ if (!!error || !res.ok) {
32
+ reject(error);
33
+ }
34
+ resolve(res);
35
+ });
36
+ });
37
+ }
38
+
39
+ // src/Adaptor.js
40
+ import { resolve as resolveUrl } from "url";
41
+ import {
42
+ fn,
43
+ field,
44
+ fields,
45
+ sourceValue,
46
+ merge,
47
+ dataPath,
48
+ dataValue,
49
+ lastReferenceValue
50
+ } from "@openfn/language-common";
51
+ function execute(...operations) {
52
+ const initialState = {
53
+ references: [],
54
+ data: null
55
+ };
56
+ return (state) => {
57
+ return commonExecute(...operations)({ ...initialState, ...state });
58
+ };
59
+ }
60
+ function encounter(encounterData) {
61
+ return (state) => {
62
+ const body = expandReferences(encounterData)(state);
63
+ const { username, password, apiUrl } = state.configuration;
64
+ const url = resolveUrl(apiUrl + "/", "chw/encounter");
65
+ console.log("Posting encounter:");
66
+ console.log(JSON.stringify(body, null, 2));
67
+ return post({ username, password, body, url }).then((result) => {
68
+ console.log("Success:", result);
69
+ return { ...state, references: [result, ...state.references] };
70
+ });
71
+ };
72
+ }
73
+
74
+ // src/index.js
75
+ var src_default = Adaptor_exports;
76
+ export {
77
+ dataPath,
78
+ dataValue,
79
+ src_default as default,
80
+ encounter,
81
+ execute,
82
+ field,
83
+ fields,
84
+ fn,
85
+ lastReferenceValue,
86
+ merge,
87
+ sourceValue
88
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/language-openhim",
3
- "version": "0.1.3",
3
+ "version": "0.2.1",
4
4
  "description": "openhim Language Pack for OpenFn",
5
5
  "main": "dist/index.cjs",
6
6
  "author": "Open Function Group",
@@ -13,7 +13,7 @@
13
13
  ],
14
14
  "dependencies": {
15
15
  "JSONPath": "^0.10.0",
16
- "@openfn/language-common": "^1.7.5",
16
+ "@openfn/language-common": "^1.8.1",
17
17
  "lodash-fp": "^0.10.2",
18
18
  "superagent": "^3.7.0"
19
19
  },
@@ -47,10 +47,11 @@
47
47
  },
48
48
  "types": "types/index.d.ts",
49
49
  "scripts": {
50
- "build": "pnpm clean && build-adaptor mssql",
50
+ "build": "pnpm clean && build-adaptor openhim",
51
51
  "test": "mocha --experimental-specifier-resolution=node --no-warnings",
52
52
  "test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings",
53
53
  "clean": "rimraf dist types docs",
54
- "pack": "pnpm pack --pack-destination ../../dist"
54
+ "pack": "pnpm pack --pack-destination ../../dist",
55
+ "lint": "eslint src"
55
56
  }
56
57
  }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Execute a sequence of operations.
3
+ * Wraps `language-common/execute`, and prepends initial state for openhim.
4
+ * @example
5
+ * execute(
6
+ * create('foo'),
7
+ * delete('bar')
8
+ * )(state)
9
+ * @private
10
+ * @param {Operations} operations - Operations to be performed.
11
+ * @returns {Operation}
12
+ */
13
+ export function execute(...operations: Operations): Operation;
14
+ /**
15
+ * Create an encounter
16
+ * @example
17
+ * execute(
18
+ * encounter(data)
19
+ * )(state)
20
+ * @function
21
+ * @param {object} encounterData - Payload data for the encounter
22
+ * @returns {Operation}
23
+ */
24
+ export function encounter(encounterData: object): Operation;
25
+ export { fn, field, fields, sourceValue, merge, dataPath, dataValue, lastReferenceValue } from "@openfn/language-common";
@@ -0,0 +1,6 @@
1
+ export function post({ username, password, body, url }: {
2
+ username: any;
3
+ password: any;
4
+ body: any;
5
+ url: any;
6
+ }): Promise<any>;
@@ -0,0 +1,3 @@
1
+ export default Adaptor;
2
+ export * from "./Adaptor";
3
+ import * as Adaptor from "./Adaptor";