@dhis2/app-service-data 3.7.0 → 3.9.0

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 (83) hide show
  1. package/build/cjs/__tests__/integration.test.js +16 -10
  2. package/build/cjs/__tests__/mutations.test.js +8 -5
  3. package/build/cjs/engine/DataEngine.js +14 -12
  4. package/build/cjs/engine/helpers/resolveDynamicQuery.js +14 -11
  5. package/build/cjs/engine/helpers/resolveDynamicQuery.test.js +23 -14
  6. package/build/cjs/engine/helpers/validate.js +6 -4
  7. package/build/cjs/engine/helpers/validate.test.js +74 -15
  8. package/build/cjs/engine/types/FetchError.js +6 -5
  9. package/build/cjs/engine/types/InvalidQueryError.js +1 -1
  10. package/build/cjs/index.js +10 -10
  11. package/build/cjs/links/CustomDataLink.js +8 -6
  12. package/build/cjs/links/CustomDataLink.test.js +2 -2
  13. package/build/cjs/links/RestAPILink/fetchData.js +3 -2
  14. package/build/cjs/links/RestAPILink/fetchData.test.js +1 -1
  15. package/build/cjs/links/RestAPILink/metadataResources.js +1 -1
  16. package/build/cjs/links/RestAPILink/path.js +5 -1
  17. package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +29 -16
  18. package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.js +9 -6
  19. package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +2 -2
  20. package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +51 -33
  21. package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +6 -3
  22. package/build/cjs/links/RestAPILink/queryToRequestOptions.js +1 -1
  23. package/build/cjs/links/RestAPILink/queryToRequestOptions.test.js +56 -6
  24. package/build/cjs/links/RestAPILink/queryToResourcePath.js +14 -6
  25. package/build/cjs/links/RestAPILink/queryToResourcePath.test.js +16 -16
  26. package/build/cjs/links/RestAPILink/validateQuery.test.js +12 -12
  27. package/build/cjs/links/RestAPILink.js +4 -3
  28. package/build/cjs/react/components/CustomDataProvider.js +7 -6
  29. package/build/cjs/react/components/DataMutation.js +8 -7
  30. package/build/cjs/react/components/DataProvider.js +1 -1
  31. package/build/cjs/react/components/DataQuery.js +9 -8
  32. package/build/cjs/react/context/defaultContext.test.js +10 -2
  33. package/build/cjs/react/hooks/stableVariablesHash.js +1 -2
  34. package/build/cjs/react/hooks/stableVariablesHash.test.js +6 -6
  35. package/build/cjs/react/hooks/useDataMutation.js +7 -6
  36. package/build/cjs/react/hooks/useDataMutation.test.js +70 -43
  37. package/build/cjs/react/hooks/useDataQuery.js +13 -9
  38. package/build/cjs/react/hooks/useDataQuery.test.js +259 -162
  39. package/build/cjs/react/hooks/useQueryExecutor.js +11 -9
  40. package/build/cjs/react/hooks/useQueryExecutor.test.js +16 -12
  41. package/build/cjs/react/hooks/useStaticInput.js +7 -6
  42. package/build/cjs/react/hooks/useStaticInput.test.js +44 -25
  43. package/build/cjs/react/index.js +6 -6
  44. package/build/es/__tests__/integration.test.js +16 -10
  45. package/build/es/__tests__/mutations.test.js +8 -5
  46. package/build/es/engine/DataEngine.js +14 -12
  47. package/build/es/engine/helpers/resolveDynamicQuery.js +14 -11
  48. package/build/es/engine/helpers/resolveDynamicQuery.test.js +23 -14
  49. package/build/es/engine/helpers/validate.js +6 -4
  50. package/build/es/engine/helpers/validate.test.js +74 -15
  51. package/build/es/engine/types/FetchError.js +6 -5
  52. package/build/es/engine/types/InvalidQueryError.js +1 -1
  53. package/build/es/links/CustomDataLink.js +8 -6
  54. package/build/es/links/CustomDataLink.test.js +2 -2
  55. package/build/es/links/RestAPILink/fetchData.js +3 -2
  56. package/build/es/links/RestAPILink/fetchData.test.js +1 -1
  57. package/build/es/links/RestAPILink/path.js +5 -1
  58. package/build/es/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +28 -15
  59. package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.js +8 -5
  60. package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +2 -2
  61. package/build/es/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +50 -32
  62. package/build/es/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +6 -3
  63. package/build/es/links/RestAPILink/queryToRequestOptions.js +1 -1
  64. package/build/es/links/RestAPILink/queryToRequestOptions.test.js +56 -6
  65. package/build/es/links/RestAPILink/queryToResourcePath.js +14 -6
  66. package/build/es/links/RestAPILink/queryToResourcePath.test.js +16 -16
  67. package/build/es/links/RestAPILink/validateQuery.test.js +12 -12
  68. package/build/es/links/RestAPILink.js +4 -3
  69. package/build/es/react/components/CustomDataProvider.js +7 -6
  70. package/build/es/react/components/DataMutation.js +8 -7
  71. package/build/es/react/components/DataQuery.js +9 -8
  72. package/build/es/react/context/defaultContext.test.js +10 -2
  73. package/build/es/react/hooks/stableVariablesHash.js +1 -2
  74. package/build/es/react/hooks/stableVariablesHash.test.js +6 -6
  75. package/build/es/react/hooks/useDataMutation.js +7 -6
  76. package/build/es/react/hooks/useDataMutation.test.js +70 -43
  77. package/build/es/react/hooks/useDataQuery.js +13 -9
  78. package/build/es/react/hooks/useDataQuery.test.js +259 -162
  79. package/build/es/react/hooks/useQueryExecutor.js +11 -9
  80. package/build/es/react/hooks/useQueryExecutor.test.js +16 -12
  81. package/build/es/react/hooks/useStaticInput.js +7 -6
  82. package/build/es/react/hooks/useStaticInput.test.js +44 -25
  83. package/package.json +2 -2
