@dhis2/app-service-data 3.11.3 → 3.12.0-alpha.2

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.
Files changed (113) hide show
  1. package/build/cjs/__tests__/integration.test.js +6 -15
  2. package/build/cjs/__tests__/mutations.test.js +4 -11
  3. package/build/cjs/engine/DataEngine.js +4 -14
  4. package/build/cjs/engine/DataEngine.test.js +0 -2
  5. package/build/cjs/engine/helpers/getMutationFetchType.js +0 -2
  6. package/build/cjs/engine/helpers/getMutationFetchType.test.js +0 -1
  7. package/build/cjs/engine/helpers/resolveDynamicQuery.js +0 -2
  8. package/build/cjs/engine/helpers/resolveDynamicQuery.test.js +3 -4
  9. package/build/cjs/engine/helpers/validate.js +0 -21
  10. package/build/cjs/engine/helpers/validate.test.js +0 -1
  11. package/build/cjs/engine/index.js +0 -18
  12. package/build/cjs/engine/types/FetchError.js +3 -8
  13. package/build/cjs/engine/types/FetchError.test.js +0 -1
  14. package/build/cjs/engine/types/InvalidQueryError.js +3 -8
  15. package/build/cjs/index.js +0 -2
  16. package/build/cjs/links/CustomDataLink.js +3 -17
  17. package/build/cjs/links/CustomDataLink.test.js +0 -1
  18. package/build/cjs/links/ErrorLink.js +3 -7
  19. package/build/cjs/links/RestAPILink/fetchData.js +12 -22
  20. package/build/cjs/links/RestAPILink/fetchData.test.js +0 -2
  21. package/build/cjs/links/RestAPILink/metadataResources.js +9 -7
  22. package/build/cjs/links/RestAPILink/path.js +0 -3
  23. package/build/cjs/links/RestAPILink/path.test.js +0 -1
  24. package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +9 -14
  25. package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.test.js +0 -1
  26. package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.js +4 -31
  27. package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +0 -1
  28. package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +22 -39
  29. package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.test.js +0 -1
  30. package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +0 -2
  31. package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.test.js +0 -1
  32. package/build/cjs/links/RestAPILink/queryToRequestOptions.js +0 -9
  33. package/build/cjs/links/RestAPILink/queryToRequestOptions.test.js +0 -1
  34. package/build/cjs/links/RestAPILink/queryToResourcePath.js +3 -24
  35. package/build/cjs/links/RestAPILink/queryToResourcePath.test.js +2 -4
  36. package/build/cjs/links/RestAPILink/validateQuery.js +4 -18
  37. package/build/cjs/links/RestAPILink/validateQuery.test.js +0 -1
  38. package/build/cjs/links/RestAPILink.js +3 -14
  39. package/build/cjs/links/RestAPILink.test.js +0 -2
  40. package/build/cjs/links/index.js +0 -6
  41. package/build/cjs/react/components/CustomDataProvider.js +3 -12
  42. package/build/cjs/react/components/DataMutation.js +1 -4
  43. package/build/cjs/react/components/DataProvider.js +11 -16
  44. package/build/cjs/react/components/DataProvider.test.js +2 -9
  45. package/build/cjs/react/components/DataQuery.js +1 -4
  46. package/build/cjs/react/context/DataContext.js +2 -8
  47. package/build/cjs/react/context/defaultContext.js +2 -6
  48. package/build/cjs/react/context/defaultContext.test.js +0 -1
  49. package/build/cjs/react/hooks/mergeAndCompareVariables.js +4 -6
  50. package/build/cjs/react/hooks/mergeAndCompareVariables.test.js +2 -3
  51. package/build/cjs/react/hooks/stableVariablesHash.js +11 -16
  52. package/build/cjs/react/hooks/stableVariablesHash.test.js +0 -1
  53. package/build/cjs/react/hooks/useDataEngine.js +0 -4
  54. package/build/cjs/react/hooks/useDataMutation.js +0 -7
  55. package/build/cjs/react/hooks/useDataMutation.test.js +42 -71
  56. package/build/cjs/react/hooks/useDataQuery.js +26 -44
  57. package/build/cjs/react/hooks/useDataQuery.test.js +318 -374
  58. package/build/cjs/react/hooks/useQueryExecutor.js +6 -14
  59. package/build/cjs/react/hooks/useQueryExecutor.test.js +42 -45
  60. package/build/cjs/react/hooks/useStaticInput.js +0 -3
  61. package/build/cjs/react/hooks/useStaticInput.test.js +8 -10
  62. package/build/cjs/react/index.js +0 -11
  63. package/build/cjs/setupRTL.js +1 -2
  64. package/build/es/__tests__/integration.test.js +4 -8
  65. package/build/es/__tests__/mutations.test.js +2 -4
  66. package/build/es/engine/DataEngine.js +3 -8
  67. package/build/es/engine/DataEngine.test.js +0 -1
  68. package/build/es/engine/helpers/resolveDynamicQuery.test.js +3 -3
  69. package/build/es/engine/helpers/validate.js +0 -13
  70. package/build/es/engine/types/FetchError.js +3 -6
  71. package/build/es/engine/types/InvalidQueryError.js +3 -6
  72. package/build/es/links/CustomDataLink.js +3 -15
  73. package/build/es/links/ErrorLink.js +3 -5
  74. package/build/es/links/RestAPILink/fetchData.js +12 -16
  75. package/build/es/links/RestAPILink/metadataResources.js +8 -3
  76. package/build/es/links/RestAPILink/path.js +0 -1
  77. package/build/es/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +9 -4
  78. package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.js +2 -19
  79. package/build/es/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +22 -19
  80. package/build/es/links/RestAPILink/queryToRequestOptions.js +0 -7
  81. package/build/es/links/RestAPILink/queryToResourcePath.js +3 -21
  82. package/build/es/links/RestAPILink/queryToResourcePath.test.js +2 -3
  83. package/build/es/links/RestAPILink/validateQuery.js +4 -16
  84. package/build/es/links/RestAPILink.js +3 -8
  85. package/build/es/react/components/CustomDataProvider.js +2 -2
  86. package/build/es/react/components/DataMutation.js +1 -1
  87. package/build/es/react/components/DataProvider.js +9 -3
  88. package/build/es/react/components/DataProvider.test.js +1 -1
  89. package/build/es/react/components/DataQuery.js +1 -1
  90. package/build/es/react/hooks/mergeAndCompareVariables.js +4 -3
  91. package/build/es/react/hooks/mergeAndCompareVariables.test.js +2 -1
  92. package/build/es/react/hooks/stableVariablesHash.js +11 -14
  93. package/build/es/react/hooks/useDataMutation.test.js +17 -39
  94. package/build/es/react/hooks/useDataQuery.js +26 -37
  95. package/build/es/react/hooks/useDataQuery.test.js +268 -318
  96. package/build/es/react/hooks/useQueryExecutor.js +6 -9
  97. package/build/es/react/hooks/useQueryExecutor.test.js +33 -34
  98. package/build/es/react/hooks/useStaticInput.test.js +6 -6
  99. package/build/es/setupRTL.js +1 -1
  100. package/build/types/engine/types/ExecuteOptions.d.ts +1 -1
  101. package/build/types/engine/types/FetchError.d.ts +2 -2
  102. package/build/types/engine/types/JsonValue.d.ts +1 -1
  103. package/build/types/engine/types/Mutation.d.ts +2 -2
  104. package/build/types/engine/types/PossiblyDynamic.d.ts +1 -1
  105. package/build/types/engine/types/Query.d.ts +3 -3
  106. package/build/types/engine/types/QueryParameters.d.ts +4 -4
  107. package/build/types/links/CustomDataLink.d.ts +2 -2
  108. package/build/types/links/RestAPILink/queryToRequestOptions/requestContentType.d.ts +1 -1
  109. package/build/types/links/RestAPILink/queryToRequestOptions.d.ts +1 -1
  110. package/build/types/react/components/DataProvider.d.ts +2 -11
  111. package/build/types/react/hooks/mergeAndCompareVariables.d.ts +1 -1
  112. package/build/types/types.d.ts +6 -6
  113. package/package.json +5 -5
