@dhis2/app-service-data 3.11.2 → 3.12.0-alpha.1
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 +6 -15
- package/build/cjs/__tests__/mutations.test.js +4 -11
- package/build/cjs/engine/DataEngine.js +4 -14
- package/build/cjs/engine/DataEngine.test.js +0 -2
- package/build/cjs/engine/helpers/getMutationFetchType.js +0 -2
- package/build/cjs/engine/helpers/getMutationFetchType.test.js +0 -1
- package/build/cjs/engine/helpers/resolveDynamicQuery.js +0 -2
- package/build/cjs/engine/helpers/resolveDynamicQuery.test.js +3 -4
- package/build/cjs/engine/helpers/validate.js +0 -21
- package/build/cjs/engine/helpers/validate.test.js +0 -1
- package/build/cjs/engine/index.js +0 -18
- package/build/cjs/engine/types/FetchError.js +3 -8
- package/build/cjs/engine/types/FetchError.test.js +0 -1
- package/build/cjs/engine/types/InvalidQueryError.js +3 -8
- package/build/cjs/index.js +0 -2
- package/build/cjs/links/CustomDataLink.js +3 -17
- package/build/cjs/links/CustomDataLink.test.js +0 -1
- package/build/cjs/links/ErrorLink.js +3 -7
- package/build/cjs/links/RestAPILink/fetchData.js +12 -22
- package/build/cjs/links/RestAPILink/fetchData.test.js +0 -2
- package/build/cjs/links/RestAPILink/metadataResources.js +9 -7
- package/build/cjs/links/RestAPILink/path.js +0 -3
- package/build/cjs/links/RestAPILink/path.test.js +0 -1
- package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +9 -14
- package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.test.js +0 -1
- package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.js +4 -31
- package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +0 -1
- package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +24 -40
- package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.test.js +10 -1
- package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +0 -2
- package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.test.js +0 -1
- package/build/cjs/links/RestAPILink/queryToRequestOptions.js +0 -9
- package/build/cjs/links/RestAPILink/queryToRequestOptions.test.js +0 -1
- package/build/cjs/links/RestAPILink/queryToResourcePath.js +3 -24
- package/build/cjs/links/RestAPILink/queryToResourcePath.test.js +2 -4
- package/build/cjs/links/RestAPILink/validateQuery.js +4 -18
- package/build/cjs/links/RestAPILink/validateQuery.test.js +0 -1
- package/build/cjs/links/RestAPILink.js +3 -14
- package/build/cjs/links/RestAPILink.test.js +0 -2
- package/build/cjs/links/index.js +0 -6
- package/build/cjs/react/components/CustomDataProvider.js +2 -11
- package/build/cjs/react/components/DataMutation.js +1 -4
- package/build/cjs/react/components/DataProvider.js +5 -14
- package/build/cjs/react/components/DataProvider.test.js +2 -9
- package/build/cjs/react/components/DataQuery.js +1 -4
- package/build/cjs/react/context/DataContext.js +2 -8
- package/build/cjs/react/context/defaultContext.js +2 -6
- package/build/cjs/react/context/defaultContext.test.js +0 -1
- package/build/cjs/react/hooks/mergeAndCompareVariables.js +4 -6
- package/build/cjs/react/hooks/mergeAndCompareVariables.test.js +2 -3
- package/build/cjs/react/hooks/stableVariablesHash.js +11 -16
- package/build/cjs/react/hooks/stableVariablesHash.test.js +0 -1
- package/build/cjs/react/hooks/useDataEngine.js +0 -4
- package/build/cjs/react/hooks/useDataMutation.js +0 -7
- package/build/cjs/react/hooks/useDataMutation.test.js +42 -71
- package/build/cjs/react/hooks/useDataQuery.js +11 -22
- package/build/cjs/react/hooks/useDataQuery.test.js +318 -374
- package/build/cjs/react/hooks/useQueryExecutor.js +6 -14
- package/build/cjs/react/hooks/useQueryExecutor.test.js +42 -45
- package/build/cjs/react/hooks/useStaticInput.js +0 -3
- package/build/cjs/react/hooks/useStaticInput.test.js +8 -10
- package/build/cjs/react/index.js +0 -11
- package/build/cjs/setupRTL.js +1 -2
- package/build/es/__tests__/integration.test.js +4 -8
- package/build/es/__tests__/mutations.test.js +2 -4
- package/build/es/engine/DataEngine.js +3 -8
- package/build/es/engine/DataEngine.test.js +0 -1
- package/build/es/engine/helpers/resolveDynamicQuery.test.js +3 -3
- package/build/es/engine/helpers/validate.js +0 -13
- package/build/es/engine/types/FetchError.js +3 -6
- package/build/es/engine/types/InvalidQueryError.js +3 -6
- package/build/es/links/CustomDataLink.js +3 -15
- package/build/es/links/ErrorLink.js +3 -5
- package/build/es/links/RestAPILink/fetchData.js +12 -16
- package/build/es/links/RestAPILink/metadataResources.js +8 -3
- package/build/es/links/RestAPILink/path.js +0 -1
- package/build/es/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +9 -4
- package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.js +2 -19
- package/build/es/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +24 -20
- package/build/es/links/RestAPILink/queryToRequestOptions/textPlainMatchers.test.js +10 -0
- package/build/es/links/RestAPILink/queryToRequestOptions.js +0 -7
- package/build/es/links/RestAPILink/queryToResourcePath.js +3 -21
- package/build/es/links/RestAPILink/queryToResourcePath.test.js +2 -3
- package/build/es/links/RestAPILink/validateQuery.js +4 -16
- package/build/es/links/RestAPILink.js +3 -8
- package/build/es/react/components/CustomDataProvider.js +1 -1
- package/build/es/react/components/DataMutation.js +1 -1
- package/build/es/react/components/DataProvider.js +3 -1
- package/build/es/react/components/DataProvider.test.js +1 -1
- package/build/es/react/components/DataQuery.js +1 -1
- package/build/es/react/hooks/mergeAndCompareVariables.js +4 -3
- package/build/es/react/hooks/mergeAndCompareVariables.test.js +2 -1
- package/build/es/react/hooks/stableVariablesHash.js +11 -14
- package/build/es/react/hooks/useDataMutation.test.js +17 -39
- package/build/es/react/hooks/useDataQuery.js +11 -15
- package/build/es/react/hooks/useDataQuery.test.js +268 -318
- package/build/es/react/hooks/useQueryExecutor.js +6 -9
- package/build/es/react/hooks/useQueryExecutor.test.js +33 -34
- package/build/es/react/hooks/useStaticInput.test.js +6 -6
- package/build/es/setupRTL.js +1 -1
- package/build/types/engine/types/ExecuteOptions.d.ts +1 -1
- package/build/types/engine/types/FetchError.d.ts +2 -2
- package/build/types/engine/types/JsonValue.d.ts +1 -1
- package/build/types/engine/types/Mutation.d.ts +2 -2
- package/build/types/engine/types/PossiblyDynamic.d.ts +1 -1
- package/build/types/engine/types/Query.d.ts +3 -3
- package/build/types/engine/types/QueryParameters.d.ts +4 -4
- package/build/types/links/CustomDataLink.d.ts +2 -2
- package/build/types/links/RestAPILink/queryToRequestOptions/requestContentType.d.ts +1 -1
- package/build/types/links/RestAPILink/queryToRequestOptions.d.ts +1 -1
- package/build/types/react/hooks/mergeAndCompareVariables.d.ts +1 -1
- package/build/types/types.d.ts +6 -6
- package/package.json +4 -4
|
@@ -4,14 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useQueryExecutor = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _engine = require("../../engine");
|
|
11
|
-
|
|
12
9
|
var _useStaticInput = require("./useStaticInput");
|
|
13
|
-
|
|
14
|
-
const useQueryExecutor = (_ref) => {
|
|
10
|
+
const useQueryExecutor = _ref => {
|
|
15
11
|
let {
|
|
16
12
|
execute,
|
|
17
13
|
variables: initialVariables,
|
|
@@ -48,14 +44,13 @@ const useQueryExecutor = (_ref) => {
|
|
|
48
44
|
called: true,
|
|
49
45
|
loading: true
|
|
50
46
|
} : state);
|
|
51
|
-
|
|
52
47
|
if (singular) {
|
|
53
48
|
abort(); // Cleanup any in-progress fetches
|
|
54
49
|
}
|
|
55
|
-
|
|
56
50
|
const controller = new AbortController();
|
|
57
51
|
abortControllersRef.current.push(controller);
|
|
58
|
-
variables.current = {
|
|
52
|
+
variables.current = {
|
|
53
|
+
...variables.current,
|
|
59
54
|
...newVariables
|
|
60
55
|
};
|
|
61
56
|
const options = {
|
|
@@ -73,7 +68,6 @@ const useQueryExecutor = (_ref) => {
|
|
|
73
68
|
});
|
|
74
69
|
return data;
|
|
75
70
|
}
|
|
76
|
-
|
|
77
71
|
return new Promise(() => undefined); // Wait forever
|
|
78
72
|
}).catch(error => {
|
|
79
73
|
if (!controller.signal.aborted) {
|
|
@@ -83,17 +77,16 @@ const useQueryExecutor = (_ref) => {
|
|
|
83
77
|
error
|
|
84
78
|
});
|
|
85
79
|
}
|
|
86
|
-
|
|
87
80
|
return new Promise(() => undefined); // Don't throw errors in refetch promises, wait forever
|
|
88
81
|
});
|
|
89
|
-
}, [abort, onComplete, onError, singular, theExecute]);
|
|
90
|
-
// may be triggered by changes to input, i.e. recreating the onComplete callback
|
|
82
|
+
}, [abort, onComplete, onError, singular, theExecute]);
|
|
91
83
|
|
|
84
|
+
// Don't include immediate or refetch as deps, otherwise unintentional refetches
|
|
85
|
+
// may be triggered by changes to input, i.e. recreating the onComplete callback
|
|
92
86
|
(0, _react.useEffect)(() => {
|
|
93
87
|
if (immediate) {
|
|
94
88
|
refetch();
|
|
95
89
|
}
|
|
96
|
-
|
|
97
90
|
return abort;
|
|
98
91
|
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
99
92
|
|
|
@@ -103,5 +96,4 @@ const useQueryExecutor = (_ref) => {
|
|
|
103
96
|
...state
|
|
104
97
|
};
|
|
105
98
|
};
|
|
106
|
-
|
|
107
99
|
exports.useQueryExecutor = useQueryExecutor;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
5
4
|
var _useQueryExecutor = require("./useQueryExecutor");
|
|
6
|
-
|
|
7
5
|
const testError = new Error('TEST ERROR');
|
|
8
6
|
let theSignal;
|
|
9
|
-
const execute = jest.fn(async
|
|
7
|
+
const execute = jest.fn(async _ref => {
|
|
10
8
|
let {
|
|
11
9
|
signal
|
|
12
10
|
} = _ref;
|
|
@@ -24,7 +22,7 @@ describe('useQueryExecutor', () => {
|
|
|
24
22
|
it('When not immediate, should start with called false and loading false', () => {
|
|
25
23
|
const {
|
|
26
24
|
result
|
|
27
|
-
} = (0,
|
|
25
|
+
} = (0, _react.renderHook)(() => (0, _useQueryExecutor.useQueryExecutor)({
|
|
28
26
|
execute,
|
|
29
27
|
immediate: false,
|
|
30
28
|
singular: true,
|
|
@@ -37,9 +35,8 @@ describe('useQueryExecutor', () => {
|
|
|
37
35
|
});
|
|
38
36
|
it('When immediate, should start with called true and loading true', async () => {
|
|
39
37
|
const {
|
|
40
|
-
result
|
|
41
|
-
|
|
42
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useQueryExecutor.useQueryExecutor)({
|
|
38
|
+
result
|
|
39
|
+
} = (0, _react.renderHook)(() => (0, _useQueryExecutor.useQueryExecutor)({
|
|
43
40
|
execute,
|
|
44
41
|
immediate: true,
|
|
45
42
|
singular: true,
|
|
@@ -49,18 +46,18 @@ describe('useQueryExecutor', () => {
|
|
|
49
46
|
called: true,
|
|
50
47
|
loading: true
|
|
51
48
|
});
|
|
52
|
-
await
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
await (0, _react.waitFor)(() => {
|
|
50
|
+
expect(result.current).toMatchObject({
|
|
51
|
+
called: true,
|
|
52
|
+
loading: false,
|
|
53
|
+
data: 42
|
|
54
|
+
});
|
|
57
55
|
});
|
|
58
56
|
});
|
|
59
57
|
it('Should start when refetch called (if not immediate)', async () => {
|
|
60
58
|
const {
|
|
61
|
-
result
|
|
62
|
-
|
|
63
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useQueryExecutor.useQueryExecutor)({
|
|
59
|
+
result
|
|
60
|
+
} = (0, _react.renderHook)(() => (0, _useQueryExecutor.useQueryExecutor)({
|
|
64
61
|
execute,
|
|
65
62
|
immediate: false,
|
|
66
63
|
singular: true,
|
|
@@ -70,25 +67,25 @@ describe('useQueryExecutor', () => {
|
|
|
70
67
|
called: false,
|
|
71
68
|
loading: false
|
|
72
69
|
});
|
|
73
|
-
(0,
|
|
70
|
+
(0, _react.act)(() => {
|
|
74
71
|
result.current.refetch();
|
|
75
72
|
});
|
|
76
73
|
expect(result.current).toMatchObject({
|
|
77
74
|
called: true,
|
|
78
75
|
loading: true
|
|
79
76
|
});
|
|
80
|
-
await
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
await (0, _react.waitFor)(() => {
|
|
78
|
+
expect(result.current).toMatchObject({
|
|
79
|
+
called: true,
|
|
80
|
+
loading: false,
|
|
81
|
+
data: 42
|
|
82
|
+
});
|
|
85
83
|
});
|
|
86
84
|
});
|
|
87
85
|
it('Should report an error when execute fails', async () => {
|
|
88
86
|
const {
|
|
89
|
-
result
|
|
90
|
-
|
|
91
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useQueryExecutor.useQueryExecutor)({
|
|
87
|
+
result
|
|
88
|
+
} = (0, _react.renderHook)(() => (0, _useQueryExecutor.useQueryExecutor)({
|
|
92
89
|
execute: failingExecute,
|
|
93
90
|
immediate: false,
|
|
94
91
|
singular: true,
|
|
@@ -98,26 +95,26 @@ describe('useQueryExecutor', () => {
|
|
|
98
95
|
called: false,
|
|
99
96
|
loading: false
|
|
100
97
|
});
|
|
101
|
-
(0,
|
|
98
|
+
(0, _react.act)(() => {
|
|
102
99
|
result.current.refetch();
|
|
103
100
|
});
|
|
104
101
|
expect(result.current).toMatchObject({
|
|
105
102
|
called: true,
|
|
106
103
|
loading: true
|
|
107
104
|
});
|
|
108
|
-
await
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
await (0, _react.waitFor)(() => {
|
|
106
|
+
expect(result.current).toMatchObject({
|
|
107
|
+
called: true,
|
|
108
|
+
loading: false,
|
|
109
|
+
error: testError
|
|
110
|
+
});
|
|
113
111
|
});
|
|
114
112
|
});
|
|
115
113
|
it("Shouldn't abort+refetch when inputs change on subsequent renders", async () => {
|
|
116
114
|
const {
|
|
117
115
|
result,
|
|
118
|
-
waitForNextUpdate,
|
|
119
116
|
rerender
|
|
120
|
-
} = (0,
|
|
117
|
+
} = (0, _react.renderHook)(_ref2 => {
|
|
121
118
|
let {
|
|
122
119
|
onComplete
|
|
123
120
|
} = _ref2;
|
|
@@ -140,20 +137,20 @@ describe('useQueryExecutor', () => {
|
|
|
140
137
|
rerender({
|
|
141
138
|
onComplete: () => null
|
|
142
139
|
});
|
|
143
|
-
await
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
140
|
+
await (0, _react.waitFor)(() => {
|
|
141
|
+
expect(result.current).toMatchObject({
|
|
142
|
+
called: true,
|
|
143
|
+
loading: false,
|
|
144
|
+
data: 42
|
|
145
|
+
});
|
|
146
|
+
expect(theSignal && theSignal.aborted).toBe(false);
|
|
147
|
+
expect(execute).toHaveBeenCalledTimes(1);
|
|
148
148
|
});
|
|
149
|
-
expect(theSignal && theSignal.aborted).toBe(false);
|
|
150
|
-
expect(execute).toHaveBeenCalledTimes(1);
|
|
151
149
|
});
|
|
152
150
|
it('Should respect abort signal', async () => {
|
|
153
151
|
const {
|
|
154
|
-
result
|
|
155
|
-
|
|
156
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useQueryExecutor.useQueryExecutor)({
|
|
152
|
+
result
|
|
153
|
+
} = (0, _react.renderHook)(() => (0, _useQueryExecutor.useQueryExecutor)({
|
|
157
154
|
execute,
|
|
158
155
|
immediate: false,
|
|
159
156
|
singular: true,
|
|
@@ -163,14 +160,14 @@ describe('useQueryExecutor', () => {
|
|
|
163
160
|
called: false,
|
|
164
161
|
loading: false
|
|
165
162
|
});
|
|
166
|
-
(0,
|
|
163
|
+
(0, _react.act)(() => {
|
|
167
164
|
result.current.refetch();
|
|
168
165
|
});
|
|
169
166
|
expect(result.current).toMatchObject({
|
|
170
167
|
called: true,
|
|
171
168
|
loading: true
|
|
172
169
|
});
|
|
173
|
-
(0,
|
|
170
|
+
(0, _react.act)(() => {
|
|
174
171
|
result.current.abort();
|
|
175
172
|
});
|
|
176
173
|
expect(theSignal && theSignal.aborted).toBe(true);
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useStaticInput = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
const useStaticInput = function (staticValue) {
|
|
11
9
|
let {
|
|
12
10
|
warn = false,
|
|
@@ -22,5 +20,4 @@ const useStaticInput = function (staticValue) {
|
|
|
22
20
|
}, [warn, staticValue, originalValue, name]);
|
|
23
21
|
return [value, setValue];
|
|
24
22
|
};
|
|
25
|
-
|
|
26
23
|
exports.useStaticInput = useStaticInput;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
5
4
|
var _useStaticInput = require("./useStaticInput");
|
|
6
|
-
|
|
7
5
|
describe('useStaticInput', () => {
|
|
8
6
|
const originalWarn = console.warn;
|
|
9
7
|
const mockWarn = jest.fn();
|
|
@@ -15,7 +13,7 @@ describe('useStaticInput', () => {
|
|
|
15
13
|
it('Should pass without warnings on first render', () => {
|
|
16
14
|
const {
|
|
17
15
|
result
|
|
18
|
-
} = (0,
|
|
16
|
+
} = (0, _react.renderHook)(() => (0, _useStaticInput.useStaticInput)(42));
|
|
19
17
|
expect(result.current[0]).toBe(42);
|
|
20
18
|
expect(mockWarn).not.toHaveBeenCalled();
|
|
21
19
|
});
|
|
@@ -23,7 +21,7 @@ describe('useStaticInput', () => {
|
|
|
23
21
|
const {
|
|
24
22
|
result,
|
|
25
23
|
rerender
|
|
26
|
-
} = (0,
|
|
24
|
+
} = (0, _react.renderHook)(_ref => {
|
|
27
25
|
let {
|
|
28
26
|
value
|
|
29
27
|
} = _ref;
|
|
@@ -44,7 +42,7 @@ describe('useStaticInput', () => {
|
|
|
44
42
|
const {
|
|
45
43
|
result,
|
|
46
44
|
rerender
|
|
47
|
-
} = (0,
|
|
45
|
+
} = (0, _react.renderHook)(_ref2 => {
|
|
48
46
|
let {
|
|
49
47
|
value
|
|
50
48
|
} = _ref2;
|
|
@@ -72,7 +70,7 @@ describe('useStaticInput', () => {
|
|
|
72
70
|
const {
|
|
73
71
|
result,
|
|
74
72
|
rerender
|
|
75
|
-
} = (0,
|
|
73
|
+
} = (0, _react.renderHook)(_ref3 => {
|
|
76
74
|
let {
|
|
77
75
|
value
|
|
78
76
|
} = _ref3;
|
|
@@ -97,7 +95,7 @@ describe('useStaticInput', () => {
|
|
|
97
95
|
const {
|
|
98
96
|
result,
|
|
99
97
|
rerender
|
|
100
|
-
} = (0,
|
|
98
|
+
} = (0, _react.renderHook)(_ref4 => {
|
|
101
99
|
let {
|
|
102
100
|
value
|
|
103
101
|
} = _ref4;
|
|
@@ -111,7 +109,7 @@ describe('useStaticInput', () => {
|
|
|
111
109
|
});
|
|
112
110
|
const [value, setValue] = result.current;
|
|
113
111
|
expect(value).toBe(42);
|
|
114
|
-
(0,
|
|
112
|
+
(0, _react.act)(() => {
|
|
115
113
|
setValue(54);
|
|
116
114
|
});
|
|
117
115
|
expect(result.current[0]).toBe(54);
|
|
@@ -133,7 +131,7 @@ describe('useStaticInput', () => {
|
|
|
133
131
|
const {
|
|
134
132
|
result,
|
|
135
133
|
rerender
|
|
136
|
-
} = (0,
|
|
134
|
+
} = (0, _react.renderHook)(_ref5 => {
|
|
137
135
|
let {
|
|
138
136
|
value
|
|
139
137
|
} = _ref5;
|
package/build/cjs/react/index.js
CHANGED
|
@@ -69,25 +69,14 @@ Object.defineProperty(exports, "useStaticInput", {
|
|
|
69
69
|
return _useStaticInput.useStaticInput;
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
|
-
|
|
73
72
|
var _CustomDataProvider = require("./components/CustomDataProvider");
|
|
74
|
-
|
|
75
73
|
var _DataMutation = require("./components/DataMutation");
|
|
76
|
-
|
|
77
74
|
var _DataProvider = require("./components/DataProvider");
|
|
78
|
-
|
|
79
75
|
var _DataQuery = require("./components/DataQuery");
|
|
80
|
-
|
|
81
76
|
var _DataContext = require("./context/DataContext");
|
|
82
|
-
|
|
83
77
|
var _defaultContext = require("./context/defaultContext");
|
|
84
|
-
|
|
85
78
|
var _useDataEngine = require("./hooks/useDataEngine");
|
|
86
|
-
|
|
87
79
|
var _useDataMutation = require("./hooks/useDataMutation");
|
|
88
|
-
|
|
89
80
|
var _useDataQuery = require("./hooks/useDataQuery");
|
|
90
|
-
|
|
91
81
|
var _useQueryExecutor = require("./hooks/useQueryExecutor");
|
|
92
|
-
|
|
93
82
|
var _useStaticInput = require("./hooks/useStaticInput");
|
package/build/cjs/setupRTL.js
CHANGED
|
@@ -6,8 +6,7 @@ describe('<DataQuery />', () => {
|
|
|
6
6
|
const data = {
|
|
7
7
|
answer: 42
|
|
8
8
|
};
|
|
9
|
-
|
|
10
|
-
const wrapper = (_ref) => {
|
|
9
|
+
const wrapper = _ref => {
|
|
11
10
|
let {
|
|
12
11
|
children
|
|
13
12
|
} = _ref;
|
|
@@ -15,9 +14,8 @@ describe('<DataQuery />', () => {
|
|
|
15
14
|
data: data
|
|
16
15
|
}, children);
|
|
17
16
|
};
|
|
18
|
-
|
|
19
17
|
const renderFunction = jest.fn(() => null);
|
|
20
|
-
render(
|
|
18
|
+
render(/*#__PURE__*/React.createElement(DataQuery, {
|
|
21
19
|
query: {
|
|
22
20
|
answer: {
|
|
23
21
|
resource: 'answer'
|
|
@@ -47,8 +45,7 @@ describe('<DataQuery />', () => {
|
|
|
47
45
|
throw expectedError;
|
|
48
46
|
}
|
|
49
47
|
};
|
|
50
|
-
|
|
51
|
-
const wrapper = (_ref2) => {
|
|
48
|
+
const wrapper = _ref2 => {
|
|
52
49
|
let {
|
|
53
50
|
children
|
|
54
51
|
} = _ref2;
|
|
@@ -56,9 +53,8 @@ describe('<DataQuery />', () => {
|
|
|
56
53
|
data: data
|
|
57
54
|
}, children);
|
|
58
55
|
};
|
|
59
|
-
|
|
60
56
|
const renderFunction = jest.fn(() => null);
|
|
61
|
-
render(
|
|
57
|
+
render(/*#__PURE__*/React.createElement(DataQuery, {
|
|
62
58
|
query: {
|
|
63
59
|
test: {
|
|
64
60
|
resource: 'test'
|
|
@@ -14,8 +14,7 @@ describe('<DataMutation />', () => {
|
|
|
14
14
|
const data = {
|
|
15
15
|
answer: endpointSpy
|
|
16
16
|
};
|
|
17
|
-
|
|
18
|
-
const wrapper = (_ref) => {
|
|
17
|
+
const wrapper = _ref => {
|
|
19
18
|
let {
|
|
20
19
|
children
|
|
21
20
|
} = _ref;
|
|
@@ -23,9 +22,8 @@ describe('<DataMutation />', () => {
|
|
|
23
22
|
data: data
|
|
24
23
|
}, children);
|
|
25
24
|
};
|
|
26
|
-
|
|
27
25
|
const renderSpy = jest.fn(() => null);
|
|
28
|
-
render(
|
|
26
|
+
render(/*#__PURE__*/React.createElement(DataMutation, {
|
|
29
27
|
mutation: mutation
|
|
30
28
|
}, renderSpy), {
|
|
31
29
|
wrapper
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
function _defineProperty(
|
|
2
|
-
|
|
1
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
2
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
3
4
|
import { getMutationFetchType } from './helpers/getMutationFetchType';
|
|
4
5
|
import { resolveDynamicQuery } from './helpers/resolveDynamicQuery';
|
|
5
6
|
import { validateResourceQuery, validateResourceQueries } from './helpers/validate';
|
|
6
|
-
|
|
7
7
|
const reduceResponses = (responses, names) => responses.reduce((out, response, idx) => {
|
|
8
8
|
out[names[idx]] = response;
|
|
9
9
|
return out;
|
|
10
10
|
}, {});
|
|
11
|
-
|
|
12
11
|
export class DataEngine {
|
|
13
12
|
constructor(link) {
|
|
14
13
|
_defineProperty(this, "link", void 0);
|
|
15
|
-
|
|
16
14
|
this.link = link;
|
|
17
15
|
}
|
|
18
|
-
|
|
19
16
|
query(query) {
|
|
20
17
|
let {
|
|
21
18
|
variables = {},
|
|
@@ -39,7 +36,6 @@ export class DataEngine {
|
|
|
39
36
|
throw error;
|
|
40
37
|
});
|
|
41
38
|
}
|
|
42
|
-
|
|
43
39
|
mutate(mutation) {
|
|
44
40
|
let {
|
|
45
41
|
variables = {},
|
|
@@ -61,6 +57,5 @@ export class DataEngine {
|
|
|
61
57
|
throw error;
|
|
62
58
|
});
|
|
63
59
|
}
|
|
64
|
-
|
|
65
60
|
}
|
|
66
61
|
export default DataEngine;
|
|
@@ -17,13 +17,13 @@ describe('resolveDynamicQuery', () => {
|
|
|
17
17
|
it('Should replace variables in all dynamic properties', () => {
|
|
18
18
|
const query = {
|
|
19
19
|
resource: 'test',
|
|
20
|
-
id:
|
|
20
|
+
id: _ref => {
|
|
21
21
|
let {
|
|
22
22
|
id
|
|
23
23
|
} = _ref;
|
|
24
24
|
return id;
|
|
25
25
|
},
|
|
26
|
-
params:
|
|
26
|
+
params: _ref2 => {
|
|
27
27
|
let {
|
|
28
28
|
page
|
|
29
29
|
} = _ref2;
|
|
@@ -32,7 +32,7 @@ describe('resolveDynamicQuery', () => {
|
|
|
32
32
|
foo: 'bar'
|
|
33
33
|
};
|
|
34
34
|
},
|
|
35
|
-
data:
|
|
35
|
+
data: _ref3 => {
|
|
36
36
|
let {
|
|
37
37
|
bar
|
|
38
38
|
} = _ref3;
|
|
@@ -5,37 +5,28 @@ export const getResourceQueryErrors = (type, query) => {
|
|
|
5
5
|
if (!validTypes.includes(type)) {
|
|
6
6
|
return [`Unknown query or mutation type ${type}`];
|
|
7
7
|
}
|
|
8
|
-
|
|
9
8
|
if (typeof query !== 'object') {
|
|
10
9
|
return ['A query or mutation must be a javascript object'];
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
const errors = [];
|
|
14
|
-
|
|
15
12
|
if (!query.resource || typeof query.resource !== 'string') {
|
|
16
13
|
errors.push('Property resource must be a string');
|
|
17
14
|
}
|
|
18
|
-
|
|
19
15
|
if (type === 'create' && query.id) {
|
|
20
16
|
errors.push("Mutation type 'create' does not support property 'id'");
|
|
21
17
|
}
|
|
22
|
-
|
|
23
18
|
if (query.id && typeof query.id !== 'string') {
|
|
24
19
|
errors.push('Property id must be a string');
|
|
25
20
|
}
|
|
26
|
-
|
|
27
21
|
if (query.params && typeof query.params !== 'object') {
|
|
28
22
|
errors.push('Property params must be an object');
|
|
29
23
|
}
|
|
30
|
-
|
|
31
24
|
if (type === 'delete' && query.data) {
|
|
32
25
|
errors.push("Mutation type 'delete' does not support property 'data'");
|
|
33
26
|
}
|
|
34
|
-
|
|
35
27
|
if (type === 'json-patch' && !Array.isArray(query.data)) {
|
|
36
28
|
errors.push("Mutation type 'json-patch' requires property 'data' to be of type Array");
|
|
37
29
|
}
|
|
38
|
-
|
|
39
30
|
const invalidKeys = Object.keys(query).filter(k => !validQueryKeys.includes(k));
|
|
40
31
|
invalidKeys.forEach(k => {
|
|
41
32
|
errors.push(`Property ${k} is not supported`);
|
|
@@ -44,22 +35,18 @@ export const getResourceQueryErrors = (type, query) => {
|
|
|
44
35
|
};
|
|
45
36
|
export const validateResourceQueries = function (queries) {
|
|
46
37
|
let names = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
47
|
-
|
|
48
38
|
if (names.length !== queries.length) {
|
|
49
39
|
for (let i = names.length; i < queries.length; ++i) {
|
|
50
40
|
names.push('query#' + i);
|
|
51
41
|
}
|
|
52
42
|
}
|
|
53
|
-
|
|
54
43
|
const errors = queries.reduce((errors, query, i) => errors.concat(getResourceQueryErrors('read', query).map(e => `[${names[i]}] ${e}`)), []);
|
|
55
|
-
|
|
56
44
|
if (errors.length) {
|
|
57
45
|
throw new InvalidQueryError(errors);
|
|
58
46
|
}
|
|
59
47
|
};
|
|
60
48
|
export const validateResourceQuery = (type, query) => {
|
|
61
49
|
const errors = getResourceQueryErrors(type, query);
|
|
62
|
-
|
|
63
50
|
if (errors.length) {
|
|
64
51
|
throw new InvalidQueryError(errors);
|
|
65
52
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
function _defineProperty(
|
|
2
|
-
|
|
1
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
2
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
3
4
|
export class FetchError extends Error {
|
|
4
5
|
constructor(_ref) {
|
|
5
6
|
let {
|
|
@@ -8,13 +9,9 @@ export class FetchError extends Error {
|
|
|
8
9
|
details = {}
|
|
9
10
|
} = _ref;
|
|
10
11
|
super(message);
|
|
11
|
-
|
|
12
12
|
_defineProperty(this, "type", void 0);
|
|
13
|
-
|
|
14
13
|
_defineProperty(this, "details", void 0);
|
|
15
|
-
|
|
16
14
|
this.type = type;
|
|
17
15
|
this.details = details;
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
function _defineProperty(
|
|
2
|
-
|
|
1
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
2
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
3
4
|
export class InvalidQueryError extends Error {
|
|
4
5
|
constructor(errors) {
|
|
5
6
|
super(`Invalid query\n${errors.map(e => ' - ' + e).join('\n')}`);
|
|
6
|
-
|
|
7
7
|
_defineProperty(this, "type", 'invalid-query');
|
|
8
|
-
|
|
9
8
|
_defineProperty(this, "details", void 0);
|
|
10
|
-
|
|
11
9
|
this.details = errors;
|
|
12
10
|
}
|
|
13
|
-
|
|
14
11
|
}
|
|
@@ -1,56 +1,44 @@
|
|
|
1
|
-
function _defineProperty(
|
|
2
|
-
|
|
1
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
2
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
3
4
|
export class CustomDataLink {
|
|
4
5
|
constructor(customData) {
|
|
5
6
|
let {
|
|
6
7
|
failOnMiss = true,
|
|
7
8
|
loadForever = false
|
|
8
9
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
9
|
-
|
|
10
10
|
_defineProperty(this, "failOnMiss", void 0);
|
|
11
|
-
|
|
12
11
|
_defineProperty(this, "loadForever", void 0);
|
|
13
|
-
|
|
14
12
|
_defineProperty(this, "data", void 0);
|
|
15
|
-
|
|
16
13
|
this.data = customData;
|
|
17
14
|
this.failOnMiss = failOnMiss;
|
|
18
15
|
this.loadForever = loadForever;
|
|
19
16
|
}
|
|
20
|
-
|
|
21
17
|
async executeResourceQuery(type, query, options) {
|
|
22
18
|
if (this.loadForever) {
|
|
23
19
|
return new Promise(() => undefined);
|
|
24
20
|
}
|
|
25
|
-
|
|
26
21
|
const customResource = this.data[query.resource];
|
|
27
|
-
|
|
28
22
|
if (customResource === undefined) {
|
|
29
23
|
if (this.failOnMiss) {
|
|
30
24
|
throw new Error(`No data provided for resource type ${query.resource}!`);
|
|
31
25
|
}
|
|
32
|
-
|
|
33
26
|
return Promise.resolve(null);
|
|
34
27
|
}
|
|
35
|
-
|
|
36
28
|
switch (typeof customResource) {
|
|
37
29
|
case 'string':
|
|
38
30
|
case 'number':
|
|
39
31
|
case 'boolean':
|
|
40
32
|
case 'object':
|
|
41
33
|
return customResource;
|
|
42
|
-
|
|
43
34
|
case 'function':
|
|
44
35
|
{
|
|
45
36
|
const result = await customResource(type, query, options);
|
|
46
|
-
|
|
47
37
|
if (typeof result === 'undefined' && this.failOnMiss) {
|
|
48
38
|
throw new Error(`The custom function for resource ${query.resource} must always return a value but returned ${result}`);
|
|
49
39
|
}
|
|
50
|
-
|
|
51
40
|
return result || null;
|
|
52
41
|
}
|
|
53
42
|
}
|
|
54
43
|
}
|
|
55
|
-
|
|
56
44
|
}
|