@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.
- package/build/cjs/__tests__/integration.test.js +10 -16
- package/build/cjs/__tests__/mutations.test.js +5 -8
- package/build/cjs/index.js +16 -44
- package/build/cjs/react/components/CustomDataProvider.js +9 -11
- package/build/cjs/react/components/DataMutation.js +7 -8
- package/build/cjs/react/components/DataProvider.js +3 -4
- package/build/cjs/react/components/DataProvider.test.js +3 -4
- package/build/cjs/react/components/DataQuery.js +8 -9
- package/build/cjs/react/components/index.js +33 -0
- package/build/cjs/react/context/DataContext.js +2 -2
- package/build/cjs/react/context/defaultDataContext.js +13 -0
- package/build/cjs/react/context/{defaultContext.test.js → defaultDataContext.test.js} +3 -3
- package/build/cjs/react/hooks/index.js +26 -0
- package/build/cjs/react/hooks/useDataMutation.js +6 -7
- package/build/cjs/react/hooks/useDataMutation.test.js +44 -71
- package/build/cjs/react/hooks/useDataQuery.js +10 -14
- package/build/cjs/react/hooks/useDataQuery.test.js +172 -265
- package/build/cjs/react/hooks/useQueryExecutor.js +11 -13
- package/build/cjs/react/hooks/useQueryExecutor.test.js +12 -16
- package/build/cjs/react/hooks/useStaticInput.js +4 -5
- package/build/cjs/react/hooks/useStaticInput.test.js +24 -39
- package/build/cjs/react/index.js +22 -77
- package/build/es/__tests__/integration.test.js +10 -16
- package/build/es/__tests__/mutations.test.js +5 -8
- package/build/es/index.js +2 -3
- package/build/es/react/components/CustomDataProvider.js +7 -9
- package/build/es/react/components/DataMutation.js +7 -8
- package/build/es/react/components/DataProvider.js +1 -2
- package/build/es/react/components/DataProvider.test.js +1 -2
- package/build/es/react/components/DataQuery.js +8 -9
- package/build/es/react/components/index.js +4 -0
- package/build/es/react/context/DataContext.js +2 -2
- package/build/es/react/context/{defaultContext.js → defaultDataContext.js} +2 -3
- package/build/es/react/context/{defaultContext.test.js → defaultDataContext.test.js} +3 -3
- package/build/es/react/hooks/index.js +3 -0
- package/build/es/react/hooks/useDataMutation.js +6 -7
- package/build/es/react/hooks/useDataMutation.test.js +44 -71
- package/build/es/react/hooks/useDataQuery.js +10 -14
- package/build/es/react/hooks/useDataQuery.test.js +172 -265
- package/build/es/react/hooks/useQueryExecutor.js +10 -12
- package/build/es/react/hooks/useQueryExecutor.test.js +12 -16
- package/build/es/react/hooks/useStaticInput.js +4 -5
- package/build/es/react/hooks/useStaticInput.test.js +24 -39
- package/build/es/react/index.js +3 -11
- package/build/types/index.d.ts +2 -3
- package/build/types/react/components/CustomDataProvider.d.ts +1 -1
- package/build/types/react/components/DataMutation.d.ts +1 -1
- package/build/types/react/components/DataQuery.d.ts +1 -1
- package/build/types/react/components/index.d.ts +4 -0
- package/build/types/react/context/defaultDataContext.d.ts +4 -0
- package/build/types/react/hooks/index.d.ts +3 -0
- package/build/types/react/hooks/mergeAndCompareVariables.d.ts +1 -1
- package/build/types/react/hooks/useDataEngine.d.ts +1 -1
- package/build/types/react/hooks/useDataMutation.d.ts +1 -1
- package/build/types/react/hooks/useDataQuery.d.ts +1 -1
- package/build/types/react/index.d.ts +2 -11
- package/build/types/types.d.ts +2 -7
- package/package.json +4 -3
- package/build/cjs/engine/DataEngine.js +0 -73
- package/build/cjs/engine/DataEngine.test.js +0 -156
- package/build/cjs/engine/helpers/getMutationFetchType.js +0 -8
- package/build/cjs/engine/helpers/getMutationFetchType.test.js +0 -39
- package/build/cjs/engine/helpers/resolveDynamicQuery.js +0 -21
- package/build/cjs/engine/helpers/resolveDynamicQuery.test.js +0 -63
- package/build/cjs/engine/helpers/validate.js +0 -62
- package/build/cjs/engine/helpers/validate.test.js +0 -206
- package/build/cjs/engine/index.js +0 -104
- package/build/cjs/engine/types/DataEngineLink.js +0 -1
- package/build/cjs/engine/types/ExecuteOptions.js +0 -1
- package/build/cjs/engine/types/FetchError.js +0 -24
- package/build/cjs/engine/types/FetchError.test.js +0 -14
- package/build/cjs/engine/types/InvalidQueryError.js +0 -18
- package/build/cjs/engine/types/JsonValue.js +0 -1
- package/build/cjs/engine/types/Mutation.js +0 -1
- package/build/cjs/engine/types/PossiblyDynamic.js +0 -1
- package/build/cjs/engine/types/Query.js +0 -1
- package/build/cjs/engine/types/QueryParameters.js +0 -1
- package/build/cjs/links/CustomDataLink.js +0 -51
- package/build/cjs/links/CustomDataLink.test.js +0 -73
- package/build/cjs/links/ErrorLink.js +0 -20
- package/build/cjs/links/RestAPILink/fetchData.js +0 -80
- package/build/cjs/links/RestAPILink/fetchData.test.js +0 -132
- package/build/cjs/links/RestAPILink/metadataResources.js +0 -22
- package/build/cjs/links/RestAPILink/path.js +0 -14
- package/build/cjs/links/RestAPILink/path.test.js +0 -16
- package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +0 -58
- package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.test.js +0 -73
- package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.js +0 -80
- package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +0 -120
- package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +0 -170
- package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.test.js +0 -246
- package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +0 -14
- package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.test.js +0 -20
- package/build/cjs/links/RestAPILink/queryToRequestOptions.js +0 -34
- package/build/cjs/links/RestAPILink/queryToRequestOptions.test.js +0 -107
- package/build/cjs/links/RestAPILink/queryToResourcePath.js +0 -82
- package/build/cjs/links/RestAPILink/queryToResourcePath.test.js +0 -173
- package/build/cjs/links/RestAPILink/validateQuery.js +0 -59
- package/build/cjs/links/RestAPILink/validateQuery.test.js +0 -209
- package/build/cjs/links/RestAPILink.js +0 -33
- package/build/cjs/links/RestAPILink.test.js +0 -21
- package/build/cjs/links/index.js +0 -38
- package/build/cjs/locales/en/translations.json +0 -3
- package/build/cjs/locales/index.js +0 -21
- package/build/cjs/react/context/defaultContext.js +0 -14
- package/build/es/engine/DataEngine.js +0 -66
- package/build/es/engine/DataEngine.test.js +0 -154
- package/build/es/engine/helpers/getMutationFetchType.js +0 -1
- package/build/es/engine/helpers/getMutationFetchType.test.js +0 -37
- package/build/es/engine/helpers/resolveDynamicQuery.js +0 -14
- package/build/es/engine/helpers/resolveDynamicQuery.test.js +0 -61
- package/build/es/engine/helpers/validate.js +0 -53
- package/build/es/engine/helpers/validate.test.js +0 -204
- package/build/es/engine/index.js +0 -10
- package/build/es/engine/types/DataEngineLink.js +0 -1
- package/build/es/engine/types/ExecuteOptions.js +0 -1
- package/build/es/engine/types/FetchError.js +0 -17
- package/build/es/engine/types/FetchError.test.js +0 -12
- package/build/es/engine/types/InvalidQueryError.js +0 -11
- package/build/es/engine/types/JsonValue.js +0 -1
- package/build/es/engine/types/Mutation.js +0 -1
- package/build/es/engine/types/PossiblyDynamic.js +0 -1
- package/build/es/engine/types/Query.js +0 -1
- package/build/es/engine/types/QueryParameters.js +0 -1
- package/build/es/links/CustomDataLink.js +0 -44
- package/build/es/links/CustomDataLink.test.js +0 -71
- package/build/es/links/ErrorLink.js +0 -13
- package/build/es/links/RestAPILink/fetchData.js +0 -71
- package/build/es/links/RestAPILink/fetchData.test.js +0 -130
- package/build/es/links/RestAPILink/metadataResources.js +0 -16
- package/build/es/links/RestAPILink/path.js +0 -7
- package/build/es/links/RestAPILink/path.test.js +0 -14
- package/build/es/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +0 -47
- package/build/es/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.test.js +0 -71
- package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.js +0 -70
- package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +0 -118
- package/build/es/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +0 -151
- package/build/es/links/RestAPILink/queryToRequestOptions/textPlainMatchers.test.js +0 -244
- package/build/es/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +0 -7
- package/build/es/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.test.js +0 -18
- package/build/es/links/RestAPILink/queryToRequestOptions.js +0 -27
- package/build/es/links/RestAPILink/queryToRequestOptions.test.js +0 -105
- package/build/es/links/RestAPILink/queryToResourcePath.js +0 -75
- package/build/es/links/RestAPILink/queryToResourcePath.test.js +0 -171
- package/build/es/links/RestAPILink/validateQuery.js +0 -52
- package/build/es/links/RestAPILink/validateQuery.test.js +0 -207
- package/build/es/links/RestAPILink.js +0 -26
- package/build/es/links/RestAPILink.test.js +0 -19
- package/build/es/links/index.js +0 -4
- package/build/es/locales/en/translations.json +0 -3
- package/build/es/locales/index.js +0 -13
- package/build/types/engine/DataEngine.d.ts +0 -13
- package/build/types/engine/helpers/getMutationFetchType.d.ts +0 -3
- package/build/types/engine/helpers/resolveDynamicQuery.d.ts +0 -2
- package/build/types/engine/helpers/validate.d.ts +0 -4
- package/build/types/engine/index.d.ts +0 -9
- package/build/types/engine/types/DataEngineLink.d.ts +0 -9
- package/build/types/engine/types/ExecuteOptions.d.ts +0 -9
- package/build/types/engine/types/FetchError.d.ts +0 -19
- package/build/types/engine/types/InvalidQueryError.d.ts +0 -5
- package/build/types/engine/types/JsonValue.d.ts +0 -6
- package/build/types/engine/types/Mutation.d.ts +0 -29
- package/build/types/engine/types/PossiblyDynamic.d.ts +0 -1
- package/build/types/engine/types/Query.d.ts +0 -24
- package/build/types/engine/types/QueryParameters.d.ts +0 -12
- package/build/types/links/CustomDataLink.d.ts +0 -17
- package/build/types/links/ErrorLink.d.ts +0 -6
- package/build/types/links/RestAPILink/fetchData.d.ts +0 -4
- package/build/types/links/RestAPILink/metadataResources.d.ts +0 -2
- package/build/types/links/RestAPILink/path.d.ts +0 -1
- package/build/types/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.d.ts +0 -6
- package/build/types/links/RestAPILink/queryToRequestOptions/requestContentType.d.ts +0 -6
- package/build/types/links/RestAPILink/queryToRequestOptions/textPlainMatchers.d.ts +0 -14
- package/build/types/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.d.ts +0 -2
- package/build/types/links/RestAPILink/queryToRequestOptions.d.ts +0 -2
- package/build/types/links/RestAPILink/queryToResourcePath.d.ts +0 -3
- package/build/types/links/RestAPILink/validateQuery.d.ts +0 -2
- package/build/types/links/RestAPILink.d.ts +0 -10
- package/build/types/links/index.d.ts +0 -3
- 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 =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
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)(
|
|
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
|
|
8
|
-
|
|
9
|
-
|
|
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)(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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 =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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)(
|
|
25
|
-
|
|
26
|
-
|
|
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)(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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)(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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)(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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)(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
}
|
package/build/cjs/react/index.js
CHANGED
|
@@ -3,80 +3,25 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Object.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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 =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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 =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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 =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
2
|
-
export {
|
|
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 =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
export const DataContext = /*#__PURE__*/React.createContext(
|
|
2
|
+
import { defaultDataContext } from './defaultDataContext';
|
|
3
|
+
export const DataContext = /*#__PURE__*/React.createContext(defaultDataContext);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { DataEngine } from '
|
|
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
|
|
5
|
+
export const defaultDataContext = {
|
|
7
6
|
engine
|
|
8
7
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 =
|
|
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 =
|
|
25
|
+
const context = defaultDataContext;
|
|
26
26
|
expect(context.engine.mutate({
|
|
27
27
|
type: 'create',
|
|
28
28
|
resource: 'test',
|
|
@@ -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 =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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,
|