@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
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _RestAPILink = require("../RestAPILink");
|
|
4
|
-
var _queryToResourcePath = require("./queryToResourcePath");
|
|
5
|
-
const createLink = config => new _RestAPILink.RestAPILink(config);
|
|
6
|
-
const defaultConfig = {
|
|
7
|
-
basePath: '<base>',
|
|
8
|
-
apiVersion: '37',
|
|
9
|
-
serverVersion: {
|
|
10
|
-
major: 2,
|
|
11
|
-
minor: 37,
|
|
12
|
-
patch: 11
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
const link = createLink(defaultConfig);
|
|
16
|
-
const apiPath = link.versionedApiPath;
|
|
17
|
-
const actionPrefix = `dhis-web-commons/`;
|
|
18
|
-
const actionPostfix = '.action';
|
|
19
|
-
describe('queryToResourcePath', () => {
|
|
20
|
-
describe('action', () => {
|
|
21
|
-
it('should return action URL with no querystring if not query parameters are passed', () => {
|
|
22
|
-
const query = {
|
|
23
|
-
resource: 'action::test'
|
|
24
|
-
};
|
|
25
|
-
expect((0, _queryToResourcePath.queryToResourcePath)(link, query, 'read')).toBe(`${actionPrefix}test${actionPostfix}`);
|
|
26
|
-
});
|
|
27
|
-
it('should return action URL with a simple querystring if query parameters are passed', () => {
|
|
28
|
-
const query = {
|
|
29
|
-
resource: 'action::test',
|
|
30
|
-
params: {
|
|
31
|
-
key: 'value'
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
expect((0, _queryToResourcePath.queryToResourcePath)(link, query, 'read')).toBe(`${actionPrefix}test${actionPostfix}?key=value`);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
describe('resource with dot', () => {
|
|
38
|
-
it('should leave dots in resources', () => {
|
|
39
|
-
const query = {
|
|
40
|
-
resource: 'svg.pdf'
|
|
41
|
-
};
|
|
42
|
-
expect((0, _queryToResourcePath.queryToResourcePath)(link, query, 'read')).toBe(`${apiPath}/svg.pdf`);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
it('should return resource url with no querystring if not query parameters are passed', () => {
|
|
46
|
-
const query = {
|
|
47
|
-
resource: 'test'
|
|
48
|
-
};
|
|
49
|
-
expect((0, _queryToResourcePath.queryToResourcePath)(link, query, 'read')).toBe(`${apiPath}/test`);
|
|
50
|
-
});
|
|
51
|
-
it('should return resource url and singular parameter separated by ?', () => {
|
|
52
|
-
const query = {
|
|
53
|
-
resource: 'test',
|
|
54
|
-
params: {
|
|
55
|
-
key: 'value'
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
expect((0, _queryToResourcePath.queryToResourcePath)(link, query, 'read')).toBe(`${apiPath}/test?key=value`);
|
|
59
|
-
});
|
|
60
|
-
it('should return resource url and multiple parameters separated by ? and &', () => {
|
|
61
|
-
const query = {
|
|
62
|
-
resource: 'test',
|
|
63
|
-
params: {
|
|
64
|
-
key: 'value',
|
|
65
|
-
param: 'value2'
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
expect((0, _queryToResourcePath.queryToResourcePath)(link, query, 'read')).toBe(`${apiPath}/test?key=value¶m=value2`);
|
|
69
|
-
});
|
|
70
|
-
it('should url encode special characters in query keys', () => {
|
|
71
|
-
const query = {
|
|
72
|
-
resource: 'test',
|
|
73
|
-
params: {
|
|
74
|
-
'key=42&val': 'value'
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
expect((0, _queryToResourcePath.queryToResourcePath)(link, query, 'read')).toBe(`${apiPath}/test?key%3D42%26val=value`);
|
|
78
|
-
});
|
|
79
|
-
it('should url encode special characters in string parameters', () => {
|
|
80
|
-
const query = {
|
|
81
|
-
resource: 'test',
|
|
82
|
-
params: {
|
|
83
|
-
key: 'value?=42',
|
|
84
|
-
param: 'value2&& 53'
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
expect((0, _queryToResourcePath.queryToResourcePath)(link, query, 'read')).toBe(`${apiPath}/test?key=value%3F%3D42¶m=value2%26%26%2053`);
|
|
88
|
-
});
|
|
89
|
-
it('should support numeric (integer and float) parameters', () => {
|
|
90
|
-
const query = {
|
|
91
|
-
resource: 'test',
|
|
92
|
-
params: {
|
|
93
|
-
key: 42,
|
|
94
|
-
param: 193.75
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
expect((0, _queryToResourcePath.queryToResourcePath)(link, query, 'read')).toBe(`${apiPath}/test?key=42¶m=193.75`);
|
|
98
|
-
});
|
|
99
|
-
it('should support boolean parameters', () => {
|
|
100
|
-
const query = {
|
|
101
|
-
resource: 'test',
|
|
102
|
-
params: {
|
|
103
|
-
key: 42,
|
|
104
|
-
someflag: true
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
expect((0, _queryToResourcePath.queryToResourcePath)(link, query, 'read')).toBe(`${apiPath}/test?key=42&someflag=true`);
|
|
108
|
-
});
|
|
109
|
-
it('should join array parameters with commas', () => {
|
|
110
|
-
const query = {
|
|
111
|
-
resource: 'test',
|
|
112
|
-
params: {
|
|
113
|
-
key: ['asdf', 123]
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
expect((0, _queryToResourcePath.queryToResourcePath)(link, query, 'read')).toBe(`${apiPath}/test?key=asdf,123`);
|
|
117
|
-
});
|
|
118
|
-
it('should include multiple filter parameters when array of filters provided', () => {
|
|
119
|
-
const query = {
|
|
120
|
-
resource: 'test',
|
|
121
|
-
params: {
|
|
122
|
-
filter: ['asdf', 123]
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
expect((0, _queryToResourcePath.queryToResourcePath)(link, query, 'read')).toBe(`${apiPath}/test?filter=asdf&filter=123`);
|
|
126
|
-
});
|
|
127
|
-
it('should NOT YET support name-aliased parameters', () => {
|
|
128
|
-
const query = {
|
|
129
|
-
resource: 'test',
|
|
130
|
-
params: {
|
|
131
|
-
key: {
|
|
132
|
-
asdf: 'fdsa'
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
expect(() => (0, _queryToResourcePath.queryToResourcePath)(link, query, 'read')).toThrow();
|
|
137
|
-
});
|
|
138
|
-
it('should throw if passed something crazy like a function', () => {
|
|
139
|
-
const query = {
|
|
140
|
-
resource: 'test',
|
|
141
|
-
params: {
|
|
142
|
-
key: a => a
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
expect(() => (0, _queryToResourcePath.queryToResourcePath)(link, query, 'read')).toThrow();
|
|
146
|
-
});
|
|
147
|
-
it('should return an unversioned endpoint for the new tracker importer (in version 2.37)', () => {
|
|
148
|
-
const query = {
|
|
149
|
-
resource: 'tracker'
|
|
150
|
-
};
|
|
151
|
-
expect((0, _queryToResourcePath.queryToResourcePath)(link, query, 'read')).toBe(`${link.unversionedApiPath}/tracker`);
|
|
152
|
-
});
|
|
153
|
-
it('should return an unversioned endpoint sub-resources of the new tracker importer (in version 2.37)', () => {
|
|
154
|
-
const query = {
|
|
155
|
-
resource: 'tracker/test'
|
|
156
|
-
};
|
|
157
|
-
expect((0, _queryToResourcePath.queryToResourcePath)(link, query, 'read')).toBe(`${link.unversionedApiPath}/tracker/test`);
|
|
158
|
-
});
|
|
159
|
-
it('should return a VERSIONED endpoint for the new tracker importer (in version 2.38)', () => {
|
|
160
|
-
const query = {
|
|
161
|
-
resource: 'tracker'
|
|
162
|
-
};
|
|
163
|
-
const v38config = {
|
|
164
|
-
...defaultConfig,
|
|
165
|
-
serverVersion: {
|
|
166
|
-
major: 2,
|
|
167
|
-
minor: 38,
|
|
168
|
-
patch: 0
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
expect((0, _queryToResourcePath.queryToResourcePath)(createLink(v38config), query, 'read')).toBe(`${link.versionedApiPath}/tracker`);
|
|
172
|
-
});
|
|
173
|
-
});
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.validateResourceQuery = void 0;
|
|
7
|
-
var _metadataResources = require("./metadataResources");
|
|
8
|
-
const validatePagination = (query, warn) => {
|
|
9
|
-
var _query$params, _query$params2;
|
|
10
|
-
if (!_metadataResources.normativeMetadataResources.includes(query.resource)) {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
if (((_query$params = query.params) === null || _query$params === void 0 ? void 0 : _query$params.paging) === false || ((_query$params2 = query.params) === null || _query$params2 === void 0 ? void 0 : _query$params2.paging) === 'false') {
|
|
14
|
-
warn('Data queries with paging=false are deprecated and should not be used!', query);
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// TODO: validate sub-resource pagination (i.e. fields=users~paging(1,50)[name] )
|
|
19
|
-
|
|
20
|
-
return true;
|
|
21
|
-
};
|
|
22
|
-
const validateDeclarativeFields = (query, warn) => {
|
|
23
|
-
var _query$params3;
|
|
24
|
-
if (!_metadataResources.normativeMetadataResources.includes(query.resource)) {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
if (!((_query$params3 = query.params) !== null && _query$params3 !== void 0 && _query$params3.fields)) {
|
|
28
|
-
warn('Data queries should always specify fields to return', query);
|
|
29
|
-
return false;
|
|
30
|
-
} else {
|
|
31
|
-
var _fields;
|
|
32
|
-
let fields = undefined;
|
|
33
|
-
if (typeof query.params.fields === 'string') {
|
|
34
|
-
fields = query.params.fields.split(',').map(field => field.trim());
|
|
35
|
-
} else if (Array.isArray(query.params.fields)) {
|
|
36
|
-
fields = query.params.fields.map(field => String(field).trim());
|
|
37
|
-
}
|
|
38
|
-
if ((_fields = fields) !== null && _fields !== void 0 && _fields.find(field => field.match(/(^\*$|^:.+)/))) {
|
|
39
|
-
warn('Data queries should not use wildcard or dynamic field groups', query.params.fields, query);
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// TODO: validate sub-resource wildcard fields (i.e. fields=users[*])
|
|
45
|
-
return true;
|
|
46
|
-
};
|
|
47
|
-
const validateResourceQuery = (query, type) => {
|
|
48
|
-
let valid = true;
|
|
49
|
-
if (process.env.NODE_ENV === 'development') {
|
|
50
|
-
// Support build-time dead code elimination in production
|
|
51
|
-
const warn = console.warn;
|
|
52
|
-
if (type === 'read') {
|
|
53
|
-
valid = validatePagination(query, warn) && valid;
|
|
54
|
-
valid = validateDeclarativeFields(query, warn) && valid;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return valid;
|
|
58
|
-
};
|
|
59
|
-
exports.validateResourceQuery = validateResourceQuery;
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _validateQuery = require("./validateQuery");
|
|
4
|
-
describe('validateQuery', () => {
|
|
5
|
-
const originalConsoleWarn = console.warn;
|
|
6
|
-
afterAll(() => {
|
|
7
|
-
console.warn = originalConsoleWarn;
|
|
8
|
-
});
|
|
9
|
-
it('Should return true and NOT console.warn for a valid query', () => {
|
|
10
|
-
const warn = console.warn = jest.fn();
|
|
11
|
-
process.env.NODE_ENV = 'development';
|
|
12
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
13
|
-
resource: 'indicators',
|
|
14
|
-
params: {
|
|
15
|
-
fields: 'name'
|
|
16
|
-
}
|
|
17
|
-
}, 'read')).toBe(true);
|
|
18
|
-
expect(console.warn).not.toHaveBeenCalled();
|
|
19
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
20
|
-
resource: 'users',
|
|
21
|
-
params: {
|
|
22
|
-
fields: ['name', 'id'],
|
|
23
|
-
pageSize: 35,
|
|
24
|
-
page: 2
|
|
25
|
-
}
|
|
26
|
-
}, 'read')).toBe(true);
|
|
27
|
-
expect(console.warn).not.toHaveBeenCalled();
|
|
28
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
29
|
-
resource: 'userGroups',
|
|
30
|
-
params: {
|
|
31
|
-
fields: ['name', 'shortName'],
|
|
32
|
-
paging: true,
|
|
33
|
-
pageSize: 20
|
|
34
|
-
}
|
|
35
|
-
}, 'read')).toBe(true);
|
|
36
|
-
expect(console.warn).not.toHaveBeenCalled();
|
|
37
|
-
});
|
|
38
|
-
it('Should return true for mutations', () => {
|
|
39
|
-
const warn = console.warn = jest.fn();
|
|
40
|
-
process.env.NODE_ENV = 'development';
|
|
41
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
42
|
-
resource: 'trackedEntityInstances',
|
|
43
|
-
params: {
|
|
44
|
-
paging: false
|
|
45
|
-
}
|
|
46
|
-
}, 'create')).toBe(true);
|
|
47
|
-
expect(console.warn).not.toHaveBeenCalled();
|
|
48
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
49
|
-
resource: 'visualizations'
|
|
50
|
-
}, 'update')).toBe(true);
|
|
51
|
-
expect(console.warn).not.toHaveBeenCalled();
|
|
52
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
53
|
-
resource: 'maps'
|
|
54
|
-
}, 'delete')).toBe(true);
|
|
55
|
-
expect(console.warn).not.toHaveBeenCalled();
|
|
56
|
-
});
|
|
57
|
-
it('Should skip validation for non-normative and non-metadata resources', () => {
|
|
58
|
-
const warn = console.warn = jest.fn();
|
|
59
|
-
process.env.NODE_ENV = 'development';
|
|
60
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
61
|
-
resource: 'analytics',
|
|
62
|
-
params: {
|
|
63
|
-
fields: ['*']
|
|
64
|
-
}
|
|
65
|
-
}, 'read')).toBe(true);
|
|
66
|
-
expect(console.warn).not.toHaveBeenCalled();
|
|
67
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
68
|
-
resource: 'dataStore',
|
|
69
|
-
params: {
|
|
70
|
-
fields: ['*']
|
|
71
|
-
}
|
|
72
|
-
}, 'read')).toBe(true);
|
|
73
|
-
expect(console.warn).not.toHaveBeenCalled();
|
|
74
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
75
|
-
resource: 'icons',
|
|
76
|
-
params: {
|
|
77
|
-
fields: ['*']
|
|
78
|
-
}
|
|
79
|
-
}, 'read')).toBe(true);
|
|
80
|
-
expect(console.warn).not.toHaveBeenCalled();
|
|
81
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
82
|
-
resource: 'apps',
|
|
83
|
-
params: {
|
|
84
|
-
fields: ['*']
|
|
85
|
-
}
|
|
86
|
-
}, 'read')).toBe(true);
|
|
87
|
-
expect(console.warn).not.toHaveBeenCalled();
|
|
88
|
-
process.env.NODE_ENV = 'test';
|
|
89
|
-
});
|
|
90
|
-
it('Should return true and not warn in production mode', () => {
|
|
91
|
-
console.warn = jest.fn();
|
|
92
|
-
process.env.NODE_ENV = 'production';
|
|
93
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
94
|
-
resource: 'programTrackedEntityAttributeGroups',
|
|
95
|
-
params: {
|
|
96
|
-
fields: ['*']
|
|
97
|
-
}
|
|
98
|
-
}, 'read')).toBe(true);
|
|
99
|
-
expect(console.warn).not.toHaveBeenCalled();
|
|
100
|
-
process.env.NODE_ENV = 'test';
|
|
101
|
-
});
|
|
102
|
-
it('Should return false and warn in development mode', () => {
|
|
103
|
-
const warn = console.warn = jest.fn();
|
|
104
|
-
process.env.NODE_ENV = 'development';
|
|
105
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
106
|
-
resource: 'dataElements',
|
|
107
|
-
params: {
|
|
108
|
-
fields: ['*']
|
|
109
|
-
}
|
|
110
|
-
}, 'read')).toBe(false);
|
|
111
|
-
expect(warn).toHaveBeenCalledTimes(1);
|
|
112
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries should not use wildcard or dynamic field groups"`);
|
|
113
|
-
process.env.NODE_ENV = 'test';
|
|
114
|
-
});
|
|
115
|
-
it('Should detect missing fields', () => {
|
|
116
|
-
const warn = console.warn = jest.fn();
|
|
117
|
-
process.env.NODE_ENV = 'development';
|
|
118
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
119
|
-
resource: 'mapViews'
|
|
120
|
-
}, 'read')).toBe(false);
|
|
121
|
-
expect(warn).toHaveBeenCalledTimes(1);
|
|
122
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries should always specify fields to return"`);
|
|
123
|
-
process.env.NODE_ENV = 'test';
|
|
124
|
-
});
|
|
125
|
-
it('Should detect paging false', () => {
|
|
126
|
-
const warn = console.warn = jest.fn();
|
|
127
|
-
process.env.NODE_ENV = 'development';
|
|
128
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
129
|
-
resource: 'attributes',
|
|
130
|
-
params: {
|
|
131
|
-
fields: ['name'],
|
|
132
|
-
paging: false
|
|
133
|
-
}
|
|
134
|
-
}, 'read')).toBe(false);
|
|
135
|
-
expect(warn).toHaveBeenCalledTimes(1);
|
|
136
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries with paging=false are deprecated and should not be used!"`);
|
|
137
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
138
|
-
resource: 'optionSets',
|
|
139
|
-
params: {
|
|
140
|
-
fields: ['name'],
|
|
141
|
-
paging: 'false'
|
|
142
|
-
}
|
|
143
|
-
}, 'read')).toBe(false);
|
|
144
|
-
expect(warn).toHaveBeenCalledTimes(1);
|
|
145
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries with paging=false are deprecated and should not be used!"`);
|
|
146
|
-
process.env.NODE_ENV = 'test';
|
|
147
|
-
});
|
|
148
|
-
it('Should detect wildcard fields', () => {
|
|
149
|
-
const warn = console.warn = jest.fn();
|
|
150
|
-
process.env.NODE_ENV = 'development';
|
|
151
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
152
|
-
resource: 'categoryOptionCombos',
|
|
153
|
-
params: {
|
|
154
|
-
fields: ['*']
|
|
155
|
-
}
|
|
156
|
-
}, 'read')).toBe(false);
|
|
157
|
-
expect(warn).toHaveBeenCalledTimes(1);
|
|
158
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries should not use wildcard or dynamic field groups"`);
|
|
159
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
160
|
-
resource: 'organisationUnits',
|
|
161
|
-
params: {
|
|
162
|
-
fields: 'test, :all, something'
|
|
163
|
-
}
|
|
164
|
-
}, 'read')).toBe(false);
|
|
165
|
-
expect(warn).toHaveBeenCalledTimes(1);
|
|
166
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries should not use wildcard or dynamic field groups"`);
|
|
167
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
168
|
-
resource: 'organisationUnitGroups',
|
|
169
|
-
params: {
|
|
170
|
-
fields: ['asdf', ':owner']
|
|
171
|
-
}
|
|
172
|
-
}, 'read')).toBe(false);
|
|
173
|
-
expect(warn).toHaveBeenCalledTimes(1);
|
|
174
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries should not use wildcard or dynamic field groups"`);
|
|
175
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
176
|
-
resource: 'dashboards',
|
|
177
|
-
params: {
|
|
178
|
-
fields: ['*', ':owner', ':all']
|
|
179
|
-
}
|
|
180
|
-
}, 'read')).toBe(false);
|
|
181
|
-
expect(warn).toHaveBeenCalledTimes(1);
|
|
182
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries should not use wildcard or dynamic field groups"`);
|
|
183
|
-
process.env.NODE_ENV = 'test';
|
|
184
|
-
});
|
|
185
|
-
it('Should warn for multiple errors in one query', () => {
|
|
186
|
-
const warn = console.warn = jest.fn();
|
|
187
|
-
process.env.NODE_ENV = 'development';
|
|
188
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
189
|
-
resource: 'dataSets',
|
|
190
|
-
params: {
|
|
191
|
-
fields: ['*'],
|
|
192
|
-
paging: false
|
|
193
|
-
}
|
|
194
|
-
}, 'read')).toBe(false);
|
|
195
|
-
expect(warn).toHaveBeenCalledTimes(2);
|
|
196
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries with paging=false are deprecated and should not be used!"`);
|
|
197
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries should not use wildcard or dynamic field groups"`);
|
|
198
|
-
expect((0, _validateQuery.validateResourceQuery)({
|
|
199
|
-
resource: 'dashboardItems',
|
|
200
|
-
params: {
|
|
201
|
-
paging: false
|
|
202
|
-
}
|
|
203
|
-
}, 'read')).toBe(false);
|
|
204
|
-
expect(warn).toHaveBeenCalledTimes(2);
|
|
205
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries with paging=false are deprecated and should not be used!"`);
|
|
206
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries should always specify fields to return"`);
|
|
207
|
-
process.env.NODE_ENV = 'test';
|
|
208
|
-
});
|
|
209
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.RestAPILink = void 0;
|
|
7
|
-
var _fetchData = require("./RestAPILink/fetchData");
|
|
8
|
-
var _path = require("./RestAPILink/path");
|
|
9
|
-
var _queryToRequestOptions = require("./RestAPILink/queryToRequestOptions");
|
|
10
|
-
var _queryToResourcePath = require("./RestAPILink/queryToResourcePath");
|
|
11
|
-
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; }
|
|
12
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
13
|
-
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); }
|
|
14
|
-
class RestAPILink {
|
|
15
|
-
constructor(config) {
|
|
16
|
-
_defineProperty(this, "config", void 0);
|
|
17
|
-
_defineProperty(this, "versionedApiPath", void 0);
|
|
18
|
-
_defineProperty(this, "unversionedApiPath", void 0);
|
|
19
|
-
this.config = config;
|
|
20
|
-
this.versionedApiPath = (0, _path.joinPath)('api', String(config.apiVersion));
|
|
21
|
-
this.unversionedApiPath = (0, _path.joinPath)('api');
|
|
22
|
-
}
|
|
23
|
-
fetch(path, options) {
|
|
24
|
-
return (0, _fetchData.fetchData)((0, _path.joinPath)(this.config.baseUrl, path), options);
|
|
25
|
-
}
|
|
26
|
-
executeResourceQuery(type, query, _ref) {
|
|
27
|
-
let {
|
|
28
|
-
signal
|
|
29
|
-
} = _ref;
|
|
30
|
-
return this.fetch((0, _queryToResourcePath.queryToResourcePath)(this, query, type), (0, _queryToRequestOptions.queryToRequestOptions)(type, query, signal));
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.RestAPILink = RestAPILink;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _fetchData = require("./RestAPILink/fetchData");
|
|
4
|
-
var _ = require(".");
|
|
5
|
-
jest.mock('./RestAPILink/fetchData', () => ({
|
|
6
|
-
fetchData: jest.fn(async () => null)
|
|
7
|
-
}));
|
|
8
|
-
describe('RestAPILink', () => {
|
|
9
|
-
it('should call fetch with the expected URL', async () => {
|
|
10
|
-
const link = new _.RestAPILink({
|
|
11
|
-
baseUrl: 'http://url',
|
|
12
|
-
apiVersion: 42
|
|
13
|
-
});
|
|
14
|
-
await link.executeResourceQuery('read', {
|
|
15
|
-
resource: 'something'
|
|
16
|
-
}, {});
|
|
17
|
-
expect(_fetchData.fetchData).toHaveBeenCalledWith('http://url/api/42/something', {
|
|
18
|
-
method: 'GET'
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
});
|
package/build/cjs/links/index.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _CustomDataLink = require("./CustomDataLink");
|
|
7
|
-
Object.keys(_CustomDataLink).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _CustomDataLink[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _CustomDataLink[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _ErrorLink = require("./ErrorLink");
|
|
18
|
-
Object.keys(_ErrorLink).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _ErrorLink[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _ErrorLink[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _RestAPILink = require("./RestAPILink");
|
|
29
|
-
Object.keys(_RestAPILink).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _RestAPILink[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _RestAPILink[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _d2I18n = _interopRequireDefault(require("@dhis2/d2-i18n"));
|
|
8
|
-
var _translations = _interopRequireDefault(require("./en/translations.json"));
|
|
9
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
//------------------------------------------------------------------------------
|
|
11
|
-
// <auto-generated>
|
|
12
|
-
// This code was generated by d2-i18n-generate.
|
|
13
|
-
//
|
|
14
|
-
// Changes to this file may cause incorrect behavior and will be lost if
|
|
15
|
-
// the code is regenerated.
|
|
16
|
-
// </auto-generated>
|
|
17
|
-
//------------------------------------------------------------------------------
|
|
18
|
-
|
|
19
|
-
const namespace = 'default';
|
|
20
|
-
_d2I18n.default.addResources('en', namespace, _translations.default);
|
|
21
|
-
var _default = exports.default = _d2I18n.default;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.defaultContext = void 0;
|
|
7
|
-
var _engine = require("../../engine");
|
|
8
|
-
var _links = require("../../links");
|
|
9
|
-
const errorMessage = 'DHIS2 data context must be initialized, please ensure that you include a <DataProvider> in your application';
|
|
10
|
-
const link = new _links.ErrorLink(errorMessage);
|
|
11
|
-
const engine = new _engine.DataEngine(link);
|
|
12
|
-
const defaultContext = exports.defaultContext = {
|
|
13
|
-
engine
|
|
14
|
-
};
|
|
@@ -1,66 +0,0 @@
|
|
|
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); }
|
|
4
|
-
import { getMutationFetchType } from './helpers/getMutationFetchType';
|
|
5
|
-
import { resolveDynamicQuery } from './helpers/resolveDynamicQuery';
|
|
6
|
-
import { validateResourceQuery, validateResourceQueries } from './helpers/validate';
|
|
7
|
-
const reduceResponses = (responses, names) => responses.reduce((out, response, idx) => {
|
|
8
|
-
out[names[idx]] = response;
|
|
9
|
-
return out;
|
|
10
|
-
}, {});
|
|
11
|
-
export class DataEngine {
|
|
12
|
-
constructor(link) {
|
|
13
|
-
_defineProperty(this, "link", void 0);
|
|
14
|
-
this.link = link;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Overload 1: When no generic is provided, accept any Query and return inferred type
|
|
18
|
-
|
|
19
|
-
// Overload 2: When generic is provided, enforce that query keys match the generic keys
|
|
20
|
-
|
|
21
|
-
query(query) {
|
|
22
|
-
let {
|
|
23
|
-
variables = {},
|
|
24
|
-
signal,
|
|
25
|
-
onComplete,
|
|
26
|
-
onError
|
|
27
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
28
|
-
const names = Object.keys(query);
|
|
29
|
-
const queries = names.map(name => query[name]).map(q => resolveDynamicQuery(q, variables));
|
|
30
|
-
validateResourceQueries(queries, names);
|
|
31
|
-
return Promise.all(queries.map(q => {
|
|
32
|
-
return this.link.executeResourceQuery('read', q, {
|
|
33
|
-
signal
|
|
34
|
-
});
|
|
35
|
-
})).then(results => {
|
|
36
|
-
const data = reduceResponses(results, names);
|
|
37
|
-
onComplete && onComplete(data);
|
|
38
|
-
return data;
|
|
39
|
-
}).catch(error => {
|
|
40
|
-
onError && onError(error);
|
|
41
|
-
throw error;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
mutate(mutation) {
|
|
45
|
-
let {
|
|
46
|
-
variables = {},
|
|
47
|
-
signal,
|
|
48
|
-
onComplete,
|
|
49
|
-
onError
|
|
50
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
51
|
-
const query = resolveDynamicQuery(mutation, variables);
|
|
52
|
-
const type = getMutationFetchType(mutation);
|
|
53
|
-
validateResourceQuery(type, query);
|
|
54
|
-
const result = this.link.executeResourceQuery(type, query, {
|
|
55
|
-
signal
|
|
56
|
-
});
|
|
57
|
-
return result.then(data => {
|
|
58
|
-
onComplete && onComplete(data);
|
|
59
|
-
return data;
|
|
60
|
-
}).catch(error => {
|
|
61
|
-
onError && onError(error);
|
|
62
|
-
throw error;
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
export default DataEngine;
|