@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.
- package/build/cjs/__tests__/integration.test.js +16 -10
- package/build/cjs/__tests__/mutations.test.js +8 -5
- package/build/cjs/engine/DataEngine.js +14 -12
- package/build/cjs/engine/helpers/resolveDynamicQuery.js +14 -11
- package/build/cjs/engine/helpers/resolveDynamicQuery.test.js +23 -14
- package/build/cjs/engine/helpers/validate.js +6 -4
- package/build/cjs/engine/helpers/validate.test.js +74 -15
- package/build/cjs/engine/types/FetchError.js +6 -5
- package/build/cjs/engine/types/InvalidQueryError.js +1 -1
- package/build/cjs/index.js +10 -10
- package/build/cjs/links/CustomDataLink.js +8 -6
- package/build/cjs/links/CustomDataLink.test.js +2 -2
- package/build/cjs/links/RestAPILink/fetchData.js +3 -2
- package/build/cjs/links/RestAPILink/fetchData.test.js +1 -1
- package/build/cjs/links/RestAPILink/metadataResources.js +1 -1
- package/build/cjs/links/RestAPILink/path.js +5 -1
- package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +29 -16
- package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.js +9 -6
- package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +2 -2
- package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +51 -33
- package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +6 -3
- package/build/cjs/links/RestAPILink/queryToRequestOptions.js +1 -1
- package/build/cjs/links/RestAPILink/queryToRequestOptions.test.js +56 -6
- package/build/cjs/links/RestAPILink/queryToResourcePath.js +14 -6
- package/build/cjs/links/RestAPILink/queryToResourcePath.test.js +16 -16
- package/build/cjs/links/RestAPILink/validateQuery.test.js +12 -12
- package/build/cjs/links/RestAPILink.js +4 -3
- package/build/cjs/react/components/CustomDataProvider.js +7 -6
- package/build/cjs/react/components/DataMutation.js +8 -7
- package/build/cjs/react/components/DataProvider.js +1 -1
- package/build/cjs/react/components/DataQuery.js +9 -8
- package/build/cjs/react/context/defaultContext.test.js +10 -2
- package/build/cjs/react/hooks/stableVariablesHash.js +1 -2
- package/build/cjs/react/hooks/stableVariablesHash.test.js +6 -6
- package/build/cjs/react/hooks/useDataMutation.js +7 -6
- package/build/cjs/react/hooks/useDataMutation.test.js +70 -43
- package/build/cjs/react/hooks/useDataQuery.js +13 -9
- package/build/cjs/react/hooks/useDataQuery.test.js +259 -162
- package/build/cjs/react/hooks/useQueryExecutor.js +11 -9
- package/build/cjs/react/hooks/useQueryExecutor.test.js +16 -12
- package/build/cjs/react/hooks/useStaticInput.js +7 -6
- package/build/cjs/react/hooks/useStaticInput.test.js +44 -25
- package/build/cjs/react/index.js +6 -6
- package/build/es/__tests__/integration.test.js +16 -10
- package/build/es/__tests__/mutations.test.js +8 -5
- package/build/es/engine/DataEngine.js +14 -12
- package/build/es/engine/helpers/resolveDynamicQuery.js +14 -11
- package/build/es/engine/helpers/resolveDynamicQuery.test.js +23 -14
- package/build/es/engine/helpers/validate.js +6 -4
- package/build/es/engine/helpers/validate.test.js +74 -15
- package/build/es/engine/types/FetchError.js +6 -5
- package/build/es/engine/types/InvalidQueryError.js +1 -1
- package/build/es/links/CustomDataLink.js +8 -6
- package/build/es/links/CustomDataLink.test.js +2 -2
- package/build/es/links/RestAPILink/fetchData.js +3 -2
- package/build/es/links/RestAPILink/fetchData.test.js +1 -1
- package/build/es/links/RestAPILink/path.js +5 -1
- package/build/es/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +28 -15
- package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.js +8 -5
- package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +2 -2
- package/build/es/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +50 -32
- package/build/es/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +6 -3
- package/build/es/links/RestAPILink/queryToRequestOptions.js +1 -1
- package/build/es/links/RestAPILink/queryToRequestOptions.test.js +56 -6
- package/build/es/links/RestAPILink/queryToResourcePath.js +14 -6
- package/build/es/links/RestAPILink/queryToResourcePath.test.js +16 -16
- package/build/es/links/RestAPILink/validateQuery.test.js +12 -12
- package/build/es/links/RestAPILink.js +4 -3
- package/build/es/react/components/CustomDataProvider.js +7 -6
- package/build/es/react/components/DataMutation.js +8 -7
- package/build/es/react/components/DataQuery.js +9 -8
- package/build/es/react/context/defaultContext.test.js +10 -2
- package/build/es/react/hooks/stableVariablesHash.js +1 -2
- package/build/es/react/hooks/stableVariablesHash.test.js +6 -6
- package/build/es/react/hooks/useDataMutation.js +7 -6
- package/build/es/react/hooks/useDataMutation.test.js +70 -43
- package/build/es/react/hooks/useDataQuery.js +13 -9
- package/build/es/react/hooks/useDataQuery.test.js +259 -162
- package/build/es/react/hooks/useQueryExecutor.js +11 -9
- package/build/es/react/hooks/useQueryExecutor.test.js +16 -12
- package/build/es/react/hooks/useStaticInput.js +7 -6
- package/build/es/react/hooks/useStaticInput.test.js +44 -25
- 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
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
4
|
-
|
|
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 =>
|
|
9
|
+
useDebugValue(value, debugValue => `${name}: ${JSON.stringify(debugValue)}`);
|
|
9
10
|
useEffect(() => {
|
|
10
11
|
if (warn && originalValue.current !== staticValue) {
|
|
11
|
-
console.warn(
|
|
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
|
-
|
|
24
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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(
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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.
|
|
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.
|
|
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",
|