@@ -4,34 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.queryToResourcePath = void 0;
7
-
8
7
  var _path = require("./path");
9
-
10
8
  var _validateQuery = require("./validateQuery");
11
-
12
9
  const encodeQueryParameter = param => {
13
10
  if (Array.isArray(param)) {
14
11
  return param.map(encodeQueryParameter).join(',');
15
12
  }
16
-
17
13
  if (typeof param === 'string') {
18
14
  return encodeURIComponent(param);
19
15
  }
20
-
21
16
  if (typeof param === 'number' || typeof param === 'boolean') {
22
17
  return String(param);
23
18
  }
24
-
25
19
  if (typeof param === 'object') {
26
20
  throw new Error('Object parameter mappings not yet implemented');
27
21
  }
28
-
29
22
  throw new Error('Unknown parameter type');
30
23
  };
31
-
32
24
  const queryParametersMapToArray = params => Object.keys(params).reduce((out, key) => {
33
25
  const value = params[key];
34
-
35
26
  if (key === 'filter' && Array.isArray(value)) {
36
27
  value.forEach(item => {
37
28
  out.push({
@@ -45,13 +36,11 @@ const queryParametersMapToArray = params => Object.keys(params).reduce((out, key
45
36
  value: params[key]
46
37
  });
47
38
  }
48
-
49
39
  return out;
50
40
  }, []);
51
-
52
41
  const queryParametersToQueryString = params => {
53
42
  const expandedParams = queryParametersMapToArray(params);
54
- return expandedParams.map((_ref) => {
43
+ return expandedParams.map(_ref => {
55
44
  let {
56
45
  key,
57
46
  value
@@ -59,30 +48,23 @@ const queryParametersToQueryString = params => {
59
48
  return `${encodeURIComponent(key)}=${encodeQueryParameter(value)}`;
60
49
  }).join('&');
61
50
  };
62
-
63
51
  const actionPrefix = 'action::';
64
-
65
52
  const isAction = resource => resource.startsWith(actionPrefix);
66
-
67
53
  const makeActionPath = resource => (0, _path.joinPath)('dhis-web-commons', `${resource.substr(actionPrefix.length)}.action`);
68
-
69
54
  const skipApiVersion = (resource, config) => {
70
55
  if (resource === 'tracker' || resource.startsWith('tracker/')) {
71
56
  var _config$serverVersion, _config$serverVersion2;
72
-
73
57
  if (!((_config$serverVersion = config.serverVersion) !== null && _config$serverVersion !== void 0 && _config$serverVersion.minor) || ((_config$serverVersion2 = config.serverVersion) === null || _config$serverVersion2 === void 0 ? void 0 : _config$serverVersion2.minor) < 38) {
74
58
  return true;
75
59
  }
76
- } // The `/api/ping` endpoint is unversioned
77
-
60
+ }
78
61
 
62
+ // The `/api/ping` endpoint is unversioned
79
63
  if (resource === 'ping') {
80
64
  return true;
81
65
  }
82
-
83
66
  return false;
84
67
  };
85
-
86
68
  const queryToResourcePath = (link, query, type) => {
87
69
  const {
88
70
  resource,
@@ -92,12 +74,9 @@ const queryToResourcePath = (link, query, type) => {
92
74
  const apiBase = skipApiVersion(resource, link.config) ? link.unversionedApiPath : link.versionedApiPath;
93
75
  const base = isAction(resource) ? makeActionPath(resource) : (0, _path.joinPath)(apiBase, resource, id);
94
76
  (0, _validateQuery.validateResourceQuery)(query, type);
95
-
96
77
  if (Object.keys(params).length) {
97
78
  return `${base}?${queryParametersToQueryString(params)}`;
98
79
  }
99
-
100
80
  return base;
101
81
  };
102
-
103
82
  exports.queryToResourcePath = queryToResourcePath;
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
 
3
3
  var _RestAPILink = require("../RestAPILink");
4
-
5
4
  var _queryToResourcePath = require("./queryToResourcePath");
6
-
7
5
  const createLink = config => new _RestAPILink.RestAPILink(config);
8
-
9
6
  const defaultConfig = {
10
7
  basePath: '<base>',
11
8
  apiVersion: '37',
@@ -163,7 +160,8 @@ describe('queryToResourcePath', () => {
163
160
  const query = {
164
161
  resource: 'tracker'
165
162
  };
166
- const v38config = { ...defaultConfig,
163
+ const v38config = {
164
+ ...defaultConfig,
167
165
  serverVersion: {
168
166
  major: 2,
169
167
  minor: 38,
@@ -4,70 +4,56 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.validateResourceQuery = void 0;
7
-
8
7
  var _metadataResources = require("./metadataResources");
9
-
10
8
  const validatePagination = (query, warn) => {
11
9
  var _query$params, _query$params2;
12
-
13
10
  if (!_metadataResources.normativeMetadataResources.includes(query.resource)) {
14
11
  return true;
15
12
  }
16
-
17
13
  if (((_query$params = query.params) === null || _query$params === void 0 ? void 0 : _query$params.paging) === false || ((_query$params2 = query.params) === null || _query$params2 === void 0 ? void 0 : _query$params2.paging) === 'false') {
18
14
  warn('Data queries with paging=false are deprecated and should not be used!', query);
19
15
  return false;
20
- } // TODO: validate sub-resource pagination (i.e. fields=users~paging(1,50)[name] )
16
+ }
21
17
 
18
+ // TODO: validate sub-resource pagination (i.e. fields=users~paging(1,50)[name] )
22
19
 
23
20
  return true;
24
21
  };
25
-
26
22
  const validateDeclarativeFields = (query, warn) => {
27
23
  var _query$params3;
28
-
29
24
  if (!_metadataResources.normativeMetadataResources.includes(query.resource)) {
30
25
  return true;
31
26
  }
32
-
33
27
  if (!((_query$params3 = query.params) !== null && _query$params3 !== void 0 && _query$params3.fields)) {
34
28
  warn('Data queries should always specify fields to return', query);
35
29
  return false;
36
30
  } else {
37
31
  var _fields;
38
-
39
32
  let fields = undefined;
40
-
41
33
  if (typeof query.params.fields === 'string') {
42
34
  fields = query.params.fields.split(',').map(field => field.trim());
43
35
  } else if (Array.isArray(query.params.fields)) {
44
36
  fields = query.params.fields.map(field => String(field).trim());
45
37
  }
46
-
47
38
  if ((_fields = fields) !== null && _fields !== void 0 && _fields.find(field => field.match(/(^\*$|^:.+)/))) {
48
39
  warn('Data queries should not use wildcard or dynamic field groups', query.params.fields, query);
49
40
  return false;
50
41
  }
51
- } // TODO: validate sub-resource wildcard fields (i.e. fields=users[*])
52
-
42
+ }
53
43
 
44
+ // TODO: validate sub-resource wildcard fields (i.e. fields=users[*])
54
45
  return true;
55
46
  };
56
-
57
47
  const validateResourceQuery = (query, type) => {
58
48
  let valid = true;
59
-
60
49
  if (process.env.NODE_ENV === 'development') {
61
50
  // Support build-time dead code elimination in production
62
51
  const warn = console.warn;
63
-
64
52
  if (type === 'read') {
65
53
  valid = validatePagination(query, warn) && valid;
66
54
  valid = validateDeclarativeFields(query, warn) && valid;
67
55
  }
68
56
  }
69
-
70
57
  return valid;
71
58
  };
72
-
73
59
  exports.validateResourceQuery = validateResourceQuery;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _validateQuery = require("./validateQuery");
4
-
5
4
  describe('validateQuery', () => {
6
5
  const originalConsoleWarn = console.warn;
7
6
  afterAll(() => {
@@ -4,41 +4,30 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.RestAPILink = void 0;
7
-
8
7
  var _fetchData = require("./RestAPILink/fetchData");
9
-
10
8
  var _path = require("./RestAPILink/path");
11
-
12
9
  var _queryToRequestOptions = require("./RestAPILink/queryToRequestOptions");
13
-
14
10
  var _queryToResourcePath = require("./RestAPILink/queryToResourcePath");
15
-
16
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
-
11
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
12
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
13
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
18
14
  class RestAPILink {
19
15
  constructor(config) {
20
16
  _defineProperty(this, "config", void 0);
21
-
22
17
  _defineProperty(this, "versionedApiPath", void 0);
23
-
24
18
  _defineProperty(this, "unversionedApiPath", void 0);
25
-
26
19
  this.config = config;
27
20
  this.versionedApiPath = (0, _path.joinPath)('api', String(config.apiVersion));
28
21
  this.unversionedApiPath = (0, _path.joinPath)('api');
29
22
  }
30
-
31
23
  fetch(path, options) {
32
24
  return (0, _fetchData.fetchData)((0, _path.joinPath)(this.config.baseUrl, path), options);
33
25
  }
34
-
35
26
  executeResourceQuery(type, query, _ref) {
36
27
  let {
37
28
  signal
38
29
  } = _ref;
39
30
  return this.fetch((0, _queryToResourcePath.queryToResourcePath)(this, query, type), (0, _queryToRequestOptions.queryToRequestOptions)(type, query, signal));
40
31
  }
41
-
42
32
  }
43
-
44
33
  exports.RestAPILink = RestAPILink;
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  var _fetchData = require("./RestAPILink/fetchData");
4
-
5
4
  var _ = require(".");
6
-
7
5
  jest.mock('./RestAPILink/fetchData', () => ({
8
6
  fetchData: jest.fn(async () => null)
9
7
  }));
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  var _CustomDataLink = require("./CustomDataLink");
8
-
9
7
  Object.keys(_CustomDataLink).forEach(function (key) {
10
8
  if (key === "default" || key === "__esModule") return;
11
9
  if (key in exports && exports[key] === _CustomDataLink[key]) return;
@@ -16,9 +14,7 @@ Object.keys(_CustomDataLink).forEach(function (key) {
16
14
  }
17
15
  });
18
16
  });
19
-
20
17
  var _ErrorLink = require("./ErrorLink");
21
-
22
18
  Object.keys(_ErrorLink).forEach(function (key) {
23
19
  if (key === "default" || key === "__esModule") return;
24
20
  if (key in exports && exports[key] === _ErrorLink[key]) return;
@@ -29,9 +25,7 @@ Object.keys(_ErrorLink).forEach(function (key) {
29
25
  }
30
26
  });
31
27
  });
32
-
33
28
  var _RestAPILink = require("./RestAPILink");
34
-
35
29
  Object.keys(_RestAPILink).forEach(function (key) {
36
30
  if (key === "default" || key === "__esModule") return;
37
31
  if (key in exports && exports[key] === _RestAPILink[key]) return;
@@ -4,22 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.CustomDataProvider = void 0;
7
-
7
+ var _reactQuery = require("@tanstack/react-query");
8
8
  var _react = _interopRequireDefault(require("react"));
9
-
10
- var _reactQuery = require("react-query");
11
-
12
9
  var _engine = require("../../engine");
13
-
14
10
  var _links = require("../../links");
15
-
16
11
  var _DataContext = require("../context/DataContext");
17
-
18
12
  var _DataProvider = require("./DataProvider");
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- const CustomDataProvider = (_ref) => {
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ const CustomDataProvider = _ref => {
23
15
  let {
24
16
  children,
25
17
  data,
@@ -38,5 +30,4 @@ const CustomDataProvider = (_ref) => {
38
30
  value: context
39
31
  }, children));
40
32
  };
41
-
42
33
  exports.CustomDataProvider = CustomDataProvider;
@@ -4,10 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DataMutation = void 0;
7
-
8
7
  var _useDataMutation = require("../hooks/useDataMutation");
9
-
10
- const DataMutation = (_ref) => {
8
+ const DataMutation = _ref => {
11
9
  let {
12
10
  mutation,
13
11
  onComplete,
@@ -22,5 +20,4 @@ const DataMutation = (_ref) => {
22
20
  });
23
21
  return children(mutationState);
24
22
  };
25
-
26
23
  exports.DataMutation = DataMutation;
@@ -4,23 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.queryClientOptions = exports.DataProvider = void 0;
7
-
8
7
  var _appServiceConfig = require("@dhis2/app-service-config");
9
-
8
+ var _reactQuery = require("@tanstack/react-query");
10
9
  var _react = _interopRequireDefault(require("react"));
11
-
12
- var _reactQuery = require("react-query");
13
-
14
10
  var _engine = require("../../engine");
15
-
16
11
  var _links = require("../../links");
17
-
18
12
  var _DataContext = require("../context/DataContext");
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
22
14
  /* eslint-disable react/no-unused-prop-types */
23
- const queryClientOptions = {
15
+
16
+ const queryClientOptions = exports.queryClientOptions = {
24
17
  defaultOptions: {
25
18
  queries: {
26
19
  // Disable automatic error retries
@@ -32,15 +25,18 @@ const queryClientOptions = {
32
25
  // Don't refetch when the window regains focus
33
26
  refetchOnWindowFocus: false,
34
27
  // Don't refetch after connection issues
35
- refetchOnReconnect: false
28
+ refetchOnReconnect: false,
29
+ // RQv4 uses 'online' as the default, which pauses queries without network connection.
30
+ // 'always' reestablishes behavior from v3, and lets requests fire when offline
31
+ // https://tanstack.com/query/latest/docs/framework/react/guides/network-mode
32
+ networkMode: 'always'
36
33
  }
37
34
  }
38
35
  };
39
- exports.queryClientOptions = queryClientOptions;
40
36
  const queryClient = new _reactQuery.QueryClient(queryClientOptions);
41
-
42
37
  const DataProvider = props => {
43
- const config = { ...(0, _appServiceConfig.useConfig)(),
38
+ const config = {
39
+ ...(0, _appServiceConfig.useConfig)(),
44
40
  ...props
45
41
  };
46
42
  const link = new _links.RestAPILink(config);
@@ -54,5 +50,4 @@ const DataProvider = props => {
54
50
  value: context
55
51
  }, props.children));
56
52
  };
57
-
58
53
  exports.DataProvider = DataProvider;
@@ -1,23 +1,16 @@
1
1
  "use strict";
2
2
 
3
3
  var _react = require("@testing-library/react");
4
-
5
4
  var _react2 = _interopRequireDefault(require("react"));
6
-
7
5
  var _engine = require("../../engine");
8
-
9
6
  var _links = require("../../links");
10
-
11
7
  var _DataContext = require("../context/DataContext");
12
-
13
8
  var _DataProvider = require("./DataProvider");
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
-
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
10
  describe('DataProvider', () => {
18
11
  it('Should pass a new engine and RestAPILink to consumers', () => {
19
12
  const renderFunction = jest.fn();
20
- (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_DataProvider.DataProvider, {
13
+ (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_DataProvider.DataProvider, {
21
14
  baseUrl: "test",
22
15
  apiVersion: 42
23
16
  }, /*#__PURE__*/_react2.default.createElement(_DataContext.DataContext.Consumer, null, renderFunction)));
@@ -4,10 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DataQuery = void 0;
7
-
8
7
  var _useDataQuery = require("../hooks/useDataQuery");
9
-
10
- const DataQuery = (_ref) => {
8
+ const DataQuery = _ref => {
11
9
  let {
12
10
  query,
13
11
  onComplete,
@@ -24,5 +22,4 @@ const DataQuery = (_ref) => {
24
22
  });
25
23
  return children(queryState);
26
24
  };
27
-
28
25
  exports.DataQuery = DataQuery;
@@ -4,13 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DataContext = void 0;
7
-
8
7
  var _react = _interopRequireDefault(require("react"));
9
-
10
8
  var _defaultContext = require("./defaultContext");
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- const DataContext = /*#__PURE__*/_react.default.createContext(_defaultContext.defaultContext);
15
-
16
- exports.DataContext = DataContext;
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ const DataContext = exports.DataContext = /*#__PURE__*/_react.default.createContext(_defaultContext.defaultContext);
@@ -4,15 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.defaultContext = void 0;
7
-
8
7
  var _engine = require("../../engine");
9
-
10
8
  var _links = require("../../links");
11
-
12
9
  const errorMessage = 'DHIS2 data context must be initialized, please ensure that you include a <DataProvider> in your application';
13
10
  const link = new _links.ErrorLink(errorMessage);
14
11
  const engine = new _engine.DataEngine(link);
15
- const defaultContext = {
12
+ const defaultContext = exports.defaultContext = {
16
13
  engine
17
- };
18
- exports.defaultContext = defaultContext;
14
+ };
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _defaultContext = require("./defaultContext");
4
-
5
4
  describe('defaultContext', () => {
6
5
  const originalError = console.error;
7
6
  const mockError = jest.fn();
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.mergeAndCompareVariables = void 0;
7
-
8
7
  var _stableVariablesHash = require("./stableVariablesHash");
9
-
10
8
  const mergeAndCompareVariables = (previousVariables, newVariables, previousHash) => {
11
9
  if (!newVariables) {
12
10
  return {
@@ -14,11 +12,12 @@ const mergeAndCompareVariables = (previousVariables, newVariables, previousHash)
14
12
  mergedVariablesHash: previousHash,
15
13
  mergedVariables: previousVariables
16
14
  };
17
- } // Use cached hash if it exists
18
-
15
+ }
19
16
 
17
+ // Use cached hash if it exists
20
18
  const currentHash = previousHash || (0, _stableVariablesHash.stableVariablesHash)(previousVariables);
21
- const mergedVariables = { ...previousVariables,
19
+ const mergedVariables = {
20
+ ...previousVariables,
22
21
  ...newVariables
23
22
  };
24
23
  const mergedVariablesHash = (0, _stableVariablesHash.stableVariablesHash)(mergedVariables);
@@ -29,5 +28,4 @@ const mergeAndCompareVariables = (previousVariables, newVariables, previousHash)
29
28
  mergedVariables
30
29
  };
31
30
  };
32
-
33
31
  exports.mergeAndCompareVariables = mergeAndCompareVariables;
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  var _mergeAndCompareVariables = require("./mergeAndCompareVariables");
4
-
5
4
  var _stableVariablesHash = require("./stableVariablesHash");
6
-
7
5
  jest.mock('./stableVariablesHash', () => ({
8
6
  stableVariablesHash: object => JSON.stringify(object)
9
7
  }));
@@ -45,7 +43,8 @@ describe('mergeAndCompareVariables', () => {
45
43
  const newVariables = {
46
44
  answer: 43
47
45
  };
48
- const expectedMergedVariables = { ...testVariables,
46
+ const expectedMergedVariables = {
47
+ ...testVariables,
49
48
  ...newVariables
50
49
  };
51
50
  expect((0, _mergeAndCompareVariables.mergeAndCompareVariables)(testVariables, newVariables, testHash)).toMatchObject({
@@ -5,47 +5,43 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.isPlainObject = isPlainObject;
7
7
  exports.stableVariablesHash = stableVariablesHash;
8
-
9
8
  function hasObjectPrototype(o) {
10
9
  return Object.prototype.toString.call(o) === '[object Object]';
11
- } // eslint-disable-next-line @typescript-eslint/ban-types
12
-
10
+ }
13
11
 
12
+ // eslint-disable-next-line @typescript-eslint/ban-types
14
13
  function isPlainObject(o) {
15
14
  if (!hasObjectPrototype(o)) {
16
15
  return false;
17
- } // If has modified constructor
18
-
16
+ }
19
17
 
18
+ // If has modified constructor
20
19
  const ctor = o.constructor;
21
-
22
20
  if (typeof ctor === 'undefined') {
23
21
  return true;
24
- } // If has modified prototype
25
-
22
+ }
26
23
 
24
+ // If has modified prototype
27
25
  const prot = ctor.prototype;
28
-
29
26
  if (!hasObjectPrototype(prot)) {
30
27
  return false;
31
- } // If constructor does not have an Object-specific method
32
-
28
+ }
33
29
 
30
+ // If constructor does not have an Object-specific method
34
31
  if (!Object.prototype.hasOwnProperty.call(prot, 'isPrototypeOf')) {
35
32
  return false;
36
- } // Most likely a plain Object
37
-
33
+ }
38
34
 
35
+ // Most likely a plain Object
39
36
  return true;
40
37
  }
38
+
41
39
  /**
42
40
  * Hashes the value into a stable hash.
43
41
  */
44
42
 
45
-
46
43
  function stableVariablesHash(value) {
47
44
  let hash;
48
-
49
45
  try {
50
46
  hash = JSON.stringify(value, (_, val) => isPlainObject(val) ? Object.keys(val).sort().reduce((result, key) => {
51
47
  result[key] = val[key];
@@ -54,6 +50,5 @@ function stableVariablesHash(value) {
54
50
  } catch (e) {
55
51
  throw new Error('Could not serialize variables. Make sure that the variables do not contain circular references and can be processed by JSON.stringify.');
56
52
  }
57
-
58
53
  return hash;
59
54
  }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _stableVariablesHash = require("./stableVariablesHash");
4
-
5
4
  describe('stableVariablesHash', () => {
6
5
  it('sorts objects before hashing', () => {
7
6
  const one = {
@@ -4,14 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useDataEngine = void 0;
7
-
8
7
  var _react = require("react");
9
-
10
8
  var _DataContext = require("../context/DataContext");
11
-
12
9
  const useDataEngine = () => {
13
10
  const context = (0, _react.useContext)(_DataContext.DataContext);
14
11
  return context.engine;
15
12
  };
16
-
17
13
  exports.useDataEngine = useDataEngine;
@@ -4,17 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useDataMutation = void 0;
7
-
8
7
  var _react = require("react");
9
-
10
8
  var _useDataEngine = require("./useDataEngine");
11
-
12
9
  var _useQueryExecutor = require("./useQueryExecutor");
13
-
14
10
  var _useStaticInput = require("./useStaticInput");
15
-
16
11
  const empty = {};
17
-
18
12
  const useDataMutation = function (mutation) {
19
13
  let {
20
14
  onComplete,
@@ -50,5 +44,4 @@ const useDataMutation = function (mutation) {
50
44
  data
51
45
  }];
52
46
  };
53
-
54
47
  exports.useDataMutation = useDataMutation;