@@ -7,13 +7,14 @@ exports.DataMutation = void 0;
7
7
 
8
8
  var _useDataMutation = require("../hooks/useDataMutation");
9
9
 
10
- const DataMutation = ({
11
- mutation,
12
- onComplete,
13
- onError,
14
- variables,
15
- children
16
- }) => {
10
+ const DataMutation = (_ref) => {
11
+ let {
12
+ mutation,
13
+ onComplete,
14
+ onError,
15
+ variables,
16
+ children
17
+ } = _ref;
17
18
  const mutationState = (0, _useDataMutation.useDataMutation)(mutation, {
18
19
  onComplete,
19
20
  onError,
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.DataProvider = exports.queryClientOptions = void 0;
6
+ exports.queryClientOptions = exports.DataProvider = void 0;
7
7
 
8
8
  var _appServiceConfig = require("@dhis2/app-service-config");
9
9
 
@@ -7,14 +7,15 @@ exports.DataQuery = void 0;
7
7
 
8
8
  var _useDataQuery = require("../hooks/useDataQuery");
9
9
 
10
- const DataQuery = ({
11
- query,
12
- onComplete,
13
- onError,
14
- variables,
15
- lazy,
16
- children
17
- }) => {
10
+ const DataQuery = (_ref) => {
11
+ let {
12
+ query,
13
+ onComplete,
14
+ onError,
15
+ variables,
16
+ lazy,
17
+ children
18
+ } = _ref;
18
19
  const queryState = (0, _useDataQuery.useDataQuery)(query, {
19
20
  onComplete,
20
21
  onError,
@@ -18,7 +18,11 @@ describe('defaultContext', () => {
18
18
  }
19
19
  })).rejects.toBeTruthy();
20
20
  expect(mockError).toHaveBeenCalledTimes(1);
21
- expect(mockError.mock.calls.pop()).toMatchInlineSnapshot("\n Array [\n \"DHIS2 data context must be initialized, please ensure that you include a <DataProvider> in your application\",\n ]\n ");
21
+ expect(mockError.mock.calls.pop()).toMatchInlineSnapshot(`
22
+ Array [
23
+ "DHIS2 data context must be initialized, please ensure that you include a <DataProvider> in your application",
24
+ ]
25
+ `);
22
26
  });
23
27
  it('Should throw and log if mutate is called', () => {
24
28
  const context = _defaultContext.defaultContext;
@@ -28,6 +32,10 @@ describe('defaultContext', () => {
28
32
  data: {}
29
33
  })).rejects.toBeTruthy();
30
34
  expect(mockError).toHaveBeenCalled();
31
- expect(mockError.mock.calls.pop()).toMatchInlineSnapshot("\n Array [\n \"DHIS2 data context must be initialized, please ensure that you include a <DataProvider> in your application\",\n ]\n ");
35
+ expect(mockError.mock.calls.pop()).toMatchInlineSnapshot(`
36
+ Array [
37
+ "DHIS2 data context must be initialized, please ensure that you include a <DataProvider> in your application",
38
+ ]
39
+ `);
32
40
  });
33
41
  });
@@ -8,7 +8,7 @@ exports.stableVariablesHash = stableVariablesHash;
8
8
 
9
9
  function hasObjectPrototype(o) {
10
10
  return Object.prototype.toString.call(o) === '[object Object]';
11
- } // eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/explicit-module-boundary-types
11
+ } // eslint-disable-next-line @typescript-eslint/ban-types
12
12
 
