@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
|
@@ -7,13 +7,14 @@ exports.DataMutation = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _useDataMutation = require("../hooks/useDataMutation");
|
|
9
9
|
|
|
10
|
-
const DataMutation = ({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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,
|
|
@@ -7,14 +7,15 @@ exports.DataQuery = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _useDataQuery = require("../hooks/useDataQuery");
|
|
9
9
|
|
|
10
|
-
const DataQuery = ({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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(
|
|
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(
|
|
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
|
|
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(
|
|
34
|
-
expect((0, _stableVariablesHash.stableVariablesHash)(two)).toMatchInlineSnapshot("
|
|
35
|
-
expect((0, _stableVariablesHash.stableVariablesHash)(three)).toMatchInlineSnapshot("
|
|
36
|
-
expect((0, _stableVariablesHash.stableVariablesHash)(four)).toMatchInlineSnapshot("
|
|
37
|
-
expect((0, _stableVariablesHash.stableVariablesHash)(five)).toMatchInlineSnapshot("
|
|
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("
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
201
|
-
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
131
|
-
|
|
130
|
+
}).then((_ref) => {
|
|
131
|
+
let {
|
|
132
|
+
data
|
|
133
|
+
} = _ref;
|
|
134
|
+
return data;
|
|
135
|
+
});
|
|
132
136
|
}
|
|
133
137
|
|
|
134
138
|
queryState.current.variables = mergedVariables;
|