@dhis2/app-service-data 3.16.0 → 3.17.0-beta.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 (180) hide show
  1. package/build/cjs/__tests__/integration.test.js +10 -16
  2. package/build/cjs/__tests__/mutations.test.js +5 -8
  3. package/build/cjs/index.js +16 -44
  4. package/build/cjs/react/components/CustomDataProvider.js +9 -11
  5. package/build/cjs/react/components/DataMutation.js +7 -8
  6. package/build/cjs/react/components/DataProvider.js +3 -4
  7. package/build/cjs/react/components/DataProvider.test.js +3 -4
  8. package/build/cjs/react/components/DataQuery.js +8 -9
  9. package/build/cjs/react/components/index.js +33 -0
  10. package/build/cjs/react/context/DataContext.js +2 -2
  11. package/build/cjs/react/context/defaultDataContext.js +13 -0
  12. package/build/cjs/react/context/{defaultContext.test.js → defaultDataContext.test.js} +3 -3
  13. package/build/cjs/react/hooks/index.js +26 -0
  14. package/build/cjs/react/hooks/useDataMutation.js +6 -7
  15. package/build/cjs/react/hooks/useDataMutation.test.js +44 -71
  16. package/build/cjs/react/hooks/useDataQuery.js +10 -14
  17. package/build/cjs/react/hooks/useDataQuery.test.js +172 -265
  18. package/build/cjs/react/hooks/useQueryExecutor.js +11 -13
  19. package/build/cjs/react/hooks/useQueryExecutor.test.js +12 -16
  20. package/build/cjs/react/hooks/useStaticInput.js +4 -5
  21. package/build/cjs/react/hooks/useStaticInput.test.js +24 -39
  22. package/build/cjs/react/index.js +22 -77
  23. package/build/es/__tests__/integration.test.js +10 -16
  24. package/build/es/__tests__/mutations.test.js +5 -8
  25. package/build/es/index.js +2 -3
  26. package/build/es/react/components/CustomDataProvider.js +7 -9
  27. package/build/es/react/components/DataMutation.js +7 -8
  28. package/build/es/react/components/DataProvider.js +1 -2
  29. package/build/es/react/components/DataProvider.test.js +1 -2
  30. package/build/es/react/components/DataQuery.js +8 -9
  31. package/build/es/react/components/index.js +4 -0
  32. package/build/es/react/context/DataContext.js +2 -2
  33. package/build/es/react/context/{defaultContext.js → defaultDataContext.js} +2 -3
  34. package/build/es/react/context/{defaultContext.test.js → defaultDataContext.test.js} +3 -3
  35. package/build/es/react/hooks/index.js +3 -0
  36. package/build/es/react/hooks/useDataMutation.js +6 -7
  37. package/build/es/react/hooks/useDataMutation.test.js +44 -71
  38. package/build/es/react/hooks/useDataQuery.js +10 -14
  39. package/build/es/react/hooks/useDataQuery.test.js +172 -265
  40. package/build/es/react/hooks/useQueryExecutor.js +10 -12
  41. package/build/es/react/hooks/useQueryExecutor.test.js +12 -16
  42. package/build/es/react/hooks/useStaticInput.js +4 -5
  43. package/build/es/react/hooks/useStaticInput.test.js +24 -39
  44. package/build/es/react/index.js +3 -11
  45. package/build/types/index.d.ts +2 -3
  46. package/build/types/react/components/CustomDataProvider.d.ts +1 -1
  47. package/build/types/react/components/DataMutation.d.ts +1 -1
  48. package/build/types/react/components/DataQuery.d.ts +1 -1
  49. package/build/types/react/components/index.d.ts +4 -0
  50. package/build/types/react/context/defaultDataContext.d.ts +4 -0
  51. package/build/types/react/hooks/index.d.ts +3 -0
  52. package/build/types/react/hooks/mergeAndCompareVariables.d.ts +1 -1
  53. package/build/types/react/hooks/useDataEngine.d.ts +1 -1
  54. package/build/types/react/hooks/useDataMutation.d.ts +1 -1
  55. package/build/types/react/hooks/useDataQuery.d.ts +1 -1
  56. package/build/types/react/index.d.ts +2 -11
  57. package/build/types/types.d.ts +2 -7
  58. package/package.json +4 -3
  59. package/build/cjs/engine/DataEngine.js +0 -73
  60. package/build/cjs/engine/DataEngine.test.js +0 -156
  61. package/build/cjs/engine/helpers/getMutationFetchType.js +0 -8
  62. package/build/cjs/engine/helpers/getMutationFetchType.test.js +0 -39
  63. package/build/cjs/engine/helpers/resolveDynamicQuery.js +0 -21
  64. package/build/cjs/engine/helpers/resolveDynamicQuery.test.js +0 -63
  65. package/build/cjs/engine/helpers/validate.js +0 -62
  66. package/build/cjs/engine/helpers/validate.test.js +0 -206
  67. package/build/cjs/engine/index.js +0 -104
  68. package/build/cjs/engine/types/DataEngineLink.js +0 -1
  69. package/build/cjs/engine/types/ExecuteOptions.js +0 -1
  70. package/build/cjs/engine/types/FetchError.js +0 -24
  71. package/build/cjs/engine/types/FetchError.test.js +0 -14
  72. package/build/cjs/engine/types/InvalidQueryError.js +0 -18
  73. package/build/cjs/engine/types/JsonValue.js +0 -1
  74. package/build/cjs/engine/types/Mutation.js +0 -1
  75. package/build/cjs/engine/types/PossiblyDynamic.js +0 -1
  76. package/build/cjs/engine/types/Query.js +0 -1
  77. package/build/cjs/engine/types/QueryParameters.js +0 -1
  78. package/build/cjs/links/CustomDataLink.js +0 -51
  79. package/build/cjs/links/CustomDataLink.test.js +0 -73
  80. package/build/cjs/links/ErrorLink.js +0 -20
  81. package/build/cjs/links/RestAPILink/fetchData.js +0 -80
  82. package/build/cjs/links/RestAPILink/fetchData.test.js +0 -132
  83. package/build/cjs/links/RestAPILink/metadataResources.js +0 -22
  84. package/build/cjs/links/RestAPILink/path.js +0 -14
  85. package/build/cjs/links/RestAPILink/path.test.js +0 -16
  86. package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +0 -58
  87. package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.test.js +0 -73
  88. package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.js +0 -80
  89. package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +0 -120
  90. package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +0 -170
  91. package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.test.js +0 -246
  92. package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +0 -14
  93. package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.test.js +0 -20
  94. package/build/cjs/links/RestAPILink/queryToRequestOptions.js +0 -34
  95. package/build/cjs/links/RestAPILink/queryToRequestOptions.test.js +0 -107
  96. package/build/cjs/links/RestAPILink/queryToResourcePath.js +0 -82
  97. package/build/cjs/links/RestAPILink/queryToResourcePath.test.js +0 -173
  98. package/build/cjs/links/RestAPILink/validateQuery.js +0 -59
  99. package/build/cjs/links/RestAPILink/validateQuery.test.js +0 -209
  100. package/build/cjs/links/RestAPILink.js +0 -33
  101. package/build/cjs/links/RestAPILink.test.js +0 -21
  102. package/build/cjs/links/index.js +0 -38
  103. package/build/cjs/locales/en/translations.json +0 -3
  104. package/build/cjs/locales/index.js +0 -21
  105. package/build/cjs/react/context/defaultContext.js +0 -14
  106. package/build/es/engine/DataEngine.js +0 -66
  107. package/build/es/engine/DataEngine.test.js +0 -154
  108. package/build/es/engine/helpers/getMutationFetchType.js +0 -1
  109. package/build/es/engine/helpers/getMutationFetchType.test.js +0 -37
  110. package/build/es/engine/helpers/resolveDynamicQuery.js +0 -14
  111. package/build/es/engine/helpers/resolveDynamicQuery.test.js +0 -61
  112. package/build/es/engine/helpers/validate.js +0 -53
  113. package/build/es/engine/helpers/validate.test.js +0 -204
  114. package/build/es/engine/index.js +0 -10
  115. package/build/es/engine/types/DataEngineLink.js +0 -1
  116. package/build/es/engine/types/ExecuteOptions.js +0 -1
  117. package/build/es/engine/types/FetchError.js +0 -17
  118. package/build/es/engine/types/FetchError.test.js +0 -12
  119. package/build/es/engine/types/InvalidQueryError.js +0 -11
  120. package/build/es/engine/types/JsonValue.js +0 -1
  121. package/build/es/engine/types/Mutation.js +0 -1
  122. package/build/es/engine/types/PossiblyDynamic.js +0 -1
  123. package/build/es/engine/types/Query.js +0 -1
  124. package/build/es/engine/types/QueryParameters.js +0 -1
  125. package/build/es/links/CustomDataLink.js +0 -44
  126. package/build/es/links/CustomDataLink.test.js +0 -71
  127. package/build/es/links/ErrorLink.js +0 -13
  128. package/build/es/links/RestAPILink/fetchData.js +0 -71
  129. package/build/es/links/RestAPILink/fetchData.test.js +0 -130
  130. package/build/es/links/RestAPILink/metadataResources.js +0 -16
  131. package/build/es/links/RestAPILink/path.js +0 -7
  132. package/build/es/links/RestAPILink/path.test.js +0 -14
  133. package/build/es/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +0 -47
  134. package/build/es/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.test.js +0 -71
  135. package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.js +0 -70
  136. package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +0 -118
  137. package/build/es/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +0 -151
  138. package/build/es/links/RestAPILink/queryToRequestOptions/textPlainMatchers.test.js +0 -244
  139. package/build/es/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +0 -7
  140. package/build/es/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.test.js +0 -18
  141. package/build/es/links/RestAPILink/queryToRequestOptions.js +0 -27
  142. package/build/es/links/RestAPILink/queryToRequestOptions.test.js +0 -105
  143. package/build/es/links/RestAPILink/queryToResourcePath.js +0 -75
  144. package/build/es/links/RestAPILink/queryToResourcePath.test.js +0 -171
  145. package/build/es/links/RestAPILink/validateQuery.js +0 -52
  146. package/build/es/links/RestAPILink/validateQuery.test.js +0 -207
  147. package/build/es/links/RestAPILink.js +0 -26
  148. package/build/es/links/RestAPILink.test.js +0 -19
  149. package/build/es/links/index.js +0 -4
  150. package/build/es/locales/en/translations.json +0 -3
  151. package/build/es/locales/index.js +0 -13
  152. package/build/types/engine/DataEngine.d.ts +0 -13
  153. package/build/types/engine/helpers/getMutationFetchType.d.ts +0 -3
  154. package/build/types/engine/helpers/resolveDynamicQuery.d.ts +0 -2
  155. package/build/types/engine/helpers/validate.d.ts +0 -4
  156. package/build/types/engine/index.d.ts +0 -9
  157. package/build/types/engine/types/DataEngineLink.d.ts +0 -9
  158. package/build/types/engine/types/ExecuteOptions.d.ts +0 -9
  159. package/build/types/engine/types/FetchError.d.ts +0 -19
  160. package/build/types/engine/types/InvalidQueryError.d.ts +0 -5
  161. package/build/types/engine/types/JsonValue.d.ts +0 -6
  162. package/build/types/engine/types/Mutation.d.ts +0 -29
  163. package/build/types/engine/types/PossiblyDynamic.d.ts +0 -1
  164. package/build/types/engine/types/Query.d.ts +0 -24
  165. package/build/types/engine/types/QueryParameters.d.ts +0 -12
  166. package/build/types/links/CustomDataLink.d.ts +0 -17
  167. package/build/types/links/ErrorLink.d.ts +0 -6
  168. package/build/types/links/RestAPILink/fetchData.d.ts +0 -4
  169. package/build/types/links/RestAPILink/metadataResources.d.ts +0 -2
  170. package/build/types/links/RestAPILink/path.d.ts +0 -1
  171. package/build/types/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.d.ts +0 -6
  172. package/build/types/links/RestAPILink/queryToRequestOptions/requestContentType.d.ts +0 -6
  173. package/build/types/links/RestAPILink/queryToRequestOptions/textPlainMatchers.d.ts +0 -14
  174. package/build/types/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.d.ts +0 -2
  175. package/build/types/links/RestAPILink/queryToRequestOptions.d.ts +0 -2
  176. package/build/types/links/RestAPILink/queryToResourcePath.d.ts +0 -3
  177. package/build/types/links/RestAPILink/validateQuery.d.ts +0 -2
  178. package/build/types/links/RestAPILink.d.ts +0 -10
  179. package/build/types/links/index.d.ts +0 -3
  180. package/build/types/react/context/defaultContext.d.ts +0 -4
