@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
@@ -2,9 +2,10 @@ import { renderHook, act } from '@testing-library/react-hooks';
2
2
  import { useQueryExecutor } from './useQueryExecutor';
3
3
  const testError = new Error('TEST ERROR');
4
4
  let theSignal;
5
- const execute = jest.fn(async ({
6
- signal
7
- }) => {
5
+ const execute = jest.fn(async (_ref) => {
6
+ let {
7
+ signal
8
+ } = _ref;
8
9
  theSignal = signal;
9
10
  return 42;
10
11
  });
@@ -112,15 +113,18 @@ describe('useQueryExecutor', () => {
112
113
  result,
113
114
  waitForNextUpdate,
114
115
  rerender
115
- } = renderHook(({
116
- onComplete
117
- }) => useQueryExecutor({
118
- execute,
119
- immediate: true,
120
- singular: true,
121
- variables: {},
122
- onComplete
123
- }), {
116
+ } = renderHook((_ref2) => {
117
+ let {
118
+ onComplete
119
+ } = _ref2;
120
+ return useQueryExecutor({
121
+ execute,
122
+ immediate: true,
123
+ singular: true,
124
+ variables: {},
125
+ onComplete
126
+ });
127
+ }, {
124
128
  initialProps: {
125
129
  onComplete: () => null
126
130
  }
@@ -1,14 +1,15 @@
1
1
  import { useState, useEffect, useRef, useDebugValue } from 'react';
2
- export const useStaticInput = (staticValue, {
3
- warn = false,
4
- name = 'input'
5
- } = {}) => {
2
+ export const useStaticInput = function (staticValue) {
3
+ let {
4
+ warn = false,
5
+ name = 'input'
6
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6
7
  const originalValue = useRef(staticValue);
7
8
  const [value, setValue] = useState(() => originalValue.current);
8
- useDebugValue(value, debugValue => "".concat(name, ": ").concat(JSON.stringify(debugValue)));
9
+ useDebugValue(value, debugValue => `${name}: ${JSON.stringify(debugValue)}`);
9
10
  useEffect(() => {
10
11
  if (warn && originalValue.current !== staticValue) {
11
- console.warn("The ".concat(name, " should be static, don't create it within the render loop!"));
12
+ console.warn(`The ${name} should be static, don't create it within the render loop!`);
12
13
  }
13
14
  }, [warn, staticValue, originalValue, name]);
14
15
  return [value, setValue];
@@ -19,9 +19,12 @@ describe('useStaticInput', () => {
19
19
  const {
20
20
  result,
21
21
  rerender
22
- } = renderHook(({
23
- value
24
- }) => useStaticInput(value), {
22
+ } = renderHook((_ref) => {
23
+ let {
24
+ value
25
+ } = _ref;
26
+ return useStaticInput(value);
27
+ }, {
25
28
  initialProps: {
26
29
  value: 42
27
30
  }
@@ -37,11 +40,14 @@ describe('useStaticInput', () => {
37
40
  const {
38
41
  result,
39
42
  rerender
40
- } = renderHook(({
41
- value
42
- }) => useStaticInput(value, {
43
- warn: true
44
- }), {
43
+ } = renderHook((_ref2) => {
44
+ let {
45
+ value
46
+ } = _ref2;
47
+ return useStaticInput(value, {
48
+ warn: true
49
+ });
50
+ }, {
45
51
  initialProps: {
46
52
  value: 42
47
53
  }
@@ -51,19 +57,26 @@ describe('useStaticInput', () => {
51
57
  value: 54
52
58
  });
53
59
  expect(mockWarn).toHaveBeenCalled();
54
- expect(mockWarn.mock.calls.pop()).toMatchInlineSnapshot("\n Array [\n \"The input should be static, don't create it within the render loop!\",\n ]\n ");
60
+ expect(mockWarn.mock.calls.pop()).toMatchInlineSnapshot(`
61
+ Array [
62
+ "The input should be static, don't create it within the render loop!",
63
+ ]
64
+ `);
55
65
  expect(result.current[0]).toBe(42);
56
66
  });
57
67
  it('Should show custom name in warning if supplied', () => {
58
68
  const {
59
69
  result,
60
70
  rerender
61
- } = renderHook(({
62
- value
63
- }) => useStaticInput(value, {
64
- warn: true,
65
- name: 'TESTING THING'
66
- }), {
71
+ } = renderHook((_ref3) => {
72
+ let {
73
+ value
74
+ } = _ref3;
75
+ return useStaticInput(value, {
76
+ warn: true,
77
+ name: 'TESTING THING'
78
+ });
79
+ }, {
67
80
  initialProps: {
68
81
  value: 42
69
82
  }
@@ -80,11 +93,14 @@ describe('useStaticInput', () => {
80
93
  const {
81
94
  result,
82
95
  rerender
83
- } = renderHook(({
84
- value
85
- }) => useStaticInput(value, {
86
- warn: true
87
- }), {
96
+ } = renderHook((_ref4) => {
97
+ let {
98
+ value
99
+ } = _ref4;
100
+ return useStaticInput(value, {
101
+ warn: true
102
+ });
103
+ }, {
88
104
  initialProps: {
89
105
  value: 42
90
106
  }
@@ -113,11 +129,14 @@ describe('useStaticInput', () => {
113
129
  const {
114
130
  result,
115
131
  rerender
116
- } = renderHook(({
117
- value
118
- }) => useStaticInput(value, {
119
- warn: true
120
- }), {
132
+ } = renderHook((_ref5) => {
133
+ let {
134
+ value
135
+ } = _ref5;
136
+ return useStaticInput(value, {
137
+ warn: true
138
+ });
139
+ }, {
121
140
  initialProps: {
122
141
  value: fn
123
142
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2/app-service-data",
3
- "version": "3.7.0",
3
+ "version": "3.9.0",
4
4
  "main": "./build/cjs/index.js",
5
5
  "module": "./build/es/index.js",
6
6
  "types": "build/types/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "build/**"
23
23
  ],
24
24
  "peerDependencies": {
25
- "@dhis2/app-service-config": "3.7.0",
25
+ "@dhis2/app-service-config": "3.9.0",
26
26
  "@dhis2/cli-app-scripts": "^7.1.1",
27
27
  "prop-types": "^15.7.2",
28
28
  "react": "^16.8",