13
13
 
14
14
  function isPlainObject(o) {
@@ -41,7 +41,6 @@ function isPlainObject(o) {
41
41
  /**
42
42
  * Hashes the value into a stable hash.
43
43
  */
44
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
45
44
 
46
45
 
47
46
  function stableVariablesHash(value) {
@@ -30,17 +30,17 @@ describe('stableVariablesHash', () => {
30
30
  const three = 3;
31
31
  const four = null;
32
32
  const five = true;
33
- expect((0, _stableVariablesHash.stableVariablesHash)(one)).toMatchInlineSnapshot("undefined");
34
- expect((0, _stableVariablesHash.stableVariablesHash)(two)).toMatchInlineSnapshot("\"\\\"string\\\"\"");
35
- expect((0, _stableVariablesHash.stableVariablesHash)(three)).toMatchInlineSnapshot("\"3\"");
36
- expect((0, _stableVariablesHash.stableVariablesHash)(four)).toMatchInlineSnapshot("\"null\"");
37
- expect((0, _stableVariablesHash.stableVariablesHash)(five)).toMatchInlineSnapshot("\"true\"");
33
+ expect((0, _stableVariablesHash.stableVariablesHash)(one)).toMatchInlineSnapshot(`undefined`);
34
+ expect((0, _stableVariablesHash.stableVariablesHash)(two)).toMatchInlineSnapshot(`"\\"string\\""`);
35
+ expect((0, _stableVariablesHash.stableVariablesHash)(three)).toMatchInlineSnapshot(`"3"`);
36
+ expect((0, _stableVariablesHash.stableVariablesHash)(four)).toMatchInlineSnapshot(`"null"`);
37
+ expect((0, _stableVariablesHash.stableVariablesHash)(five)).toMatchInlineSnapshot(`"true"`);
38
38
  });
39
39
  it('throws a clear error when the variables contain a circular reference', () => {
40
40
  const unserializable = {
41
41
  value: 'value'
42
42
  };
43
43
  unserializable.circular = unserializable;
44
- expect(() => (0, _stableVariablesHash.stableVariablesHash)(unserializable)).toThrowErrorMatchingInlineSnapshot("\"Could not serialize variables. Make sure that the variables do not contain circular references and can be processed by JSON.stringify.\"");
44
+ expect(() => (0, _stableVariablesHash.stableVariablesHash)(unserializable)).toThrowErrorMatchingInlineSnapshot(`"Could not serialize variables. Make sure that the variables do not contain circular references and can be processed by JSON.stringify."`);
45
45
  });
46
46
  });
@@ -15,12 +15,13 @@ var _useStaticInput = require("./useStaticInput");
15
15
 
16
16
  const empty = {};
17
17
 
18
- const useDataMutation = (mutation, {
19
- onComplete,
20
- onError,
21
- variables = empty,
22
- lazy = true
23
- } = {}) => {
18
+ const useDataMutation = function (mutation) {
19
+ let {
20
+ onComplete,
21
+ onError,
22
+ variables = empty,
23
+ lazy = true
24
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
24
25
  const engine = (0, _useDataEngine.useDataEngine)();
25
26
  const [theMutation] = (0, _useStaticInput.useStaticInput)(mutation, {
26
27
  warn: true,
@@ -27,11 +27,14 @@ describe('useDataMutation', () => {
27
27
  answer: 42
28
28
  };
29
29
 
30
- const wrapper = ({
31
- children
32
- }) => /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
33
- data: data
34
- }, children);
30
+ const wrapper = (_ref) => {
31
+ let {
32
+ children
33
+ } = _ref;
34
+ return /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
35
+ data: data
36
+ }, children);
37
+ };
35
38
 
36
39
  const {
37
40
  result,
@@ -75,11 +78,14 @@ describe('useDataMutation', () => {
75
78
  answer: 42
76
79
  };
77
80
 
78
- const wrapper = ({
79
- children
80
- }) => /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
81
- data: data
82
- }, children);
81
+ const wrapper = (_ref2) => {
82
+ let {
83
+ children
84
+ } = _ref2;
85
+ return /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
86
+ data: data
87
+ }, children);
88
+ };
83
89
 
84
90
  const {
85
91
  result,
@@ -116,11 +122,14 @@ describe('useDataMutation', () => {
116
122
  answer: 42
117
123
  };
118
124
 
119
- const wrapper = ({
120
- children
121
- }) => /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
122
- data: data
123
- }, children);
125
+ const wrapper = (_ref3) => {
126
+ let {
127
+ children
128
+ } = _ref3;
129
+ return /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
130
+ data: data
131
+ }, children);
132
+ };
124
133
 
