@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
|
@@ -15,14 +15,11 @@ describe('useDataMutation', () => {
|
|
|
15
15
|
const data = {
|
|
16
16
|
answer: 42
|
|
17
17
|
};
|
|
18
|
-
const wrapper =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
data: data
|
|
24
|
-
}, children);
|
|
25
|
-
};
|
|
18
|
+
const wrapper = ({
|
|
19
|
+
children
|
|
20
|
+
}) => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
21
|
+
data: data
|
|
22
|
+
}, children);
|
|
26
23
|
const {
|
|
27
24
|
result
|
|
28
25
|
} = renderHook(() => useDataMutation(mutation), {
|
|
@@ -63,14 +60,11 @@ describe('useDataMutation', () => {
|
|
|
63
60
|
const data = {
|
|
64
61
|
answer: 42
|
|
65
62
|
};
|
|
66
|
-
const wrapper =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
data: data
|
|
72
|
-
}, children);
|
|
73
|
-
};
|
|
63
|
+
const wrapper = ({
|
|
64
|
+
children
|
|
65
|
+
}) => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
66
|
+
data: data
|
|
67
|
+
}, children);
|
|
74
68
|
const {
|
|
75
69
|
result
|
|
76
70
|
} = renderHook(() => useDataMutation(mutation, {
|
|
@@ -104,14 +98,11 @@ describe('useDataMutation', () => {
|
|
|
104
98
|
const data = {
|
|
105
99
|
answer: 42
|
|
106
100
|
};
|
|
107
|
-
const wrapper =
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
data: data
|
|
113
|
-
}, children);
|
|
114
|
-
};
|
|
101
|
+
const wrapper = ({
|
|
102
|
+
children
|
|
103
|
+
}) => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
104
|
+
data: data
|
|
105
|
+
}, children);
|
|
115
106
|
const {
|
|
116
107
|
result
|
|
117
108
|
} = renderHook(() => useDataMutation(mutation, {
|
|
@@ -150,14 +141,11 @@ describe('useDataMutation', () => {
|
|
|
150
141
|
throw error;
|
|
151
142
|
}
|
|
152
143
|
};
|
|
153
|
-
const wrapper =
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
data: data
|
|
159
|
-
}, children);
|
|
160
|
-
};
|
|
144
|
+
const wrapper = ({
|
|
145
|
+
children
|
|
146
|
+
}) => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
147
|
+
data: data
|
|
148
|
+
}, children);
|
|
161
149
|
const {
|
|
162
150
|
result
|
|
163
151
|
} = renderHook(() => useDataMutation(mutation, {
|
|
@@ -185,28 +173,22 @@ describe('useDataMutation', () => {
|
|
|
185
173
|
const mutation = {
|
|
186
174
|
type: 'update',
|
|
187
175
|
resource: 'answer',
|
|
188
|
-
id:
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
} = _ref5;
|
|
192
|
-
return id;
|
|
193
|
-
},
|
|
176
|
+
id: ({
|
|
177
|
+
id
|
|
178
|
+
}) => id,
|
|
194
179
|
data: {
|
|
195
180
|
answer: '?'
|
|
196
181
|
}
|
|
197
182
|
};
|
|
198
|
-
const answerSpy = jest.fn(() => 42);
|
|
183
|
+
const answerSpy = jest.fn(() => Promise.resolve(42));
|
|
199
184
|
const data = {
|
|
200
185
|
answer: answerSpy
|
|
201
186
|
};
|
|
202
|
-
const wrapper =
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
data: data
|
|
208
|
-
}, children);
|
|
209
|
-
};
|
|
187
|
+
const wrapper = ({
|
|
188
|
+
children
|
|
189
|
+
}) => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
190
|
+
data: data
|
|
191
|
+
}, children);
|
|
210
192
|
const {
|
|
211
193
|
result
|
|
212
194
|
} = renderHook(() => useDataMutation(mutation, {
|
|
@@ -242,14 +224,11 @@ describe('useDataMutation', () => {
|
|
|
242
224
|
answer: '?'
|
|
243
225
|
}
|
|
244
226
|
};
|
|
245
|
-
const wrapper =
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
data: {}
|
|
251
|
-
}, children);
|
|
252
|
-
};
|
|
227
|
+
const wrapper = ({
|
|
228
|
+
children
|
|
229
|
+
}) => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
230
|
+
data: {}
|
|
231
|
+
}, children);
|
|
253
232
|
const engineHook = renderHook(() => useDataEngine(), {
|
|
254
233
|
wrapper
|
|
255
234
|
});
|
|
@@ -274,14 +253,11 @@ describe('useDataMutation', () => {
|
|
|
274
253
|
const data = {
|
|
275
254
|
answer: 42
|
|
276
255
|
};
|
|
277
|
-
const wrapper =
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
data: data
|
|
283
|
-
}, children);
|
|
284
|
-
};
|
|
256
|
+
const wrapper = ({
|
|
257
|
+
children
|
|
258
|
+
}) => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
259
|
+
data: data
|
|
260
|
+
}, children);
|
|
285
261
|
const {
|
|
286
262
|
result
|
|
287
263
|
} = renderHook(() => useDataMutation(mutation), {
|
|
@@ -311,14 +287,11 @@ describe('useDataMutation', () => {
|
|
|
311
287
|
const data = {
|
|
312
288
|
answer: 42
|
|
313
289
|
};
|
|
314
|
-
const wrapper =
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
data: data
|
|
320
|
-
}, children);
|
|
321
|
-
};
|
|
290
|
+
const wrapper = ({
|
|
291
|
+
children
|
|
292
|
+
}) => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
293
|
+
data: data
|
|
294
|
+
}, children);
|
|
322
295
|
const {
|
|
323
296
|
result
|
|
324
297
|
} = renderHook(() => useDataMutation(mutation), {
|
|
@@ -3,13 +3,12 @@ import { useState, useRef, useCallback, useDebugValue } from 'react';
|
|
|
3
3
|
import { mergeAndCompareVariables } from './mergeAndCompareVariables';
|
|
4
4
|
import { useDataEngine } from './useDataEngine';
|
|
5
5
|
import { useStaticInput } from './useStaticInput';
|
|
6
|
-
export const useDataQuery =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
6
|
+
export const useDataQuery = (query, {
|
|
7
|
+
onComplete: userOnSuccess,
|
|
8
|
+
onError: userOnError,
|
|
9
|
+
variables: initialVariables = {},
|
|
10
|
+
lazy: initialLazy = false
|
|
11
|
+
} = {}) => {
|
|
13
12
|
const [staticQuery] = useStaticInput(query, {
|
|
14
13
|
warn: true,
|
|
15
14
|
name: 'query'
|
|
@@ -38,7 +37,7 @@ export const useDataQuery = function (query) {
|
|
|
38
37
|
|
|
39
38
|
const onSuccess = data => {
|
|
40
39
|
var _queryState$current$r, _queryState$current;
|
|
41
|
-
(_queryState$current$r = (_queryState$current = queryState.current).refetchCallback) === null || _queryState$current$r === void 0
|
|
40
|
+
(_queryState$current$r = (_queryState$current = queryState.current).refetchCallback) === null || _queryState$current$r === void 0 || _queryState$current$r.call(_queryState$current, data);
|
|
42
41
|
queryState.current.refetchCallback = undefined;
|
|
43
42
|
if (userOnSuccess) {
|
|
44
43
|
userOnSuccess(data);
|
|
@@ -98,12 +97,9 @@ export const useDataQuery = function (query) {
|
|
|
98
97
|
if (queryState.current.enabled && identical) {
|
|
99
98
|
return queryRefetch({
|
|
100
99
|
throwOnError: false
|
|
101
|
-
}).then(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
} = _ref;
|
|
105
|
-
return data;
|
|
106
|
-
});
|
|
100
|
+
}).then(({
|
|
101
|
+
data
|
|
102
|
+
}) => data);
|
|
107
103
|
}
|
|
108
104
|
queryState.current.variables = mergedVariables;
|
|
109
105
|
queryState.current.variablesHash = mergedVariablesHash;
|