@@ -4,18 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useQueryExecutor = void 0;
7
+ var _dataEngine = require("@dhis2/data-engine");
7
8
  var _react = require("react");
8
- var _engine = require("../../engine");
9
9
  var _useStaticInput = require("./useStaticInput");
10
- const useQueryExecutor = _ref => {
11
- let {
12
- execute,
13
- variables: initialVariables,
14
- singular,
15
- immediate,
16
- onComplete,
17
- onError
18
- } = _ref;
10
+ const useQueryExecutor = ({
11
+ execute,
12
+ variables: initialVariables,
13
+ singular,
14
+ immediate,
15
+ onComplete,
16
+ onError
17
+ }) => {
19
18
  const [theExecute] = (0, _useStaticInput.useStaticInput)(execute);
20
19
  const [state, setState] = (0, _react.useState)({
21
20
  called: !!immediate,
@@ -32,14 +31,13 @@ const useQueryExecutor = _ref => {
32
31
  setState(state => ({
33
32
  called: state.called,
34
33
  loading: false,
35
- error: new _engine.FetchError({
34
+ error: new _dataEngine.FetchError({
36
35
  type: 'aborted',
37
36
  message: 'Aborted'
38
37
  })
39
38
  }));
40
39
  }, [abort]);
41
- const refetch = (0, _react.useCallback)(function () {
42
- let newVariables = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
40
+ const refetch = (0, _react.useCallback)((newVariables = {}) => {
43
41
  setState(state => !state.called || !state.loading ? {
44
42
  called: true,
45
43
  loading: true
@@ -4,10 +4,9 @@ var _react = require("@testing-library/react");
4
4
  var _useQueryExecutor = require("./useQueryExecutor");
5
5
  const testError = new Error('TEST ERROR');
6
6
  let theSignal;
7
- const execute = jest.fn(async _ref => {
8
- let {
9
- signal
10
- } = _ref;
7
+ const execute = jest.fn(async ({
8
+ signal
9
+ }) => {
11
10
  theSignal = signal;
12
11
  return 42;
13
12
  });
@@ -114,18 +113,15 @@ describe('useQueryExecutor', () => {
114
113
  const {
115
114
  result,
116
115
  rerender
117
- } = (0, _react.renderHook)(_ref2 => {
118
- let {
119
- onComplete
120
- } = _ref2;
121
- return (0, _useQueryExecutor.useQueryExecutor)({
122
- execute,
123
- immediate: true,
124
- singular: true,
125
- variables: {},
126
- onComplete
127
- });
128
- }, {
116
+ } = (0, _react.renderHook)(({
117
+ onComplete
118
+ }) => (0, _useQueryExecutor.useQueryExecutor)({
119
+ execute,
120
+ immediate: true,
121
+ singular: true,
122
+ variables: {},
123
+ onComplete
124
+ }), {
129
125
  initialProps: {
130
126
  onComplete: () => null
131
127
  }
@@ -5,11 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useStaticInput = void 0;
7
7
  var _react = require("react");
8
- const useStaticInput = function (staticValue) {
9
- let {
10
- warn = false,
11
- name = 'input'
12
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
8
+ const useStaticInput = (staticValue, {
9
+ warn = false,
10
+ name = 'input'
11
+ } = {}) => {
13
12
  const originalValue = (0, _react.useRef)(staticValue);
14
13
  const [value, setValue] = (0, _react.useState)(() => originalValue.current);
15
14
  (0, _react.useDebugValue)(value, debugValue => `${name}: ${JSON.stringify(debugValue)}`);
@@ -21,12 +21,9 @@ describe('useStaticInput', () => {
21
21
  const {
22
22
  result,
23
23
  rerender
24
- } = (0, _react.renderHook)(_ref => {
25
- let {
26
- value
27
- } = _ref;
28
- return (0, _useStaticInput.useStaticInput)(value);
29
- }, {
24
+ } = (0, _react.renderHook)(({
25
+ value
26
+ }) => (0, _useStaticInput.useStaticInput)(value), {
30
27
  initialProps: {
31
28
  value: 42
32
29
  }
@@ -42,14 +39,11 @@ describe('useStaticInput', () => {
42
39
  const {
43
40
  result,
44
41
  rerender
45
- } = (0, _react.renderHook)(_ref2 => {
46
- let {
47
- value
48
- } = _ref2;
49
- return (0, _useStaticInput.useStaticInput)(value, {
50
- warn: true
51
- });
52
- }, {
42
+ } = (0, _react.renderHook)(({
43
+ value
44
+ }) => (0, _useStaticInput.useStaticInput)(value, {
45
+ warn: true
46
+ }), {
53
47
  initialProps: {
54
48
  value: 42
55
49
  }
@@ -70,15 +64,12 @@ describe('useStaticInput', () => {
70
64
  const {
71
65
  result,
72
66
  rerender
73
- } = (0, _react.renderHook)(_ref3 => {
74
- let {
75
- value
76
- } = _ref3;
77
- return (0, _useStaticInput.useStaticInput)(value, {
78
- warn: true,
79
- name: 'TESTING THING'
80
- });
81
- }, {
67
+ } = (0, _react.renderHook)(({
68
+ value
69
+ }) => (0, _useStaticInput.useStaticInput)(value, {
70
+ warn: true,
71
+ name: 'TESTING THING'
72
+ }), {
82
73
  initialProps: {
83
74
  value: 42
84
75
  }
@@ -95,14 +86,11 @@ describe('useStaticInput', () => {
95
86
  const {
96
87
  result,
97
88
  rerender
98
- } = (0, _react.renderHook)(_ref4 => {
99
- let {
100
- value
101
- } = _ref4;
102
- return (0, _useStaticInput.useStaticInput)(value, {
103
- warn: true
104
- });
105
- }, {
89
+ } = (0, _react.renderHook)(({
90
+ value
91
+ }) => (0, _useStaticInput.useStaticInput)(value, {
92
+ warn: true
93
+ }), {
106
94
  initialProps: {
107
95
  value: 42
108
96
  }
@@ -131,14 +119,11 @@ describe('useStaticInput', () => {
131
119
  const {
132
120
  result,
133
121
  rerender
134
- } = (0, _react.renderHook)(_ref5 => {
135
- let {
136
- value
137
- } = _ref5;
138
- return (0, _useStaticInput.useStaticInput)(value, {
139
- warn: true
140
- });
141
- }, {
122
+ } = (0, _react.renderHook)(({
123
+ value
124
+ }) => (0, _useStaticInput.useStaticInput)(value, {
125
+ warn: true
126
+ }), {
142
127
  initialProps: {
143
128
  value: fn
144
129
  }
@@ -3,80 +3,25 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "CustomDataProvider", {
7
- enumerable: true,
8
- get: function () {
9
- return _CustomDataProvider.CustomDataProvider;
10
- }
11
- });
12
- Object.defineProperty(exports, "DataContext", {
13
- enumerable: true,
14
- get: function () {
15
- return _DataContext.DataContext;
16
- }
17
- });
18
- Object.defineProperty(exports, "DataMutation", {
19
- enumerable: true,
20
- get: function () {
21
- return _DataMutation.DataMutation;
22
- }
23
- });
24
- Object.defineProperty(exports, "DataProvider", {
25
- enumerable: true,
26
- get: function () {
27
- return _DataProvider.DataProvider;
28
- }
29
- });
30
- Object.defineProperty(exports, "DataQuery", {
31
- enumerable: true,
32
- get: function () {
33
- return _DataQuery.DataQuery;
34
- }
35
- });
36
- Object.defineProperty(exports, "defaultContext", {
37
- enumerable: true,
38
- get: function () {
39
- return _defaultContext.defaultContext;
40
- }
41
- });
42
- Object.defineProperty(exports, "useDataEngine", {
43
- enumerable: true,
44
- get: function () {
45
- return _useDataEngine.useDataEngine;
46
- }
47
- });
48
- Object.defineProperty(exports, "useDataMutation", {
49
- enumerable: true,
50
- get: function () {
51
- return _useDataMutation.useDataMutation;
52
- }
53
- });
54
- Object.defineProperty(exports, "useDataQuery", {
55
- enumerable: true,
56
- get: function () {
57
- return _useDataQuery.useDataQuery;
58
- }
59
- });
60
- Object.defineProperty(exports, "useQueryExecutor", {
61
- enumerable: true,
62
- get: function () {
63
- return _useQueryExecutor.useQueryExecutor;
64
- }
65
- });
66
- Object.defineProperty(exports, "useStaticInput", {
67
- enumerable: true,
68
- get: function () {
69
- return _useStaticInput.useStaticInput;
70
- }
71
- });
72
- var _CustomDataProvider = require("./components/CustomDataProvider");
73
- var _DataMutation = require("./components/DataMutation");
74
- var _DataProvider = require("./components/DataProvider");
75
- var _DataQuery = require("./components/DataQuery");
76
- var _DataContext = require("./context/DataContext");
77
- var _defaultContext = require("./context/defaultContext");
78
- var _useDataEngine = require("./hooks/useDataEngine");
79
- var _useDataMutation = require("./hooks/useDataMutation");
80
- var _useDataQuery = require("./hooks/useDataQuery");
81
- var _useQueryExecutor = require("./hooks/useQueryExecutor");
82
- var _useStaticInput = require("./hooks/useStaticInput");
6
+ var _components = require("./components");
7
+ Object.keys(_components).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _components[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _components[key];
14
+ }
15
+ });
16
+ });
17
+ var _hooks = require("./hooks");
18
+ Object.keys(_hooks).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _hooks[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _hooks[key];
25
+ }
26
+ });
27
+ });
@@ -6,14 +6,11 @@ describe('<DataQuery />', () => {
6
6
  const data = {
7
7
  answer: 42
8
8
  };
9
- const wrapper = _ref => {
10
- let {
11
- children
12
- } = _ref;
13
- return /*#__PURE__*/React.createElement(CustomDataProvider, {
14
- data: data
15
- }, children);
16
- };
9
+ const wrapper = ({
10
+ children
11
+ }) => /*#__PURE__*/React.createElement(CustomDataProvider, {
12
+ data: data
13
+ }, children);
17
14
  const renderFunction = jest.fn(() => null);
18
15
  render(/*#__PURE__*/React.createElement(DataQuery, {
19
16
  query: {
@@ -45,14 +42,11 @@ describe('<DataQuery />', () => {
45
42
  throw expectedError;
46
43
  }
47
44
  };
48
- const wrapper = _ref2 => {
49
- let {
50
- children
51
- } = _ref2;
52
- return /*#__PURE__*/React.createElement(CustomDataProvider, {
53
- data: data
54
- }, children);
55
- };
45
+ const wrapper = ({
46
+ children
47
+ }) => /*#__PURE__*/React.createElement(CustomDataProvider, {
48
+ data: data
49
+ }, children);
56
50
  const renderFunction = jest.fn(() => null);
57
51
  render(/*#__PURE__*/React.createElement(DataQuery, {
58
52
  query: {
@@ -14,14 +14,11 @@ describe('<DataMutation />', () => {
14
14
  const data = {
15
15
  answer: endpointSpy
16
16
  };
17
- const wrapper = _ref => {
18
- let {
19
- children
20
- } = _ref;
21
- return /*#__PURE__*/React.createElement(CustomDataProvider, {
22
- data: data
23
- }, children);
24
- };
17
+ const wrapper = ({
18
+ children
19
+ }) => /*#__PURE__*/React.createElement(CustomDataProvider, {
20
+ data: data
21
+ }, children);
25
22
  const renderSpy = jest.fn(() => null);
26
23
  render(/*#__PURE__*/React.createElement(DataMutation, {
27
24
  mutation: mutation
package/build/es/index.js CHANGED
@@ -1,3 +1,2 @@
1
- export { DataQuery, DataMutation, DataProvider, CustomDataProvider } from './react';
2
- export { useDataEngine, useDataQuery, useDataMutation } from './react';
3
- export { FetchError } from './engine';
1
+ export * from './react';
2
+ export { FetchError } from '@dhis2/data-engine';
@@ -1,16 +1,14 @@
1
+ import { DataEngine, CustomDataLink } from '@dhis2/data-engine';
1
2
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
2
3
  import React from 'react';
3
- import { DataEngine } from '../../engine';
4
- import { CustomDataLink } from '../../links';
5
4
  import { DataContext } from '../context/DataContext';
6
5
  import { queryClientOptions as queryClientDefaults } from './DataProvider';
7
- export const CustomDataProvider = _ref => {
8
- let {
9
- children,
10
- data,
11
- options,
12
- queryClientOptions = queryClientDefaults
13
- } = _ref;
6
+ export const CustomDataProvider = ({
7
+ children,
8
+ data,
9
+ options,
10
+ queryClientOptions = queryClientDefaults
11
+ }) => {
14
12
  const link = new CustomDataLink(data, options);
15
13
  const engine = new DataEngine(link);
16
14
  const queryClient = new QueryClient(queryClientOptions);
@@ -1,12 +1,11 @@
1
1
  import { useDataMutation } from '../hooks/useDataMutation';
2
- export const DataMutation = _ref => {
3
- let {
4
- mutation,
5
- onComplete,
6
- onError,
7
- variables,
8
- children
9
- } = _ref;
2
+ export const DataMutation = ({
3
+ mutation,
4
+ onComplete,
5
+ onError,
6
+ variables,
7
+ children
8
+ }) => {
10
9
  const mutationState = useDataMutation(mutation, {
11
10
  onComplete,
12
11
  onError,
@@ -1,10 +1,9 @@
1
1
  /* eslint-disable react/no-unused-prop-types */
2
2
 
3
3
  import { useConfig } from '@dhis2/app-service-config';
4
+ import { DataEngine, RestAPILink } from '@dhis2/data-engine';
4
5
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
5
6
  import React from 'react';
6
- import { DataEngine } from '../../engine';
7
- import { RestAPILink } from '../../links';
8
7
  import { DataContext } from '../context/DataContext';
9
8
  export const queryClientOptions = {
10
9
  defaultOptions: {
@@ -1,7 +1,6 @@
1
+ import { DataEngine, RestAPILink } from '@dhis2/data-engine';
1
2
  import { render } from '@testing-library/react';
2
3
  import React from 'react';
3
- import { DataEngine } from '../../engine';
4
- import { RestAPILink } from '../../links';
5
4
  import { DataContext } from '../context/DataContext';
6
5
  import { DataProvider } from './DataProvider';
7
6
  describe('DataProvider', () => {
@@ -1,13 +1,12 @@
1
1
  import { useDataQuery } from '../hooks/useDataQuery';
2
- export const DataQuery = _ref => {
3
- let {
4
- query,
5
- onComplete,
6
- onError,
7
- variables,
8
- lazy,
9
- children
10
- } = _ref;
2
+ export const DataQuery = ({
3
+ query,
4
+ onComplete,
5
+ onError,
6
+ variables,
7
+ lazy,
8
+ children
9
+ }) => {
11
10
  const queryState = useDataQuery(query, {
12
11
  onComplete,
13
12
  onError,
@@ -0,0 +1,4 @@
1
+ export { CustomDataProvider } from './CustomDataProvider';
2
+ export { DataMutation } from './DataMutation';
3
+ export { DataProvider } from './DataProvider';
4
+ export { DataQuery } from './DataQuery';
@@ -1,3 +1,3 @@
1
1
  import React from 'react';
2
- import { defaultContext } from './defaultContext';
3
- export const DataContext = /*#__PURE__*/React.createContext(defaultContext);
2
+ import { defaultDataContext } from './defaultDataContext';
3
+ export const DataContext = /*#__PURE__*/React.createContext(defaultDataContext);
@@ -1,8 +1,7 @@
1
- import { DataEngine } from '../../engine';
2
- import { ErrorLink } from '../../links';
1
+ import { DataEngine, ErrorLink } from '@dhis2/data-engine';
3
2
  const errorMessage = 'DHIS2 data context must be initialized, please ensure that you include a <DataProvider> in your application';
4
3
  const link = new ErrorLink(errorMessage);
5
4
  const engine = new DataEngine(link);
6
- export const defaultContext = {
5
+ export const defaultDataContext = {
7
6
  engine
8
7
  };
@@ -1,4 +1,4 @@
1
- import { defaultContext } from './defaultContext';
1
+ import { defaultDataContext } from './defaultDataContext';
2
2
  describe('defaultContext', () => {
3
3
  const originalError = console.error;
4
4
  const mockError = jest.fn();
@@ -8,7 +8,7 @@ describe('defaultContext', () => {
8
8
  });
9
9
  afterEach(() => console.error = originalError);
10
10
  it('Should throw if query is called', () => {
11
- const context = defaultContext;
11
+ const context = defaultDataContext;
12
12
  expect(context.engine.query({
13
13
  test: {
14
14
  resource: 'test'
@@ -22,7 +22,7 @@ describe('defaultContext', () => {
22
22
  `);
23
23
  });
24
24
  it('Should throw and log if mutate is called', () => {
25
- const context = defaultContext;
25
+ const context = defaultDataContext;
26
26
  expect(context.engine.mutate({
27
27
  type: 'create',
28
28
  resource: 'test',
@@ -0,0 +1,3 @@
1
+ export { useDataEngine } from './useDataEngine';
2
+ export { useDataMutation } from './useDataMutation';
3
+ export { useDataQuery } from './useDataQuery';
@@ -3,13 +3,12 @@ import { useDataEngine } from './useDataEngine';
3
3
  import { useQueryExecutor } from './useQueryExecutor';
4
4
  import { useStaticInput } from './useStaticInput';
5
5
  const empty = {};
6
- export const useDataMutation = function (mutation) {
7
- let {
8
- onComplete,
9
- onError,
10
- variables = empty,
11
- lazy = true
12
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6
+ export const useDataMutation = (mutation, {
7
+ onComplete,
8
+ onError,
9
+ variables = empty,
10
+ lazy = true
11
+ } = {}) => {
13
12
  const engine = useDataEngine();
14
13
  const [theMutation] = useStaticInput(mutation, {
15
14
  warn: true,