125
134
  const {
126
135
  result,
@@ -162,11 +171,14 @@ describe('useDataMutation', () => {
162
171
  }
163
172
  };
164
173
 
165
- const wrapper = ({
166
- children
167
- }) => /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
168
- data: data
169
- }, children);
174
+ const wrapper = (_ref4) => {
175
+ let {
176
+ children
177
+ } = _ref4;
178
+ return /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
179
+ data: data
180
+ }, children);
181
+ };
170
182
 
171
183
  const {
172
184
  result,
@@ -196,9 +208,12 @@ describe('useDataMutation', () => {
196
208
  const mutation = {
197
209
  type: 'update',
198
210
  resource: 'answer',
199
- id: ({
200
- id
201
- }) => id,
211
+ id: (_ref5) => {
212
+ let {
213
+ id
214
+ } = _ref5;
215
+ return id;
216
+ },
202
217
  data: {
203
218
  answer: '?'
204
219
  }
@@ -208,11 +223,14 @@ describe('useDataMutation', () => {
208
223
  answer: answerSpy
209
224
  };
210
225
 
211
- const wrapper = ({
212
- children
213
- }) => /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
214
- data: data
215
- }, children);
226
+ const wrapper = (_ref6) => {
227
+ let {
228
+ children
229
+ } = _ref6;
230
+ return /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
231
+ data: data
232
+ }, children);
233
+ };
216
234
 
217
235
  const {
218
236
  result,
@@ -251,11 +269,14 @@ describe('useDataMutation', () => {
251
269
  }
252
270
  };
253
271
 
254
- const wrapper = ({
255
- children
256
- }) => /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
257
- data: {}
258
- }, children);
272
+ const wrapper = (_ref7) => {
273
+ let {
274
+ children
275
+ } = _ref7;
276
+ return /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
277
+ data: {}
278
+ }, children);
279
+ };
259
280
 
260
281
  const engineHook = (0, _reactHooks.renderHook)(() => (0, _useDataEngine.useDataEngine)(), {
261
282
  wrapper
@@ -282,11 +303,14 @@ describe('useDataMutation', () => {
282
303
  answer: 42
283
304
  };
284
305
 
285
- const wrapper = ({
286
- children
287
- }) => /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
288
- data: data
289
- }, children);
306
+ const wrapper = (_ref8) => {
307
+ let {
308
+ children
309
+ } = _ref8;
310
+ return /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
311
+ data: data
312
+ }, children);
313
+ };
290
314
 
291
315
  const {
292
316
  result
@@ -318,11 +342,14 @@ describe('useDataMutation', () => {
318
342
  answer: 42
319
343
  };
320
344
 
321
- const wrapper = ({
322
- children
323
- }) => /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
324
- data: data
325
- }, children);
345
+ const wrapper = (_ref9) => {
346
+ let {
347
+ children
348
+ } = _ref9;
349
+ return /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
350
+ data: data
351
+ }, children);
352
+ };
326
353
 
327
354
  const {
328
355
  result,
@@ -29,12 +29,13 @@ const noop = () => {
29
29
  error: noop
30
30
  });
31
31
 
32
- const useDataQuery = (query, {
33
- onComplete: userOnSuccess,
34
- onError: userOnError,
35
- variables: initialVariables = {},
36
- lazy: initialLazy = false
37
- } = {}) => {
32
+ const useDataQuery = function (query) {
33
+ let {
34
+ onComplete: userOnSuccess,
35
+ onError: userOnError,
36
+ variables: initialVariables = {},
37
+ lazy: initialLazy = false
38
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
38
39
  const [staticQuery] = (0, _useStaticInput.useStaticInput)(query, {
39
40
  warn: true,
40
41
  name: 'query'
@@ -126,9 +127,12 @@ const useDataQuery = (query, {
126
127
  return queryRefetch({
127
128
  cancelRefetch: true,
128
129
  throwOnError: false
129
- }).then(({
130
- data
131
- }) => data);
130
+ }).then((_ref) => {
131
+ let {
132
+ data
133
+ } = _ref;
134
+ return data;
135
+ });
132
136
  }
133
137
 
134
138
  queryState.current.variables = mergedVariables;