@dhis2/app-service-data 3.8.0 → 3.10.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 +16 -10
- package/build/cjs/__tests__/mutations.test.js +8 -5
- package/build/cjs/engine/DataEngine.js +14 -12
- package/build/cjs/engine/helpers/resolveDynamicQuery.js +14 -11
- package/build/cjs/engine/helpers/resolveDynamicQuery.test.js +23 -14
- package/build/cjs/engine/helpers/validate.js +6 -4
- package/build/cjs/engine/helpers/validate.test.js +74 -15
- package/build/cjs/engine/types/FetchError.js +6 -5
- package/build/cjs/engine/types/InvalidQueryError.js +1 -1
- package/build/cjs/index.js +10 -10
- package/build/cjs/links/CustomDataLink.js +8 -6
- package/build/cjs/links/CustomDataLink.test.js +2 -2
- package/build/cjs/links/RestAPILink/fetchData.js +3 -2
- package/build/cjs/links/RestAPILink/fetchData.test.js +1 -1
- package/build/cjs/links/RestAPILink/metadataResources.js +1 -1
- package/build/cjs/links/RestAPILink/path.js +5 -1
- package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +29 -16
- package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.js +9 -6
- package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +2 -2
- package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +51 -33
- package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +6 -3
- package/build/cjs/links/RestAPILink/queryToRequestOptions.js +1 -1
- package/build/cjs/links/RestAPILink/queryToRequestOptions.test.js +56 -6
- package/build/cjs/links/RestAPILink/queryToResourcePath.js +14 -6
- package/build/cjs/links/RestAPILink/queryToResourcePath.test.js +16 -16
- package/build/cjs/links/RestAPILink/validateQuery.test.js +12 -12
- package/build/cjs/links/RestAPILink.js +4 -3
- package/build/cjs/react/components/CustomDataProvider.js +7 -6
- package/build/cjs/react/components/DataMutation.js +8 -7
- package/build/cjs/react/components/DataProvider.js +1 -1
- package/build/cjs/react/components/DataQuery.js +9 -8
- package/build/cjs/react/context/defaultContext.test.js +10 -2
- package/build/cjs/react/hooks/stableVariablesHash.js +1 -2
- package/build/cjs/react/hooks/stableVariablesHash.test.js +6 -6
- package/build/cjs/react/hooks/useDataMutation.js +7 -6
- package/build/cjs/react/hooks/useDataMutation.test.js +70 -43
- package/build/cjs/react/hooks/useDataQuery.js +13 -9
- package/build/cjs/react/hooks/useDataQuery.test.js +259 -162
- package/build/cjs/react/hooks/useQueryExecutor.js +11 -9
- package/build/cjs/react/hooks/useQueryExecutor.test.js +16 -12
- package/build/cjs/react/hooks/useStaticInput.js +7 -6
- package/build/cjs/react/hooks/useStaticInput.test.js +44 -25
- package/build/cjs/react/index.js +6 -6
- package/build/es/__tests__/integration.test.js +16 -10
- package/build/es/__tests__/mutations.test.js +8 -5
- package/build/es/engine/DataEngine.js +14 -12
- package/build/es/engine/helpers/resolveDynamicQuery.js +14 -11
- package/build/es/engine/helpers/resolveDynamicQuery.test.js +23 -14
- package/build/es/engine/helpers/validate.js +6 -4
- package/build/es/engine/helpers/validate.test.js +74 -15
- package/build/es/engine/types/FetchError.js +6 -5
- package/build/es/engine/types/InvalidQueryError.js +1 -1
- package/build/es/links/CustomDataLink.js +8 -6
- package/build/es/links/CustomDataLink.test.js +2 -2
- package/build/es/links/RestAPILink/fetchData.js +3 -2
- package/build/es/links/RestAPILink/fetchData.test.js +1 -1
- package/build/es/links/RestAPILink/path.js +5 -1
- package/build/es/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +28 -15
- package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.js +8 -5
- package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +2 -2
- package/build/es/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +50 -32
- package/build/es/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +6 -3
- package/build/es/links/RestAPILink/queryToRequestOptions.js +1 -1
- package/build/es/links/RestAPILink/queryToRequestOptions.test.js +56 -6
- package/build/es/links/RestAPILink/queryToResourcePath.js +14 -6
- package/build/es/links/RestAPILink/queryToResourcePath.test.js +16 -16
- package/build/es/links/RestAPILink/validateQuery.test.js +12 -12
- package/build/es/links/RestAPILink.js +4 -3
- package/build/es/react/components/CustomDataProvider.js +7 -6
- package/build/es/react/components/DataMutation.js +8 -7
- package/build/es/react/components/DataQuery.js +9 -8
- package/build/es/react/context/defaultContext.test.js +10 -2
- package/build/es/react/hooks/stableVariablesHash.js +1 -2
- package/build/es/react/hooks/stableVariablesHash.test.js +6 -6
- package/build/es/react/hooks/useDataMutation.js +7 -6
- package/build/es/react/hooks/useDataMutation.test.js +70 -43
- package/build/es/react/hooks/useDataQuery.js +13 -9
- package/build/es/react/hooks/useDataQuery.test.js +259 -162
- package/build/es/react/hooks/useQueryExecutor.js +11 -9
- package/build/es/react/hooks/useQueryExecutor.test.js +16 -12
- package/build/es/react/hooks/useStaticInput.js +7 -6
- package/build/es/react/hooks/useStaticInput.test.js +44 -25
- package/package.json +2 -2
|
@@ -16,11 +16,14 @@ describe('<DataQuery />', () => {
|
|
|
16
16
|
answer: 42
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
const wrapper = ({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
const wrapper = (_ref) => {
|
|
20
|
+
let {
|
|
21
|
+
children
|
|
22
|
+
} = _ref;
|
|
23
|
+
return /*#__PURE__*/React.createElement(_react3.CustomDataProvider, {
|
|
24
|
+
data: data
|
|
25
|
+
}, children);
|
|
26
|
+
};
|
|
24
27
|
|
|
25
28
|
const renderFunction = jest.fn(() => null);
|
|
26
29
|
(0, _react.render)( /*#__PURE__*/React.createElement(_react3.DataQuery, {
|
|
@@ -54,11 +57,14 @@ describe('<DataQuery />', () => {
|
|
|
54
57
|
}
|
|
55
58
|
};
|
|
56
59
|
|
|
57
|
-
const wrapper = ({
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
const wrapper = (_ref2) => {
|
|
61
|
+
let {
|
|
62
|
+
children
|
|
63
|
+
} = _ref2;
|
|
64
|
+
return /*#__PURE__*/React.createElement(_react3.CustomDataProvider, {
|
|
65
|
+
data: data
|
|
66
|
+
}, children);
|
|
67
|
+
};
|
|
62
68
|
|
|
63
69
|
const renderFunction = jest.fn(() => null);
|
|
64
70
|
(0, _react.render)( /*#__PURE__*/React.createElement(_react3.DataQuery, {
|
|
@@ -24,11 +24,14 @@ describe('<DataMutation />', () => {
|
|
|
24
24
|
answer: endpointSpy
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
const wrapper = ({
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
const wrapper = (_ref) => {
|
|
28
|
+
let {
|
|
29
|
+
children
|
|
30
|
+
} = _ref;
|
|
31
|
+
return /*#__PURE__*/React.createElement(_react3.CustomDataProvider, {
|
|
32
|
+
data: data
|
|
33
|
+
}, children);
|
|
34
|
+
};
|
|
32
35
|
|
|
33
36
|
const renderSpy = jest.fn(() => null);
|
|
34
37
|
(0, _react.render)( /*#__PURE__*/React.createElement(_react3.DataMutation, {
|
|
@@ -25,12 +25,13 @@ class DataEngine {
|
|
|
25
25
|
this.link = link;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
query(query
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
query(query) {
|
|
29
|
+
let {
|
|
30
|
+
variables = {},
|
|
31
|
+
signal,
|
|
32
|
+
onComplete,
|
|
33
|
+
onError
|
|
34
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
34
35
|
const names = Object.keys(query);
|
|
35
36
|
const queries = names.map(name => query[name]).map(q => (0, _resolveDynamicQuery.resolveDynamicQuery)(q, variables));
|
|
36
37
|
(0, _validate.validateResourceQueries)(queries, names);
|
|
@@ -48,12 +49,13 @@ class DataEngine {
|
|
|
48
49
|
});
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
mutate(mutation
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
mutate(mutation) {
|
|
53
|
+
let {
|
|
54
|
+
variables = {},
|
|
55
|
+
signal,
|
|
56
|
+
onComplete,
|
|
57
|
+
onError
|
|
58
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
57
59
|
const query = (0, _resolveDynamicQuery.resolveDynamicQuery)(mutation, variables);
|
|
58
60
|
const type = (0, _getMutationFetchType.getMutationFetchType)(mutation);
|
|
59
61
|
(0, _validate.validateResourceQuery)(type, query);
|
|
@@ -5,16 +5,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.resolveDynamicQuery = void 0;
|
|
7
7
|
|
|
8
|
-
const resolveDynamicQuery = ({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
const resolveDynamicQuery = (_ref, variables) => {
|
|
9
|
+
let {
|
|
10
|
+
resource,
|
|
11
|
+
id,
|
|
12
|
+
data,
|
|
13
|
+
params
|
|
14
|
+
} = _ref;
|
|
15
|
+
return {
|
|
16
|
+
resource,
|
|
17
|
+
id: typeof id === 'function' ? id(variables) : id,
|
|
18
|
+
data: typeof data === 'function' ? data(variables) : data,
|
|
19
|
+
params: typeof params === 'function' ? params(variables) : params
|
|
20
|
+
};
|
|
21
|
+
};
|
|
19
22
|
|
|
20
23
|
exports.resolveDynamicQuery = resolveDynamicQuery;
|
|
@@ -20,20 +20,29 @@ describe('resolveDynamicQuery', () => {
|
|
|
20
20
|
it('Should replace variables in all dynamic properties', () => {
|
|
21
21
|
const query = {
|
|
22
22
|
resource: 'test',
|
|
23
|
-
id: ({
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
23
|
+
id: (_ref) => {
|
|
24
|
+
let {
|
|
25
|
+
id
|
|
26
|
+
} = _ref;
|
|
27
|
+
return id;
|
|
28
|
+
},
|
|
29
|
+
params: (_ref2) => {
|
|
30
|
+
let {
|
|
31
|
+
page
|
|
32
|
+
} = _ref2;
|
|
33
|
+
return {
|
|
34
|
+
page,
|
|
35
|
+
foo: 'bar'
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
data: (_ref3) => {
|
|
39
|
+
let {
|
|
40
|
+
bar
|
|
41
|
+
} = _ref3;
|
|
42
|
+
return {
|
|
43
|
+
bar
|
|
44
|
+
};
|
|
45
|
+
}
|
|
37
46
|
};
|
|
38
47
|
const vars = {
|
|
39
48
|
id: '42',
|
|
@@ -12,7 +12,7 @@ const validTypes = ['read', 'create', 'update', 'replace', 'delete', 'json-patch
|
|
|
12
12
|
|
|
13
13
|
const getResourceQueryErrors = (type, query) => {
|
|
14
14
|
if (!validTypes.includes(type)) {
|
|
15
|
-
return [
|
|
15
|
+
return [`Unknown query or mutation type ${type}`];
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
if (typeof query !== 'object') {
|
|
@@ -47,21 +47,23 @@ const getResourceQueryErrors = (type, query) => {
|
|
|
47
47
|
|
|
48
48
|
const invalidKeys = Object.keys(query).filter(k => !validQueryKeys.includes(k));
|
|
49
49
|
invalidKeys.forEach(k => {
|
|
50
|
-
errors.push(
|
|
50
|
+
errors.push(`Property ${k} is not supported`);
|
|
51
51
|
});
|
|
52
52
|
return errors;
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
exports.getResourceQueryErrors = getResourceQueryErrors;
|
|
56
56
|
|
|
57
|
-
const validateResourceQueries = (queries
|
|
57
|
+
const validateResourceQueries = function (queries) {
|
|
58
|
+
let names = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
59
|
+
|
|
58
60
|
if (names.length !== queries.length) {
|
|
59
61
|
for (let i = names.length; i < queries.length; ++i) {
|
|
60
62
|
names.push('query#' + i);
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
const errors = queries.reduce((errors, query, i) => errors.concat(getResourceQueryErrors('read', query).map(e =>
|
|
66
|
+
const errors = queries.reduce((errors, query, i) => errors.concat(getResourceQueryErrors('read', query).map(e => `[${names[i]}] ${e}`)), []);
|
|
65
67
|
|
|
66
68
|
if (errors.length) {
|
|
67
69
|
throw new _InvalidQueryError.InvalidQueryError(errors);
|
|
@@ -22,25 +22,45 @@ describe('query validation', () => {
|
|
|
22
22
|
resource: 'me'
|
|
23
23
|
});
|
|
24
24
|
expect(errors).toHaveLength(1);
|
|
25
|
-
expect(errors).toMatchInlineSnapshot(
|
|
25
|
+
expect(errors).toMatchInlineSnapshot(`
|
|
26
|
+
Array [
|
|
27
|
+
"Unknown query or mutation type rainbow",
|
|
28
|
+
]
|
|
29
|
+
`);
|
|
26
30
|
});
|
|
27
31
|
it('should fail if query is not an object', () => {
|
|
28
32
|
let errors = (0, _validate.getResourceQueryErrors)('read', 'query');
|
|
29
33
|
expect(errors).toHaveLength(1);
|
|
30
|
-
expect(errors).toMatchInlineSnapshot(
|
|
34
|
+
expect(errors).toMatchInlineSnapshot(`
|
|
35
|
+
Array [
|
|
36
|
+
"A query or mutation must be a javascript object",
|
|
37
|
+
]
|
|
38
|
+
`);
|
|
31
39
|
errors = (0, _validate.getResourceQueryErrors)('read', 42);
|
|
32
40
|
expect(errors).toHaveLength(1);
|
|
33
|
-
expect(errors).toMatchInlineSnapshot(
|
|
41
|
+
expect(errors).toMatchInlineSnapshot(`
|
|
42
|
+
Array [
|
|
43
|
+
"A query or mutation must be a javascript object",
|
|
44
|
+
]
|
|
45
|
+
`);
|
|
34
46
|
});
|
|
35
47
|
it('should fail if query is missing resource property', () => {
|
|
36
48
|
const errors = (0, _validate.getResourceQueryErrors)('read', {});
|
|
37
49
|
expect(errors).toHaveLength(1);
|
|
38
|
-
expect(errors).toMatchInlineSnapshot(
|
|
50
|
+
expect(errors).toMatchInlineSnapshot(`
|
|
51
|
+
Array [
|
|
52
|
+
"Property resource must be a string",
|
|
53
|
+
]
|
|
54
|
+
`);
|
|
39
55
|
});
|
|
40
56
|
it('should fail if query is missing resource property', () => {
|
|
41
57
|
const errors = (0, _validate.getResourceQueryErrors)('read', {});
|
|
42
58
|
expect(errors).toHaveLength(1);
|
|
43
|
-
expect(errors).toMatchInlineSnapshot(
|
|
59
|
+
expect(errors).toMatchInlineSnapshot(`
|
|
60
|
+
Array [
|
|
61
|
+
"Property resource must be a string",
|
|
62
|
+
]
|
|
63
|
+
`);
|
|
44
64
|
});
|
|
45
65
|
it('should fail if query is create mutation with id prop', () => {
|
|
46
66
|
const errors = (0, _validate.getResourceQueryErrors)('create', {
|
|
@@ -48,7 +68,11 @@ describe('query validation', () => {
|
|
|
48
68
|
id: 'something'
|
|
49
69
|
});
|
|
50
70
|
expect(errors).toHaveLength(1);
|
|
51
|
-
expect(errors).toMatchInlineSnapshot(
|
|
71
|
+
expect(errors).toMatchInlineSnapshot(`
|
|
72
|
+
Array [
|
|
73
|
+
"Mutation type 'create' does not support property 'id'",
|
|
74
|
+
]
|
|
75
|
+
`);
|
|
52
76
|
});
|
|
53
77
|
it('should fail if id prop is not a string', () => {
|
|
54
78
|
const errors = (0, _validate.getResourceQueryErrors)('update', {
|
|
@@ -56,7 +80,11 @@ describe('query validation', () => {
|
|
|
56
80
|
id: 42
|
|
57
81
|
});
|
|
58
82
|
expect(errors).toHaveLength(1);
|
|
59
|
-
expect(errors).toMatchInlineSnapshot(
|
|
83
|
+
expect(errors).toMatchInlineSnapshot(`
|
|
84
|
+
Array [
|
|
85
|
+
"Property id must be a string",
|
|
86
|
+
]
|
|
87
|
+
`);
|
|
60
88
|
});
|
|
61
89
|
it('should fail if params prop is not an object', () => {
|
|
62
90
|
const errors = (0, _validate.getResourceQueryErrors)('update', {
|
|
@@ -65,7 +93,11 @@ describe('query validation', () => {
|
|
|
65
93
|
params: 'querystring=42'
|
|
66
94
|
});
|
|
67
95
|
expect(errors).toHaveLength(1);
|
|
68
|
-
expect(errors).toMatchInlineSnapshot(
|
|
96
|
+
expect(errors).toMatchInlineSnapshot(`
|
|
97
|
+
Array [
|
|
98
|
+
"Property params must be an object",
|
|
99
|
+
]
|
|
100
|
+
`);
|
|
69
101
|
});
|
|
70
102
|
it('should fail if query is delete mutation with data prop', () => {
|
|
71
103
|
const errors = (0, _validate.getResourceQueryErrors)('delete', {
|
|
@@ -74,7 +106,11 @@ describe('query validation', () => {
|
|
|
74
106
|
data: 'querystring=42'
|
|
75
107
|
});
|
|
76
108
|
expect(errors).toHaveLength(1);
|
|
77
|
-
expect(errors).toMatchInlineSnapshot(
|
|
109
|
+
expect(errors).toMatchInlineSnapshot(`
|
|
110
|
+
Array [
|
|
111
|
+
"Mutation type 'delete' does not support property 'data'",
|
|
112
|
+
]
|
|
113
|
+
`);
|
|
78
114
|
});
|
|
79
115
|
it('should fail if query is json-patch mutation with non-array data prop', () => {
|
|
80
116
|
const errors = (0, _validate.getResourceQueryErrors)('json-patch', {
|
|
@@ -82,7 +118,11 @@ describe('query validation', () => {
|
|
|
82
118
|
data: {}
|
|
83
119
|
});
|
|
84
120
|
expect(errors).toHaveLength(1);
|
|
85
|
-
expect(errors).toMatchInlineSnapshot(
|
|
121
|
+
expect(errors).toMatchInlineSnapshot(`
|
|
122
|
+
Array [
|
|
123
|
+
"Mutation type 'json-patch' requires property 'data' to be of type Array",
|
|
124
|
+
]
|
|
125
|
+
`);
|
|
86
126
|
});
|
|
87
127
|
it('should fail if unrecognized keys are passed to query', () => {
|
|
88
128
|
const errors = (0, _validate.getResourceQueryErrors)('update', {
|
|
@@ -92,7 +132,12 @@ describe('query validation', () => {
|
|
|
92
132
|
foo: 'bar'
|
|
93
133
|
});
|
|
94
134
|
expect(errors).toHaveLength(2);
|
|
95
|
-
expect(errors).toMatchInlineSnapshot(
|
|
135
|
+
expect(errors).toMatchInlineSnapshot(`
|
|
136
|
+
Array [
|
|
137
|
+
"Property query is not supported",
|
|
138
|
+
"Property foo is not supported",
|
|
139
|
+
]
|
|
140
|
+
`);
|
|
96
141
|
});
|
|
97
142
|
});
|
|
98
143
|
describe('validateResourceQuery', () => {
|
|
@@ -105,13 +150,19 @@ describe('query validation', () => {
|
|
|
105
150
|
expect(() => (0, _validate.validateResourceQuery)('create', {
|
|
106
151
|
resource: 'me',
|
|
107
152
|
id: '42'
|
|
108
|
-
})).toThrowErrorMatchingInlineSnapshot(
|
|
153
|
+
})).toThrowErrorMatchingInlineSnapshot(`
|
|
154
|
+
"Invalid query
|
|
155
|
+
- Mutation type 'create' does not support property 'id'"
|
|
156
|
+
`);
|
|
109
157
|
});
|
|
110
158
|
it('should throw an error with an invalid query', () => {
|
|
111
159
|
expect(() => (0, _validate.validateResourceQuery)('create', {
|
|
112
160
|
resource: 'me',
|
|
113
161
|
answer: 42
|
|
114
|
-
})).toThrowErrorMatchingInlineSnapshot(
|
|
162
|
+
})).toThrowErrorMatchingInlineSnapshot(`
|
|
163
|
+
"Invalid query
|
|
164
|
+
- Property answer is not supported"
|
|
165
|
+
`);
|
|
115
166
|
});
|
|
116
167
|
});
|
|
117
168
|
describe('validateResourceQueries', () => {
|
|
@@ -131,7 +182,11 @@ describe('query validation', () => {
|
|
|
131
182
|
}, {
|
|
132
183
|
resource: 'me',
|
|
133
184
|
id: 42
|
|
134
|
-
}])).toThrowErrorMatchingInlineSnapshot(
|
|
185
|
+
}])).toThrowErrorMatchingInlineSnapshot(`
|
|
186
|
+
"Invalid query
|
|
187
|
+
- [query#1] Property params must be an object
|
|
188
|
+
- [query#2] Property id must be a string"
|
|
189
|
+
`);
|
|
135
190
|
});
|
|
136
191
|
it('should throw if any query is invalid, prefixing with relevant name', () => {
|
|
137
192
|
expect(() => (0, _validate.validateResourceQueries)([{
|
|
@@ -142,7 +197,11 @@ describe('query validation', () => {
|
|
|
142
197
|
}, {
|
|
143
198
|
resource: 'me',
|
|
144
199
|
id: 42
|
|
145
|
-
}], ['me', 'inds'])).toThrowErrorMatchingInlineSnapshot(
|
|
200
|
+
}], ['me', 'inds'])).toThrowErrorMatchingInlineSnapshot(`
|
|
201
|
+
"Invalid query
|
|
202
|
+
- [inds] Property params must be an object
|
|
203
|
+
- [query#2] Property id must be a string"
|
|
204
|
+
`);
|
|
146
205
|
});
|
|
147
206
|
});
|
|
148
207
|
});
|
|
@@ -8,11 +8,12 @@ exports.FetchError = void 0;
|
|
|
8
8
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
9
|
|
|
10
10
|
class FetchError extends Error {
|
|
11
|
-
constructor({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
constructor(_ref) {
|
|
12
|
+
let {
|
|
13
|
+
message,
|
|
14
|
+
type,
|
|
15
|
+
details = {}
|
|
16
|
+
} = _ref;
|
|
16
17
|
super(message);
|
|
17
18
|
|
|
18
19
|
_defineProperty(this, "type", void 0);
|
|
@@ -9,7 +9,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
9
9
|
|
|
10
10
|
class InvalidQueryError extends Error {
|
|
11
11
|
constructor(errors) {
|
|
12
|
-
super(
|
|
12
|
+
super(`Invalid query\n${errors.map(e => ' - ' + e).join('\n')}`);
|
|
13
13
|
|
|
14
14
|
_defineProperty(this, "type", 'invalid-query');
|
|
15
15
|
|
package/build/cjs/index.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "CustomDataProvider", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return _react.
|
|
9
|
+
return _react.CustomDataProvider;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "DataMutation", {
|
|
@@ -21,22 +21,22 @@ Object.defineProperty(exports, "DataProvider", {
|
|
|
21
21
|
return _react.DataProvider;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
-
Object.defineProperty(exports, "
|
|
24
|
+
Object.defineProperty(exports, "DataQuery", {
|
|
25
25
|
enumerable: true,
|
|
26
26
|
get: function () {
|
|
27
|
-
return _react.
|
|
27
|
+
return _react.DataQuery;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
Object.defineProperty(exports, "
|
|
30
|
+
Object.defineProperty(exports, "FetchError", {
|
|
31
31
|
enumerable: true,
|
|
32
32
|
get: function () {
|
|
33
|
-
return
|
|
33
|
+
return _engine.FetchError;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
-
Object.defineProperty(exports, "
|
|
36
|
+
Object.defineProperty(exports, "useDataEngine", {
|
|
37
37
|
enumerable: true,
|
|
38
38
|
get: function () {
|
|
39
|
-
return _react.
|
|
39
|
+
return _react.useDataEngine;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
Object.defineProperty(exports, "useDataMutation", {
|
|
@@ -45,10 +45,10 @@ Object.defineProperty(exports, "useDataMutation", {
|
|
|
45
45
|
return _react.useDataMutation;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
-
Object.defineProperty(exports, "
|
|
48
|
+
Object.defineProperty(exports, "useDataQuery", {
|
|
49
49
|
enumerable: true,
|
|
50
50
|
get: function () {
|
|
51
|
-
return
|
|
51
|
+
return _react.useDataQuery;
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
54
|
|
|
@@ -8,10 +8,12 @@ exports.CustomDataLink = void 0;
|
|
|
8
8
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
9
|
|
|
10
10
|
class CustomDataLink {
|
|
11
|
-
constructor(customData
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
constructor(customData) {
|
|
12
|
+
let {
|
|
13
|
+
failOnMiss = true,
|
|
14
|
+
loadForever = false
|
|
15
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
16
|
+
|
|
15
17
|
_defineProperty(this, "failOnMiss", void 0);
|
|
16
18
|
|
|
17
19
|
_defineProperty(this, "loadForever", void 0);
|
|
@@ -32,7 +34,7 @@ class CustomDataLink {
|
|
|
32
34
|
|
|
33
35
|
if (customResource === undefined) {
|
|
34
36
|
if (this.failOnMiss) {
|
|
35
|
-
throw new Error(
|
|
37
|
+
throw new Error(`No data provided for resource type ${query.resource}!`);
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
return Promise.resolve(null);
|
|
@@ -50,7 +52,7 @@ class CustomDataLink {
|
|
|
50
52
|
const result = await customResource(type, query, options);
|
|
51
53
|
|
|
52
54
|
if (typeof result === 'undefined' && this.failOnMiss) {
|
|
53
|
-
throw new Error(
|
|
55
|
+
throw new Error(`The custom function for resource ${query.resource} must always return a value but returned ${result}`);
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
return result || null;
|
|
@@ -17,7 +17,7 @@ describe('CustomDataLink', () => {
|
|
|
17
17
|
});
|
|
18
18
|
expect(link.executeResourceQuery('read', {
|
|
19
19
|
resource: 'something'
|
|
20
|
-
}, {})).rejects.toMatchInlineSnapshot(
|
|
20
|
+
}, {})).rejects.toMatchInlineSnapshot(`[Error: No data provided for resource type something!]`);
|
|
21
21
|
});
|
|
22
22
|
it('Should swallow miss error with failOnMiss=false', async () => {
|
|
23
23
|
const link = new _CustomDataLink.CustomDataLink({
|
|
@@ -43,7 +43,7 @@ describe('CustomDataLink', () => {
|
|
|
43
43
|
});
|
|
44
44
|
expect(link.executeResourceQuery('read', {
|
|
45
45
|
resource: 'foo'
|
|
46
|
-
}, {})).rejects.toMatchInlineSnapshot(
|
|
46
|
+
}, {})).rejects.toMatchInlineSnapshot(`[Error: The custom function for resource foo must always return a value but returned undefined]`);
|
|
47
47
|
});
|
|
48
48
|
it('Should swallow functional miss if failOnMiss=false', async () => {
|
|
49
49
|
const link = new _CustomDataLink.CustomDataLink({
|
|
@@ -38,7 +38,7 @@ const parseStatus = async response => {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
if (response.status < 200 || response.status >= 400) {
|
|
41
|
-
const message =
|
|
41
|
+
const message = `An unknown error occurred - ${response.statusText} (${response.status})`;
|
|
42
42
|
let details = {};
|
|
43
43
|
|
|
44
44
|
try {
|
|
@@ -58,7 +58,8 @@ const parseStatus = async response => {
|
|
|
58
58
|
|
|
59
59
|
exports.parseStatus = parseStatus;
|
|
60
60
|
|
|
61
|
-
function fetchData(url
|
|
61
|
+
function fetchData(url) {
|
|
62
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
62
63
|
return fetch(url, { ...options,
|
|
63
64
|
credentials: 'include',
|
|
64
65
|
headers: {
|
|
@@ -81,7 +81,7 @@ describe('networkFetch', () => {
|
|
|
81
81
|
};
|
|
82
82
|
expect((0, _fetchData.parseStatus)(response)).rejects.toMatchObject({
|
|
83
83
|
type: 'unknown',
|
|
84
|
-
message:
|
|
84
|
+
message: `An unknown error occurred - Failed (500)`,
|
|
85
85
|
details: {
|
|
86
86
|
message: 'An error occurred'
|
|
87
87
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.normativeMetadataResources = exports.nonNormativeMetadataResources = void 0;
|
|
7
7
|
|
|
8
8
|
/*
|
|
9
9
|
* These are metadata resources (from /api/resources) which are known to support paging.
|
|
@@ -5,7 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.joinPath = void 0;
|
|
7
7
|
|
|
8
|
-
const joinPath = (
|
|
8
|
+
const joinPath = function () {
|
|
9
|
+
for (var _len = arguments.length, parts = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
10
|
+
parts[_key] = arguments[_key];
|
|
11
|
+
}
|
|
12
|
+
|
|
9
13
|
const realParts = parts.filter(part => !!part);
|
|
10
14
|
return realParts.map(part => part.replace(/^\/+|\/+$/g, '')).join('/');
|
|
11
15
|
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.isStaticContentUpload = exports.isMessageConversationAttachment = exports.isFileResourceUpload = exports.isDataValue = exports.isAppInstall = void 0;
|
|
7
7
|
|
|
8
8
|
/*
|
|
9
9
|
* Requests that expect a "multipart/form-data" Content-Type have been collected by scanning
|
|
@@ -12,30 +12,40 @@ exports.isAppInstall = exports.isStaticContentUpload = exports.isMessageConversa
|
|
|
12
12
|
*/
|
|
13
13
|
// Post to 'dataValues' (send/update a data value; endpoint doesn't support JSON)
|
|
14
14
|
// For file-uploads too
|
|
15
|
-
const isDataValue = (type, {
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const isDataValue = (type, _ref) => {
|
|
16
|
+
let {
|
|
17
|
+
resource
|
|
18
|
+
} = _ref;
|
|
19
|
+
return type === 'create' && (resource === 'dataValues' || resource === 'dataValues/file');
|
|
20
|
+
}; // POST to 'fileResources' (upload a file resource)
|
|
18
21
|
|
|
19
22
|
|
|
20
23
|
exports.isDataValue = isDataValue;
|
|
21
24
|
|
|
22
|
-
const isFileResourceUpload = (type, {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
const isFileResourceUpload = (type, _ref2) => {
|
|
26
|
+
let {
|
|
27
|
+
resource
|
|
28
|
+
} = _ref2;
|
|
29
|
+
return type === 'create' && resource === 'fileResources';
|
|
30
|
+
}; // POST to 'messageConversations/attachments' (upload a message conversation attachment)
|
|
25
31
|
|
|
26
32
|
|
|
27
33
|
exports.isFileResourceUpload = isFileResourceUpload;
|
|
28
34
|
|
|
29
|
-
const isMessageConversationAttachment = (type, {
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
const isMessageConversationAttachment = (type, _ref3) => {
|
|
36
|
+
let {
|
|
37
|
+
resource
|
|
38
|
+
} = _ref3;
|
|
39
|
+
return type === 'create' && resource === 'messageConversations/attachments';
|
|
40
|
+
}; // POST to `staticContent/${key}` (upload staticContent: logo_banner | logo_front)
|
|
32
41
|
|
|
33
42
|
|
|
34
43
|
exports.isMessageConversationAttachment = isMessageConversationAttachment;
|
|
35
44
|
|
|
36
|
-
const isStaticContentUpload = (type, {
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
const isStaticContentUpload = (type, _ref4) => {
|
|
46
|
+
let {
|
|
47
|
+
resource
|
|
48
|
+
} = _ref4;
|
|
39
49
|
const pattern = /^staticContent\/(?:logo_banner|logo_front)$/;
|
|
40
50
|
return type === 'create' && pattern.test(resource);
|
|
41
51
|
}; // POST to 'apps' (install an app)
|
|
@@ -43,8 +53,11 @@ const isStaticContentUpload = (type, {
|
|
|
43
53
|
|
|
44
54
|
exports.isStaticContentUpload = isStaticContentUpload;
|
|
45
55
|
|
|
46
|
-
const isAppInstall = (type, {
|
|
47
|
-
|
|
48
|
-
|
|
56
|
+
const isAppInstall = (type, _ref5) => {
|
|
57
|
+
let {
|
|
58
|
+
resource
|
|
59
|
+
} = _ref5;
|
|
60
|
+
return type === 'create' && resource === 'apps';
|
|
61
|
+
};
|
|
49
62
|
|
|
50
63
|
exports.isAppInstall = isAppInstall;
|