@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
|
@@ -9,14 +9,11 @@ describe('<DataQuery />', () => {
|
|
|
9
9
|
const data = {
|
|
10
10
|
answer: 42
|
|
11
11
|
};
|
|
12
|
-
const wrapper =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
data: data
|
|
18
|
-
}, children);
|
|
19
|
-
};
|
|
12
|
+
const wrapper = ({
|
|
13
|
+
children
|
|
14
|
+
}) => /*#__PURE__*/React.createElement(_react3.CustomDataProvider, {
|
|
15
|
+
data: data
|
|
16
|
+
}, children);
|
|
20
17
|
const renderFunction = jest.fn(() => null);
|
|
21
18
|
(0, _react.render)(/*#__PURE__*/React.createElement(_react3.DataQuery, {
|
|
22
19
|
query: {
|
|
@@ -48,14 +45,11 @@ describe('<DataQuery />', () => {
|
|
|
48
45
|
throw expectedError;
|
|
49
46
|
}
|
|
50
47
|
};
|
|
51
|
-
const wrapper =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
data: data
|
|
57
|
-
}, children);
|
|
58
|
-
};
|
|
48
|
+
const wrapper = ({
|
|
49
|
+
children
|
|
50
|
+
}) => /*#__PURE__*/React.createElement(_react3.CustomDataProvider, {
|
|
51
|
+
data: data
|
|
52
|
+
}, children);
|
|
59
53
|
const renderFunction = jest.fn(() => null);
|
|
60
54
|
(0, _react.render)(/*#__PURE__*/React.createElement(_react3.DataQuery, {
|
|
61
55
|
query: {
|
|
@@ -17,14 +17,11 @@ describe('<DataMutation />', () => {
|
|
|
17
17
|
const data = {
|
|
18
18
|
answer: endpointSpy
|
|
19
19
|
};
|
|
20
|
-
const wrapper =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
data: data
|
|
26
|
-
}, children);
|
|
27
|
-
};
|
|
20
|
+
const wrapper = ({
|
|
21
|
+
children
|
|
22
|
+
}) => /*#__PURE__*/React.createElement(_react3.CustomDataProvider, {
|
|
23
|
+
data: data
|
|
24
|
+
}, children);
|
|
28
25
|
const renderSpy = jest.fn(() => null);
|
|
29
26
|
(0, _react.render)(/*#__PURE__*/React.createElement(_react3.DataMutation, {
|
|
30
27
|
mutation: mutation
|
package/build/cjs/index.js
CHANGED
|
@@ -3,53 +3,25 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return _react.CustomDataProvider;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "DataMutation", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _react.DataMutation;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "DataProvider", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _react.DataProvider;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(exports, "DataQuery", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function () {
|
|
27
|
-
return _react.DataQuery;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
FetchError: true
|
|
8
|
+
};
|
|
30
9
|
Object.defineProperty(exports, "FetchError", {
|
|
31
10
|
enumerable: true,
|
|
32
11
|
get: function () {
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(exports, "useDataEngine", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function () {
|
|
39
|
-
return _react.useDataEngine;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(exports, "useDataMutation", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
get: function () {
|
|
45
|
-
return _react.useDataMutation;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
Object.defineProperty(exports, "useDataQuery", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
get: function () {
|
|
51
|
-
return _react.useDataQuery;
|
|
12
|
+
return _dataEngine.FetchError;
|
|
52
13
|
}
|
|
53
14
|
});
|
|
54
15
|
var _react = require("./react");
|
|
55
|
-
|
|
16
|
+
Object.keys(_react).forEach(function (key) {
|
|
17
|
+
if (key === "default" || key === "__esModule") return;
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
19
|
+
if (key in exports && exports[key] === _react[key]) return;
|
|
20
|
+
Object.defineProperty(exports, key, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () {
|
|
23
|
+
return _react[key];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
var _dataEngine = require("@dhis2/data-engine");
|
|
@@ -4,22 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.CustomDataProvider = void 0;
|
|
7
|
+
var _dataEngine = require("@dhis2/data-engine");
|
|
7
8
|
var _reactQuery = require("@tanstack/react-query");
|
|
8
9
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
var _engine = require("../../engine");
|
|
10
|
-
var _links = require("../../links");
|
|
11
10
|
var _DataContext = require("../context/DataContext");
|
|
12
11
|
var _DataProvider = require("./DataProvider");
|
|
13
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
-
const CustomDataProvider =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const engine = new _engine.DataEngine(link);
|
|
13
|
+
const CustomDataProvider = ({
|
|
14
|
+
children,
|
|
15
|
+
data,
|
|
16
|
+
options,
|
|
17
|
+
queryClientOptions = _DataProvider.queryClientOptions
|
|
18
|
+
}) => {
|
|
19
|
+
const link = new _dataEngine.CustomDataLink(data, options);
|
|
20
|
+
const engine = new _dataEngine.DataEngine(link);
|
|
23
21
|
const queryClient = new _reactQuery.QueryClient(queryClientOptions);
|
|
24
22
|
const context = {
|
|
25
23
|
engine
|
|
@@ -5,14 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.DataMutation = void 0;
|
|
7
7
|
var _useDataMutation = require("../hooks/useDataMutation");
|
|
8
|
-
const DataMutation =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} = _ref;
|
|
8
|
+
const DataMutation = ({
|
|
9
|
+
mutation,
|
|
10
|
+
onComplete,
|
|
11
|
+
onError,
|
|
12
|
+
variables,
|
|
13
|
+
children
|
|
14
|
+
}) => {
|
|
16
15
|
const mutationState = (0, _useDataMutation.useDataMutation)(mutation, {
|
|
17
16
|
onComplete,
|
|
18
17
|
onError,
|
|
@@ -5,10 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.queryClientOptions = exports.DataProvider = void 0;
|
|
7
7
|
var _appServiceConfig = require("@dhis2/app-service-config");
|
|
8
|
+
var _dataEngine = require("@dhis2/data-engine");
|
|
8
9
|
var _reactQuery = require("@tanstack/react-query");
|
|
9
10
|
var _react = _interopRequireDefault(require("react"));
|
|
10
|
-
var _engine = require("../../engine");
|
|
11
|
-
var _links = require("../../links");
|
|
12
11
|
var _DataContext = require("../context/DataContext");
|
|
13
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
13
|
/* eslint-disable react/no-unused-prop-types */
|
|
@@ -39,8 +38,8 @@ const DataProvider = props => {
|
|
|
39
38
|
...(0, _appServiceConfig.useConfig)(),
|
|
40
39
|
...props
|
|
41
40
|
};
|
|
42
|
-
const link = new
|
|
43
|
-
const engine = new
|
|
41
|
+
const link = new _dataEngine.RestAPILink(config);
|
|
42
|
+
const engine = new _dataEngine.DataEngine(link);
|
|
44
43
|
const context = {
|
|
45
44
|
engine
|
|
46
45
|
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _dataEngine = require("@dhis2/data-engine");
|
|
3
4
|
var _react = require("@testing-library/react");
|
|
4
5
|
var _react2 = _interopRequireDefault(require("react"));
|
|
5
|
-
var _engine = require("../../engine");
|
|
6
|
-
var _links = require("../../links");
|
|
7
6
|
var _DataContext = require("../context/DataContext");
|
|
8
7
|
var _DataProvider = require("./DataProvider");
|
|
9
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -17,7 +16,7 @@ describe('DataProvider', () => {
|
|
|
17
16
|
expect(renderFunction).toHaveBeenCalled();
|
|
18
17
|
const context = renderFunction.mock.calls.pop()[0];
|
|
19
18
|
expect(context).not.toBeUndefined();
|
|
20
|
-
expect(context.engine).toBeInstanceOf(
|
|
21
|
-
expect(context.engine.link).toBeInstanceOf(
|
|
19
|
+
expect(context.engine).toBeInstanceOf(_dataEngine.DataEngine);
|
|
20
|
+
expect(context.engine.link).toBeInstanceOf(_dataEngine.RestAPILink);
|
|
22
21
|
});
|
|
23
22
|
});
|
|
@@ -5,15 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.DataQuery = void 0;
|
|
7
7
|
var _useDataQuery = require("../hooks/useDataQuery");
|
|
8
|
-
const DataQuery =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} = _ref;
|
|
8
|
+
const DataQuery = ({
|
|
9
|
+
query,
|
|
10
|
+
onComplete,
|
|
11
|
+
onError,
|
|
12
|
+
variables,
|
|
13
|
+
lazy,
|
|
14
|
+
children
|
|
15
|
+
}) => {
|
|
17
16
|
const queryState = (0, _useDataQuery.useDataQuery)(query, {
|
|
18
17
|
onComplete,
|
|
19
18
|
onError,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "CustomDataProvider", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _CustomDataProvider.CustomDataProvider;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "DataMutation", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _DataMutation.DataMutation;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "DataProvider", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _DataProvider.DataProvider;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "DataQuery", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _DataQuery.DataQuery;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
var _CustomDataProvider = require("./CustomDataProvider");
|
|
31
|
+
var _DataMutation = require("./DataMutation");
|
|
32
|
+
var _DataProvider = require("./DataProvider");
|
|
33
|
+
var _DataQuery = require("./DataQuery");
|
|
@@ -5,6 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.DataContext = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
|
-
var
|
|
8
|
+
var _defaultDataContext = require("./defaultDataContext");
|
|
9
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
const DataContext = exports.DataContext = /*#__PURE__*/_react.default.createContext(
|
|
10
|
+
const DataContext = exports.DataContext = /*#__PURE__*/_react.default.createContext(_defaultDataContext.defaultDataContext);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.defaultDataContext = void 0;
|
|
7
|
+
var _dataEngine = require("@dhis2/data-engine");
|
|
8
|
+
const errorMessage = 'DHIS2 data context must be initialized, please ensure that you include a <DataProvider> in your application';
|
|
9
|
+
const link = new _dataEngine.ErrorLink(errorMessage);
|
|
10
|
+
const engine = new _dataEngine.DataEngine(link);
|
|
11
|
+
const defaultDataContext = exports.defaultDataContext = {
|
|
12
|
+
engine
|
|
13
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _defaultDataContext = require("./defaultDataContext");
|
|
4
4
|
describe('defaultContext', () => {
|
|
5
5
|
const originalError = console.error;
|
|
6
6
|
const mockError = jest.fn();
|
|
@@ -10,7 +10,7 @@ describe('defaultContext', () => {
|
|
|
10
10
|
});
|
|
11
11
|
afterEach(() => console.error = originalError);
|
|
12
12
|
it('Should throw if query is called', () => {
|
|
13
|
-
const context =
|
|
13
|
+
const context = _defaultDataContext.defaultDataContext;
|
|
14
14
|
expect(context.engine.query({
|
|
15
15
|
test: {
|
|
16
16
|
resource: 'test'
|
|
@@ -24,7 +24,7 @@ describe('defaultContext', () => {
|
|
|
24
24
|
`);
|
|
25
25
|
});
|
|
26
26
|
it('Should throw and log if mutate is called', () => {
|
|
27
|
-
const context =
|
|
27
|
+
const context = _defaultDataContext.defaultDataContext;
|
|
28
28
|
expect(context.engine.mutate({
|
|
29
29
|
type: 'create',
|
|
30
30
|
resource: 'test',
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "useDataEngine", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _useDataEngine.useDataEngine;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "useDataMutation", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _useDataMutation.useDataMutation;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "useDataQuery", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _useDataQuery.useDataQuery;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
var _useDataEngine = require("./useDataEngine");
|
|
25
|
+
var _useDataMutation = require("./useDataMutation");
|
|
26
|
+
var _useDataQuery = require("./useDataQuery");
|
|
@@ -9,13 +9,12 @@ var _useDataEngine = require("./useDataEngine");
|
|
|
9
9
|
var _useQueryExecutor = require("./useQueryExecutor");
|
|
10
10
|
var _useStaticInput = require("./useStaticInput");
|
|
11
11
|
const empty = {};
|
|
12
|
-
const useDataMutation =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
12
|
+
const useDataMutation = (mutation, {
|
|
13
|
+
onComplete,
|
|
14
|
+
onError,
|
|
15
|
+
variables = empty,
|
|
16
|
+
lazy = true
|
|
17
|
+
} = {}) => {
|
|
19
18
|
const engine = (0, _useDataEngine.useDataEngine)();
|
|
20
19
|
const [theMutation] = (0, _useStaticInput.useStaticInput)(mutation, {
|
|
21
20
|
warn: true,
|
|
@@ -18,14 +18,11 @@ describe('useDataMutation', () => {
|
|
|
18
18
|
const data = {
|
|
19
19
|
answer: 42
|
|
20
20
|
};
|
|
21
|
-
const wrapper =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
data: data
|
|
27
|
-
}, children);
|
|
28
|
-
};
|
|
21
|
+
const wrapper = ({
|
|
22
|
+
children
|
|
23
|
+
}) => /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
|
|
24
|
+
data: data
|
|
25
|
+
}, children);
|
|
29
26
|
const {
|
|
30
27
|
result
|
|
31
28
|
} = (0, _react.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation), {
|
|
@@ -66,14 +63,11 @@ describe('useDataMutation', () => {
|
|
|
66
63
|
const data = {
|
|
67
64
|
answer: 42
|
|
68
65
|
};
|
|
69
|
-
const wrapper =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
data: data
|
|
75
|
-
}, children);
|
|
76
|
-
};
|
|
66
|
+
const wrapper = ({
|
|
67
|
+
children
|
|
68
|
+
}) => /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
|
|
69
|
+
data: data
|
|
70
|
+
}, children);
|
|
77
71
|
const {
|
|
78
72
|
result
|
|
79
73
|
} = (0, _react.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation, {
|
|
@@ -107,14 +101,11 @@ describe('useDataMutation', () => {
|
|
|
107
101
|
const data = {
|
|
108
102
|
answer: 42
|
|
109
103
|
};
|
|
110
|
-
const wrapper =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
data: data
|
|
116
|
-
}, children);
|
|
117
|
-
};
|
|
104
|
+
const wrapper = ({
|
|
105
|
+
children
|
|
106
|
+
}) => /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
|
|
107
|
+
data: data
|
|
108
|
+
}, children);
|
|
118
109
|
const {
|
|
119
110
|
result
|
|
120
111
|
} = (0, _react.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation, {
|
|
@@ -153,14 +144,11 @@ describe('useDataMutation', () => {
|
|
|
153
144
|
throw error;
|
|
154
145
|
}
|
|
155
146
|
};
|
|
156
|
-
const wrapper =
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
data: data
|
|
162
|
-
}, children);
|
|
163
|
-
};
|
|
147
|
+
const wrapper = ({
|
|
148
|
+
children
|
|
149
|
+
}) => /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
|
|
150
|
+
data: data
|
|
151
|
+
}, children);
|
|
164
152
|
const {
|
|
165
153
|
result
|
|
166
154
|
} = (0, _react.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation, {
|
|
@@ -188,28 +176,22 @@ describe('useDataMutation', () => {
|
|
|
188
176
|
const mutation = {
|
|
189
177
|
type: 'update',
|
|
190
178
|
resource: 'answer',
|
|
191
|
-
id:
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
} = _ref5;
|
|
195
|
-
return id;
|
|
196
|
-
},
|
|
179
|
+
id: ({
|
|
180
|
+
id
|
|
181
|
+
}) => id,
|
|
197
182
|
data: {
|
|
198
183
|
answer: '?'
|
|
199
184
|
}
|
|
200
185
|
};
|
|
201
|
-
const answerSpy = jest.fn(() => 42);
|
|
186
|
+
const answerSpy = jest.fn(() => Promise.resolve(42));
|
|
202
187
|
const data = {
|
|
203
188
|
answer: answerSpy
|
|
204
189
|
};
|
|
205
|
-
const wrapper =
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
data: data
|
|
211
|
-
}, children);
|
|
212
|
-
};
|
|
190
|
+
const wrapper = ({
|
|
191
|
+
children
|
|
192
|
+
}) => /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
|
|
193
|
+
data: data
|
|
194
|
+
}, children);
|
|
213
195
|
const {
|
|
214
196
|
result
|
|
215
197
|
} = (0, _react.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation, {
|
|
@@ -245,14 +227,11 @@ describe('useDataMutation', () => {
|
|
|
245
227
|
answer: '?'
|
|
246
228
|
}
|
|
247
229
|
};
|
|
248
|
-
const wrapper =
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
data: {}
|
|
254
|
-
}, children);
|
|
255
|
-
};
|
|
230
|
+
const wrapper = ({
|
|
231
|
+
children
|
|
232
|
+
}) => /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
|
|
233
|
+
data: {}
|
|
234
|
+
}, children);
|
|
256
235
|
const engineHook = (0, _react.renderHook)(() => (0, _useDataEngine.useDataEngine)(), {
|
|
257
236
|
wrapper
|
|
258
237
|
});
|
|
@@ -277,14 +256,11 @@ describe('useDataMutation', () => {
|
|
|
277
256
|
const data = {
|
|
278
257
|
answer: 42
|
|
279
258
|
};
|
|
280
|
-
const wrapper =
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
data: data
|
|
286
|
-
}, children);
|
|
287
|
-
};
|
|
259
|
+
const wrapper = ({
|
|
260
|
+
children
|
|
261
|
+
}) => /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
|
|
262
|
+
data: data
|
|
263
|
+
}, children);
|
|
288
264
|
const {
|
|
289
265
|
result
|
|
290
266
|
} = (0, _react.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation), {
|
|
@@ -314,14 +290,11 @@ describe('useDataMutation', () => {
|
|
|
314
290
|
const data = {
|
|
315
291
|
answer: 42
|
|
316
292
|
};
|
|
317
|
-
const wrapper =
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
data: data
|
|
323
|
-
}, children);
|
|
324
|
-
};
|
|
293
|
+
const wrapper = ({
|
|
294
|
+
children
|
|
295
|
+
}) => /*#__PURE__*/React.createElement(_CustomDataProvider.CustomDataProvider, {
|
|
296
|
+
data: data
|
|
297
|
+
}, children);
|
|
325
298
|
const {
|
|
326
299
|
result
|
|
327
300
|
} = (0, _react.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation), {
|
|
@@ -9,13 +9,12 @@ var _react = require("react");
|
|
|
9
9
|
var _mergeAndCompareVariables = require("./mergeAndCompareVariables");
|
|
10
10
|
var _useDataEngine = require("./useDataEngine");
|
|
11
11
|
var _useStaticInput = require("./useStaticInput");
|
|
12
|
-
const useDataQuery =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
12
|
+
const useDataQuery = (query, {
|
|
13
|
+
onComplete: userOnSuccess,
|
|
14
|
+
onError: userOnError,
|
|
15
|
+
variables: initialVariables = {},
|
|
16
|
+
lazy: initialLazy = false
|
|
17
|
+
} = {}) => {
|
|
19
18
|
const [staticQuery] = (0, _useStaticInput.useStaticInput)(query, {
|
|
20
19
|
warn: true,
|
|
21
20
|
name: 'query'
|
|
@@ -44,7 +43,7 @@ const useDataQuery = function (query) {
|
|
|
44
43
|
|
|
45
44
|
const onSuccess = data => {
|
|
46
45
|
var _queryState$current$r, _queryState$current;
|
|
47
|
-
(_queryState$current$r = (_queryState$current = queryState.current).refetchCallback) === null || _queryState$current$r === void 0
|
|
46
|
+
(_queryState$current$r = (_queryState$current = queryState.current).refetchCallback) === null || _queryState$current$r === void 0 || _queryState$current$r.call(_queryState$current, data);
|
|
48
47
|
queryState.current.refetchCallback = undefined;
|
|
49
48
|
if (userOnSuccess) {
|
|
50
49
|
userOnSuccess(data);
|
|
@@ -104,12 +103,9 @@ const useDataQuery = function (query) {
|
|
|
104
103
|
if (queryState.current.enabled && identical) {
|
|
105
104
|
return queryRefetch({
|
|
106
105
|
throwOnError: false
|
|
107
|
-
}).then(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
} = _ref;
|
|
111
|
-
return data;
|
|
112
|
-
});
|
|
106
|
+
}).then(({
|
|
107
|
+
data
|
|
108
|
+
}) => data);
|
|
113
109
|
}
|
|
114
110
|
queryState.current.variables = mergedVariables;
|
|
115
111
|
queryState.current.variablesHash = mergedVariablesHash;
|