@openfn/language-dhis2 3.2.8 → 3.2.10
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/dist/index.cjs +24 -58
- package/dist/index.js +4 -34
- package/package.json +3 -3
- package/types/Adaptor.d.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -53,42 +53,8 @@ __export(src_exports, {
|
|
|
53
53
|
});
|
|
54
54
|
module.exports = __toCommonJS(src_exports);
|
|
55
55
|
|
|
56
|
-
//
|
|
57
|
-
var
|
|
58
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
59
|
-
|
|
60
|
-
// ../../tools/metadata/src/model.js
|
|
61
|
-
var createEntity = (name, type, props = {}, children) => {
|
|
62
|
-
const { label, datatype, value, ...meta } = props;
|
|
63
|
-
const e = {
|
|
64
|
-
name,
|
|
65
|
-
type,
|
|
66
|
-
addChild: function(e2, name2) {
|
|
67
|
-
if (!this.children) {
|
|
68
|
-
this.children = name2 ? {} : [];
|
|
69
|
-
}
|
|
70
|
-
if (name2) {
|
|
71
|
-
if (isArray(this.children)) {
|
|
72
|
-
throw new Error("Cannot add a named entity to child array");
|
|
73
|
-
}
|
|
74
|
-
this.children[name2] = e2;
|
|
75
|
-
} else {
|
|
76
|
-
this.children.push(e2);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
if (label) {
|
|
81
|
-
e.label = label;
|
|
82
|
-
}
|
|
83
|
-
if (datatype) {
|
|
84
|
-
e.datatype = datatype;
|
|
85
|
-
}
|
|
86
|
-
if (children) {
|
|
87
|
-
e.children = children;
|
|
88
|
-
}
|
|
89
|
-
e.meta = meta || {};
|
|
90
|
-
return e;
|
|
91
|
-
};
|
|
56
|
+
// src/meta/metadata.js
|
|
57
|
+
var import_metadata = require("@openfn/language-common/metadata");
|
|
92
58
|
|
|
93
59
|
// src/meta/helper.js
|
|
94
60
|
var import_axios = __toESM(require("axios"), 1);
|
|
@@ -137,11 +103,11 @@ function handleResponse(result, state, callback) {
|
|
|
137
103
|
function prettyJson(data) {
|
|
138
104
|
return JSON.stringify(data, null, 2);
|
|
139
105
|
}
|
|
140
|
-
var
|
|
106
|
+
var isArray = (variable) => !!variable && variable.constructor === Array;
|
|
141
107
|
function nestArray(data, key) {
|
|
142
|
-
return
|
|
108
|
+
return isArray(data) ? { [key]: data } : data;
|
|
143
109
|
}
|
|
144
|
-
function generateUrl(configuration, options, resourceType,
|
|
110
|
+
function generateUrl(configuration, options, resourceType, path = null) {
|
|
145
111
|
let { hostUrl, apiVersion } = configuration;
|
|
146
112
|
const urlString = "/" + resourceType;
|
|
147
113
|
if (options == null ? void 0 : options.apiVersion)
|
|
@@ -149,8 +115,8 @@ function generateUrl(configuration, options, resourceType, path2 = null) {
|
|
|
149
115
|
const apiMessage = apiVersion ? `Using DHIS2 api version ${apiVersion}` : "Using latest available version of the DHIS2 api on this server.";
|
|
150
116
|
console.log(apiMessage);
|
|
151
117
|
const url = buildUrl(urlString, hostUrl, apiVersion);
|
|
152
|
-
if (
|
|
153
|
-
return `${url}/${
|
|
118
|
+
if (path)
|
|
119
|
+
return `${url}/${path}`;
|
|
154
120
|
return url;
|
|
155
121
|
}
|
|
156
122
|
|
|
@@ -216,7 +182,7 @@ var metadata = async (configuration = {}, helper) => {
|
|
|
216
182
|
const children = {};
|
|
217
183
|
const units = await helper.getOrgUnits();
|
|
218
184
|
children.orgUnits = units.organisationUnits.map(
|
|
219
|
-
(unit) => createEntity(unit.id, "orgUnit", {
|
|
185
|
+
(unit) => (0, import_metadata.createEntity)(unit.id, "orgUnit", {
|
|
220
186
|
datatype: "string",
|
|
221
187
|
label: unit.displayName
|
|
222
188
|
})
|
|
@@ -224,14 +190,14 @@ var metadata = async (configuration = {}, helper) => {
|
|
|
224
190
|
children.resourceTypes = await helper.getResourceTypes();
|
|
225
191
|
const types = await helper.getTrackedEntityTypes() ?? [];
|
|
226
192
|
children.trackedEntityTypes = ((_a = types.trackedEntityTypes) == null ? void 0 : _a.map(
|
|
227
|
-
(type) => createEntity(type.id, "trackedEntityType", {
|
|
193
|
+
(type) => (0, import_metadata.createEntity)(type.id, "trackedEntityType", {
|
|
228
194
|
datatype: "string",
|
|
229
195
|
label: type.displayName
|
|
230
196
|
})
|
|
231
197
|
)) ?? [];
|
|
232
198
|
const attributes = await helper.getAttributes() ?? [];
|
|
233
199
|
children.attributes = ((_b = attributes.attributes) == null ? void 0 : _b.map(
|
|
234
|
-
(attr2) => createEntity(attr2.id, "attribute", {
|
|
200
|
+
(attr2) => (0, import_metadata.createEntity)(attr2.id, "attribute", {
|
|
235
201
|
datatype: "string",
|
|
236
202
|
label: attr2.displayName
|
|
237
203
|
})
|
|
@@ -388,23 +354,23 @@ function create(resourceType, data, options = {}, callback = false) {
|
|
|
388
354
|
});
|
|
389
355
|
};
|
|
390
356
|
}
|
|
391
|
-
function update(resourceType,
|
|
357
|
+
function update(resourceType, path, data, options = {}, callback = false) {
|
|
392
358
|
return (state) => {
|
|
393
359
|
console.log(`Preparing update operation...`);
|
|
394
360
|
resourceType = (0, import_language_common2.expandReferences)(resourceType)(state);
|
|
395
|
-
|
|
361
|
+
path = (0, import_language_common2.expandReferences)(path)(state);
|
|
396
362
|
data = (0, import_language_common2.expandReferences)(data)(state);
|
|
397
363
|
options = (0, import_language_common2.expandReferences)(options)(state);
|
|
398
364
|
const { params, requestConfig } = options;
|
|
399
365
|
const { configuration } = state;
|
|
400
366
|
return request(configuration, {
|
|
401
367
|
method: "put",
|
|
402
|
-
url: generateUrl(configuration, options, resourceType,
|
|
368
|
+
url: generateUrl(configuration, options, resourceType, path),
|
|
403
369
|
params,
|
|
404
370
|
data,
|
|
405
371
|
...requestConfig
|
|
406
372
|
}).then((result) => {
|
|
407
|
-
Log.success(`Updated ${resourceType} at ${
|
|
373
|
+
Log.success(`Updated ${resourceType} at ${path}`);
|
|
408
374
|
return handleResponse(result, state, callback);
|
|
409
375
|
});
|
|
410
376
|
};
|
|
@@ -445,8 +411,8 @@ function upsert(resourceType, query, data, options = {}, callback = false) {
|
|
|
445
411
|
} else if (resources.length <= 0) {
|
|
446
412
|
return create(resourceType, data, options)(state);
|
|
447
413
|
} else {
|
|
448
|
-
const
|
|
449
|
-
return update(resourceType,
|
|
414
|
+
const path = resources[0][selectId(resourceType)];
|
|
415
|
+
return update(resourceType, path, data, options)(state);
|
|
450
416
|
}
|
|
451
417
|
}).then((result) => {
|
|
452
418
|
Log.success(`Performed a "composed upsert" on ${resourceType}`);
|
|
@@ -520,44 +486,44 @@ ${prettyJson(
|
|
|
520
486
|
});
|
|
521
487
|
};
|
|
522
488
|
}
|
|
523
|
-
function patch(resourceType,
|
|
489
|
+
function patch(resourceType, path, data, options = {}, callback = false) {
|
|
524
490
|
return (state) => {
|
|
525
491
|
console.log("Preparing patch operation...");
|
|
526
492
|
resourceType = (0, import_language_common2.expandReferences)(resourceType)(state);
|
|
527
|
-
|
|
493
|
+
path = (0, import_language_common2.expandReferences)(path)(state);
|
|
528
494
|
data = (0, import_language_common2.expandReferences)(data)(state);
|
|
529
495
|
options = (0, import_language_common2.expandReferences)(options)(state);
|
|
530
496
|
const { params, requestConfig } = options;
|
|
531
497
|
const { configuration } = state;
|
|
532
498
|
return request(configuration, {
|
|
533
499
|
method: "patch",
|
|
534
|
-
url: generateUrl(configuration, options, resourceType,
|
|
500
|
+
url: generateUrl(configuration, options, resourceType, path),
|
|
535
501
|
params,
|
|
536
502
|
data,
|
|
537
503
|
...requestConfig
|
|
538
504
|
}).then((result) => {
|
|
539
|
-
Log.success(`Patched ${resourceType} at ${
|
|
505
|
+
Log.success(`Patched ${resourceType} at ${path}`);
|
|
540
506
|
return handleResponse(result, state, callback);
|
|
541
507
|
});
|
|
542
508
|
};
|
|
543
509
|
}
|
|
544
|
-
function destroy(resourceType,
|
|
510
|
+
function destroy(resourceType, path, data = null, options = {}, callback = false) {
|
|
545
511
|
return (state) => {
|
|
546
512
|
console.log("Preparing destroy operation...");
|
|
547
513
|
resourceType = (0, import_language_common2.expandReferences)(resourceType)(state);
|
|
548
|
-
|
|
514
|
+
path = (0, import_language_common2.expandReferences)(path)(state);
|
|
549
515
|
data = (0, import_language_common2.expandReferences)(data)(state);
|
|
550
516
|
options = (0, import_language_common2.expandReferences)(options)(state);
|
|
551
517
|
const { params, requestConfig } = options;
|
|
552
518
|
const { configuration } = state;
|
|
553
519
|
return request({
|
|
554
520
|
method: "delete",
|
|
555
|
-
url: generateUrl(configuration, options, resourceType,
|
|
521
|
+
url: generateUrl(configuration, options, resourceType, path),
|
|
556
522
|
params,
|
|
557
523
|
data,
|
|
558
524
|
...requestConfig
|
|
559
525
|
}).then((result) => {
|
|
560
|
-
Log.success(`Deleted ${resourceType} at ${
|
|
526
|
+
Log.success(`Deleted ${resourceType} at ${path}`);
|
|
561
527
|
return handleResponse(result, state, callback);
|
|
562
528
|
});
|
|
563
529
|
};
|
package/dist/index.js
CHANGED
|
@@ -4,38 +4,8 @@ var __export = (target, all) => {
|
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
const { label, datatype, value, ...meta } = props;
|
|
10
|
-
const e = {
|
|
11
|
-
name,
|
|
12
|
-
type,
|
|
13
|
-
addChild: function(e2, name2) {
|
|
14
|
-
if (!this.children) {
|
|
15
|
-
this.children = name2 ? {} : [];
|
|
16
|
-
}
|
|
17
|
-
if (name2) {
|
|
18
|
-
if (isArray(this.children)) {
|
|
19
|
-
throw new Error("Cannot add a named entity to child array");
|
|
20
|
-
}
|
|
21
|
-
this.children[name2] = e2;
|
|
22
|
-
} else {
|
|
23
|
-
this.children.push(e2);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
if (label) {
|
|
28
|
-
e.label = label;
|
|
29
|
-
}
|
|
30
|
-
if (datatype) {
|
|
31
|
-
e.datatype = datatype;
|
|
32
|
-
}
|
|
33
|
-
if (children) {
|
|
34
|
-
e.children = children;
|
|
35
|
-
}
|
|
36
|
-
e.meta = meta || {};
|
|
37
|
-
return e;
|
|
38
|
-
};
|
|
7
|
+
// src/meta/metadata.js
|
|
8
|
+
import { createEntity } from "@openfn/language-common/metadata";
|
|
39
9
|
|
|
40
10
|
// src/meta/helper.js
|
|
41
11
|
import axios from "axios";
|
|
@@ -84,9 +54,9 @@ function handleResponse(result, state, callback) {
|
|
|
84
54
|
function prettyJson(data) {
|
|
85
55
|
return JSON.stringify(data, null, 2);
|
|
86
56
|
}
|
|
87
|
-
var
|
|
57
|
+
var isArray = (variable) => !!variable && variable.constructor === Array;
|
|
88
58
|
function nestArray(data, key) {
|
|
89
|
-
return
|
|
59
|
+
return isArray(data) ? { [key]: data } : data;
|
|
90
60
|
}
|
|
91
61
|
function generateUrl(configuration, options, resourceType, path = null) {
|
|
92
62
|
let { hostUrl, apiVersion } = configuration;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-dhis2",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.10",
|
|
4
4
|
"description": "DHIS2 Language Pack for OpenFn",
|
|
5
5
|
"homepage": "https://docs.openfn.org",
|
|
6
6
|
"repository": {
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@openfn/buildtools": "^1.0.2",
|
|
28
|
-
"@openfn/language-common": "^1.7.
|
|
28
|
+
"@openfn/language-common": "^1.7.7",
|
|
29
29
|
"axios": "^0.24.0",
|
|
30
30
|
"lodash": "^4.17.19",
|
|
31
31
|
"qs": "^6.11.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@openfn/buildtools": "^1.0.2",
|
|
35
|
-
"@openfn/metadata": "^1.0.
|
|
35
|
+
"@openfn/metadata": "^1.0.1",
|
|
36
36
|
"@openfn/parse-jsdoc": "^1.0.0",
|
|
37
37
|
"@openfn/simple-ast": "0.4.1",
|
|
38
38
|
"assertion-error": "2.0.0",
|