@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,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _resolveDynamicQuery = require("./resolveDynamicQuery");
|
|
4
|
-
describe('resolveDynamicQuery', () => {
|
|
5
|
-
it('Should return an unmodified query if no dynamic properties exist', () => {
|
|
6
|
-
const query = {
|
|
7
|
-
resource: 'test',
|
|
8
|
-
id: '42',
|
|
9
|
-
params: {
|
|
10
|
-
page: 3,
|
|
11
|
-
foo: 'bar'
|
|
12
|
-
},
|
|
13
|
-
data: {
|
|
14
|
-
bar: 'baz'
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
expect((0, _resolveDynamicQuery.resolveDynamicQuery)(query, {})).toStrictEqual(query);
|
|
18
|
-
});
|
|
19
|
-
it('Should replace variables in all dynamic properties', () => {
|
|
20
|
-
const query = {
|
|
21
|
-
resource: 'test',
|
|
22
|
-
id: _ref => {
|
|
23
|
-
let {
|
|
24
|
-
id
|
|
25
|
-
} = _ref;
|
|
26
|
-
return id;
|
|
27
|
-
},
|
|
28
|
-
params: _ref2 => {
|
|
29
|
-
let {
|
|
30
|
-
page
|
|
31
|
-
} = _ref2;
|
|
32
|
-
return {
|
|
33
|
-
page,
|
|
34
|
-
foo: 'bar'
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
data: _ref3 => {
|
|
38
|
-
let {
|
|
39
|
-
bar
|
|
40
|
-
} = _ref3;
|
|
41
|
-
return {
|
|
42
|
-
bar
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
const vars = {
|
|
47
|
-
id: '42',
|
|
48
|
-
page: 3,
|
|
49
|
-
bar: 'baz'
|
|
50
|
-
};
|
|
51
|
-
expect((0, _resolveDynamicQuery.resolveDynamicQuery)(query, vars)).toStrictEqual({
|
|
52
|
-
resource: 'test',
|
|
53
|
-
id: '42',
|
|
54
|
-
params: {
|
|
55
|
-
page: 3,
|
|
56
|
-
foo: 'bar'
|
|
57
|
-
},
|
|
58
|
-
data: {
|
|
59
|
-
bar: 'baz'
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.validateResourceQuery = exports.validateResourceQueries = exports.getResourceQueryErrors = void 0;
|
|
7
|
-
var _InvalidQueryError = require("../types/InvalidQueryError");
|
|
8
|
-
const validQueryKeys = ['resource', 'id', 'params', 'data'];
|
|
9
|
-
const validTypes = ['read', 'create', 'update', 'replace', 'delete', 'json-patch'];
|
|
10
|
-
const getResourceQueryErrors = (type, query) => {
|
|
11
|
-
if (!validTypes.includes(type)) {
|
|
12
|
-
return [`Unknown query or mutation type ${type}`];
|
|
13
|
-
}
|
|
14
|
-
if (typeof query !== 'object') {
|
|
15
|
-
return ['A query or mutation must be a javascript object'];
|
|
16
|
-
}
|
|
17
|
-
const errors = [];
|
|
18
|
-
if (!query.resource || typeof query.resource !== 'string') {
|
|
19
|
-
errors.push('Property resource must be a string');
|
|
20
|
-
}
|
|
21
|
-
if (type === 'create' && query.id) {
|
|
22
|
-
errors.push("Mutation type 'create' does not support property 'id'");
|
|
23
|
-
}
|
|
24
|
-
if (query.id && typeof query.id !== 'string') {
|
|
25
|
-
errors.push('Property id must be a string');
|
|
26
|
-
}
|
|
27
|
-
if (query.params && typeof query.params !== 'object') {
|
|
28
|
-
errors.push('Property params must be an object');
|
|
29
|
-
}
|
|
30
|
-
if (type === 'delete' && query.data) {
|
|
31
|
-
errors.push("Mutation type 'delete' does not support property 'data'");
|
|
32
|
-
}
|
|
33
|
-
if (type === 'json-patch' && !Array.isArray(query.data)) {
|
|
34
|
-
errors.push("Mutation type 'json-patch' requires property 'data' to be of type Array");
|
|
35
|
-
}
|
|
36
|
-
const invalidKeys = Object.keys(query).filter(k => !validQueryKeys.includes(k));
|
|
37
|
-
invalidKeys.forEach(k => {
|
|
38
|
-
errors.push(`Property ${k} is not supported`);
|
|
39
|
-
});
|
|
40
|
-
return errors;
|
|
41
|
-
};
|
|
42
|
-
exports.getResourceQueryErrors = getResourceQueryErrors;
|
|
43
|
-
const validateResourceQueries = function (queries) {
|
|
44
|
-
let names = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
45
|
-
if (names.length !== queries.length) {
|
|
46
|
-
for (let i = names.length; i < queries.length; ++i) {
|
|
47
|
-
names.push('query#' + i);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const errors = queries.reduce((errors, query, i) => errors.concat(getResourceQueryErrors('read', query).map(e => `[${names[i]}] ${e}`)), []);
|
|
51
|
-
if (errors.length) {
|
|
52
|
-
throw new _InvalidQueryError.InvalidQueryError(errors);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
exports.validateResourceQueries = validateResourceQueries;
|
|
56
|
-
const validateResourceQuery = (type, query) => {
|
|
57
|
-
const errors = getResourceQueryErrors(type, query);
|
|
58
|
-
if (errors.length) {
|
|
59
|
-
throw new _InvalidQueryError.InvalidQueryError(errors);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
exports.validateResourceQuery = validateResourceQuery;
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _validate = require("./validate");
|
|
4
|
-
describe('query validation', () => {
|
|
5
|
-
describe('getResourceQueryErrors', () => {
|
|
6
|
-
it('should pass with a simple valid query', () => {
|
|
7
|
-
expect((0, _validate.getResourceQueryErrors)('read', {
|
|
8
|
-
resource: 'me'
|
|
9
|
-
})).toHaveLength(0);
|
|
10
|
-
});
|
|
11
|
-
it('should pass with a simple valid mutation', () => {
|
|
12
|
-
expect((0, _validate.getResourceQueryErrors)('create', {
|
|
13
|
-
resource: 'indicators',
|
|
14
|
-
data: {
|
|
15
|
-
this: 'is a test'
|
|
16
|
-
}
|
|
17
|
-
})).toHaveLength(0);
|
|
18
|
-
});
|
|
19
|
-
it('should fail if an unknown type is specified', () => {
|
|
20
|
-
const errors = (0, _validate.getResourceQueryErrors)('rainbow', {
|
|
21
|
-
resource: 'me'
|
|
22
|
-
});
|
|
23
|
-
expect(errors).toHaveLength(1);
|
|
24
|
-
expect(errors).toMatchInlineSnapshot(`
|
|
25
|
-
Array [
|
|
26
|
-
"Unknown query or mutation type rainbow",
|
|
27
|
-
]
|
|
28
|
-
`);
|
|
29
|
-
});
|
|
30
|
-
it('should fail if query is not an object', () => {
|
|
31
|
-
let errors = (0, _validate.getResourceQueryErrors)('read', 'query');
|
|
32
|
-
expect(errors).toHaveLength(1);
|
|
33
|
-
expect(errors).toMatchInlineSnapshot(`
|
|
34
|
-
Array [
|
|
35
|
-
"A query or mutation must be a javascript object",
|
|
36
|
-
]
|
|
37
|
-
`);
|
|
38
|
-
errors = (0, _validate.getResourceQueryErrors)('read', 42);
|
|
39
|
-
expect(errors).toHaveLength(1);
|
|
40
|
-
expect(errors).toMatchInlineSnapshot(`
|
|
41
|
-
Array [
|
|
42
|
-
"A query or mutation must be a javascript object",
|
|
43
|
-
]
|
|
44
|
-
`);
|
|
45
|
-
});
|
|
46
|
-
it('should fail if query is missing resource property', () => {
|
|
47
|
-
const errors = (0, _validate.getResourceQueryErrors)('read', {});
|
|
48
|
-
expect(errors).toHaveLength(1);
|
|
49
|
-
expect(errors).toMatchInlineSnapshot(`
|
|
50
|
-
Array [
|
|
51
|
-
"Property resource must be a string",
|
|
52
|
-
]
|
|
53
|
-
`);
|
|
54
|
-
});
|
|
55
|
-
it('should fail if query is missing resource property', () => {
|
|
56
|
-
const errors = (0, _validate.getResourceQueryErrors)('read', {});
|
|
57
|
-
expect(errors).toHaveLength(1);
|
|
58
|
-
expect(errors).toMatchInlineSnapshot(`
|
|
59
|
-
Array [
|
|
60
|
-
"Property resource must be a string",
|
|
61
|
-
]
|
|
62
|
-
`);
|
|
63
|
-
});
|
|
64
|
-
it('should fail if query is create mutation with id prop', () => {
|
|
65
|
-
const errors = (0, _validate.getResourceQueryErrors)('create', {
|
|
66
|
-
resource: 'indicators',
|
|
67
|
-
id: 'something'
|
|
68
|
-
});
|
|
69
|
-
expect(errors).toHaveLength(1);
|
|
70
|
-
expect(errors).toMatchInlineSnapshot(`
|
|
71
|
-
Array [
|
|
72
|
-
"Mutation type 'create' does not support property 'id'",
|
|
73
|
-
]
|
|
74
|
-
`);
|
|
75
|
-
});
|
|
76
|
-
it('should fail if id prop is not a string', () => {
|
|
77
|
-
const errors = (0, _validate.getResourceQueryErrors)('update', {
|
|
78
|
-
resource: 'indicators',
|
|
79
|
-
id: 42
|
|
80
|
-
});
|
|
81
|
-
expect(errors).toHaveLength(1);
|
|
82
|
-
expect(errors).toMatchInlineSnapshot(`
|
|
83
|
-
Array [
|
|
84
|
-
"Property id must be a string",
|
|
85
|
-
]
|
|
86
|
-
`);
|
|
87
|
-
});
|
|
88
|
-
it('should fail if params prop is not an object', () => {
|
|
89
|
-
const errors = (0, _validate.getResourceQueryErrors)('update', {
|
|
90
|
-
resource: 'indicators',
|
|
91
|
-
id: '42',
|
|
92
|
-
params: 'querystring=42'
|
|
93
|
-
});
|
|
94
|
-
expect(errors).toHaveLength(1);
|
|
95
|
-
expect(errors).toMatchInlineSnapshot(`
|
|
96
|
-
Array [
|
|
97
|
-
"Property params must be an object",
|
|
98
|
-
]
|
|
99
|
-
`);
|
|
100
|
-
});
|
|
101
|
-
it('should fail if query is delete mutation with data prop', () => {
|
|
102
|
-
const errors = (0, _validate.getResourceQueryErrors)('delete', {
|
|
103
|
-
resource: 'indicators',
|
|
104
|
-
id: '42',
|
|
105
|
-
data: 'querystring=42'
|
|
106
|
-
});
|
|
107
|
-
expect(errors).toHaveLength(1);
|
|
108
|
-
expect(errors).toMatchInlineSnapshot(`
|
|
109
|
-
Array [
|
|
110
|
-
"Mutation type 'delete' does not support property 'data'",
|
|
111
|
-
]
|
|
112
|
-
`);
|
|
113
|
-
});
|
|
114
|
-
it('should fail if query is json-patch mutation with non-array data prop', () => {
|
|
115
|
-
const errors = (0, _validate.getResourceQueryErrors)('json-patch', {
|
|
116
|
-
resource: 'metadata',
|
|
117
|
-
data: {}
|
|
118
|
-
});
|
|
119
|
-
expect(errors).toHaveLength(1);
|
|
120
|
-
expect(errors).toMatchInlineSnapshot(`
|
|
121
|
-
Array [
|
|
122
|
-
"Mutation type 'json-patch' requires property 'data' to be of type Array",
|
|
123
|
-
]
|
|
124
|
-
`);
|
|
125
|
-
});
|
|
126
|
-
it('should fail if unrecognized keys are passed to query', () => {
|
|
127
|
-
const errors = (0, _validate.getResourceQueryErrors)('update', {
|
|
128
|
-
resource: 'indicators',
|
|
129
|
-
id: '42',
|
|
130
|
-
query: 'something',
|
|
131
|
-
foo: 'bar'
|
|
132
|
-
});
|
|
133
|
-
expect(errors).toHaveLength(2);
|
|
134
|
-
expect(errors).toMatchInlineSnapshot(`
|
|
135
|
-
Array [
|
|
136
|
-
"Property query is not supported",
|
|
137
|
-
"Property foo is not supported",
|
|
138
|
-
]
|
|
139
|
-
`);
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
describe('validateResourceQuery', () => {
|
|
143
|
-
it('should pass with a valid query', () => {
|
|
144
|
-
expect(() => (0, _validate.validateResourceQuery)('read', {
|
|
145
|
-
resource: 'me'
|
|
146
|
-
})).not.toThrowError();
|
|
147
|
-
});
|
|
148
|
-
it('should throw an error with an invalid query', () => {
|
|
149
|
-
expect(() => (0, _validate.validateResourceQuery)('create', {
|
|
150
|
-
resource: 'me',
|
|
151
|
-
id: '42'
|
|
152
|
-
})).toThrowErrorMatchingInlineSnapshot(`
|
|
153
|
-
"Invalid query
|
|
154
|
-
- Mutation type 'create' does not support property 'id'"
|
|
155
|
-
`);
|
|
156
|
-
});
|
|
157
|
-
it('should throw an error with an invalid query', () => {
|
|
158
|
-
expect(() => (0, _validate.validateResourceQuery)('create', {
|
|
159
|
-
resource: 'me',
|
|
160
|
-
answer: 42
|
|
161
|
-
})).toThrowErrorMatchingInlineSnapshot(`
|
|
162
|
-
"Invalid query
|
|
163
|
-
- Property answer is not supported"
|
|
164
|
-
`);
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
describe('validateResourceQueries', () => {
|
|
168
|
-
it('should pass with valid queries', () => {
|
|
169
|
-
expect(() => (0, _validate.validateResourceQueries)([{
|
|
170
|
-
resource: 'me'
|
|
171
|
-
}, {
|
|
172
|
-
resource: 'indicators'
|
|
173
|
-
}], ['me', 'ind'])).not.toThrowError();
|
|
174
|
-
});
|
|
175
|
-
it('should throw if any query is invalid', () => {
|
|
176
|
-
expect(() => (0, _validate.validateResourceQueries)([{
|
|
177
|
-
resource: 'me'
|
|
178
|
-
}, {
|
|
179
|
-
resource: 'indicators',
|
|
180
|
-
params: 'parameters'
|
|
181
|
-
}, {
|
|
182
|
-
resource: 'me',
|
|
183
|
-
id: 42
|
|
184
|
-
}])).toThrowErrorMatchingInlineSnapshot(`
|
|
185
|
-
"Invalid query
|
|
186
|
-
- [query#1] Property params must be an object
|
|
187
|
-
- [query#2] Property id must be a string"
|
|
188
|
-
`);
|
|
189
|
-
});
|
|
190
|
-
it('should throw if any query is invalid, prefixing with relevant name', () => {
|
|
191
|
-
expect(() => (0, _validate.validateResourceQueries)([{
|
|
192
|
-
resource: 'me'
|
|
193
|
-
}, {
|
|
194
|
-
resource: 'indicators',
|
|
195
|
-
params: 'parameters'
|
|
196
|
-
}, {
|
|
197
|
-
resource: 'me',
|
|
198
|
-
id: 42
|
|
199
|
-
}], ['me', 'inds'])).toThrowErrorMatchingInlineSnapshot(`
|
|
200
|
-
"Invalid query
|
|
201
|
-
- [inds] Property params must be an object
|
|
202
|
-
- [query#2] Property id must be a string"
|
|
203
|
-
`);
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
});
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _DataEngine = require("./DataEngine");
|
|
7
|
-
Object.keys(_DataEngine).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _DataEngine[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _DataEngine[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _DataEngineLink = require("./types/DataEngineLink");
|
|
18
|
-
Object.keys(_DataEngineLink).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _DataEngineLink[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _DataEngineLink[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _ExecuteOptions = require("./types/ExecuteOptions");
|
|
29
|
-
Object.keys(_ExecuteOptions).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _ExecuteOptions[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _ExecuteOptions[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
var _FetchError = require("./types/FetchError");
|
|
40
|
-
Object.keys(_FetchError).forEach(function (key) {
|
|
41
|
-
if (key === "default" || key === "__esModule") return;
|
|
42
|
-
if (key in exports && exports[key] === _FetchError[key]) return;
|
|
43
|
-
Object.defineProperty(exports, key, {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function () {
|
|
46
|
-
return _FetchError[key];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
var _JsonValue = require("./types/JsonValue");
|
|
51
|
-
Object.keys(_JsonValue).forEach(function (key) {
|
|
52
|
-
if (key === "default" || key === "__esModule") return;
|
|
53
|
-
if (key in exports && exports[key] === _JsonValue[key]) return;
|
|
54
|
-
Object.defineProperty(exports, key, {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function () {
|
|
57
|
-
return _JsonValue[key];
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
var _Mutation = require("./types/Mutation");
|
|
62
|
-
Object.keys(_Mutation).forEach(function (key) {
|
|
63
|
-
if (key === "default" || key === "__esModule") return;
|
|
64
|
-
if (key in exports && exports[key] === _Mutation[key]) return;
|
|
65
|
-
Object.defineProperty(exports, key, {
|
|
66
|
-
enumerable: true,
|
|
67
|
-
get: function () {
|
|
68
|
-
return _Mutation[key];
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
var _PossiblyDynamic = require("./types/PossiblyDynamic");
|
|
73
|
-
Object.keys(_PossiblyDynamic).forEach(function (key) {
|
|
74
|
-
if (key === "default" || key === "__esModule") return;
|
|
75
|
-
if (key in exports && exports[key] === _PossiblyDynamic[key]) return;
|
|
76
|
-
Object.defineProperty(exports, key, {
|
|
77
|
-
enumerable: true,
|
|
78
|
-
get: function () {
|
|
79
|
-
return _PossiblyDynamic[key];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
var _Query = require("./types/Query");
|
|
84
|
-
Object.keys(_Query).forEach(function (key) {
|
|
85
|
-
if (key === "default" || key === "__esModule") return;
|
|
86
|
-
if (key in exports && exports[key] === _Query[key]) return;
|
|
87
|
-
Object.defineProperty(exports, key, {
|
|
88
|
-
enumerable: true,
|
|
89
|
-
get: function () {
|
|
90
|
-
return _Query[key];
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
var _QueryParameters = require("./types/QueryParameters");
|
|
95
|
-
Object.keys(_QueryParameters).forEach(function (key) {
|
|
96
|
-
if (key === "default" || key === "__esModule") return;
|
|
97
|
-
if (key in exports && exports[key] === _QueryParameters[key]) return;
|
|
98
|
-
Object.defineProperty(exports, key, {
|
|
99
|
-
enumerable: true,
|
|
100
|
-
get: function () {
|
|
101
|
-
return _QueryParameters[key];
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.FetchError = void 0;
|
|
7
|
-
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; }
|
|
8
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
9
|
-
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); }
|
|
10
|
-
class FetchError extends Error {
|
|
11
|
-
constructor(_ref) {
|
|
12
|
-
let {
|
|
13
|
-
message,
|
|
14
|
-
type,
|
|
15
|
-
details = {}
|
|
16
|
-
} = _ref;
|
|
17
|
-
super(message);
|
|
18
|
-
_defineProperty(this, "type", void 0);
|
|
19
|
-
_defineProperty(this, "details", void 0);
|
|
20
|
-
this.type = type;
|
|
21
|
-
this.details = details;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.FetchError = FetchError;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _FetchError = require("./FetchError");
|
|
4
|
-
describe('FetchError', () => {
|
|
5
|
-
it('should construct successfully', () => {
|
|
6
|
-
const message = 'this is a test';
|
|
7
|
-
const error = new _FetchError.FetchError({
|
|
8
|
-
message,
|
|
9
|
-
type: 'network'
|
|
10
|
-
});
|
|
11
|
-
expect(error.type).toBe('network');
|
|
12
|
-
expect(error.message).toBe(message);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.InvalidQueryError = void 0;
|
|
7
|
-
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; }
|
|
8
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
9
|
-
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); }
|
|
10
|
-
class InvalidQueryError extends Error {
|
|
11
|
-
constructor(errors) {
|
|
12
|
-
super(`Invalid query\n${errors.map(e => ' - ' + e).join('\n')}`);
|
|
13
|
-
_defineProperty(this, "type", 'invalid-query');
|
|
14
|
-
_defineProperty(this, "details", void 0);
|
|
15
|
-
this.details = errors;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.InvalidQueryError = InvalidQueryError;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.CustomDataLink = void 0;
|
|
7
|
-
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; }
|
|
8
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
9
|
-
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); }
|
|
10
|
-
class CustomDataLink {
|
|
11
|
-
constructor(customData) {
|
|
12
|
-
let {
|
|
13
|
-
failOnMiss = true,
|
|
14
|
-
loadForever = false
|
|
15
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
16
|
-
_defineProperty(this, "failOnMiss", void 0);
|
|
17
|
-
_defineProperty(this, "loadForever", void 0);
|
|
18
|
-
_defineProperty(this, "data", void 0);
|
|
19
|
-
this.data = customData;
|
|
20
|
-
this.failOnMiss = failOnMiss;
|
|
21
|
-
this.loadForever = loadForever;
|
|
22
|
-
}
|
|
23
|
-
async executeResourceQuery(type, query, options) {
|
|
24
|
-
if (this.loadForever) {
|
|
25
|
-
return new Promise(() => undefined);
|
|
26
|
-
}
|
|
27
|
-
const customResource = this.data[query.resource];
|
|
28
|
-
if (customResource === undefined) {
|
|
29
|
-
if (this.failOnMiss) {
|
|
30
|
-
throw new Error(`No data provided for resource type ${query.resource}!`);
|
|
31
|
-
}
|
|
32
|
-
return Promise.resolve(null);
|
|
33
|
-
}
|
|
34
|
-
switch (typeof customResource) {
|
|
35
|
-
case 'string':
|
|
36
|
-
case 'number':
|
|
37
|
-
case 'boolean':
|
|
38
|
-
case 'object':
|
|
39
|
-
return customResource;
|
|
40
|
-
case 'function':
|
|
41
|
-
{
|
|
42
|
-
const result = await customResource(type, query, options);
|
|
43
|
-
if (typeof result === 'undefined' && this.failOnMiss) {
|
|
44
|
-
throw new Error(`The custom function for resource ${query.resource} must always return a value but returned ${result}`);
|
|
45
|
-
}
|
|
46
|
-
return result || null;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.CustomDataLink = CustomDataLink;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _CustomDataLink = require("./CustomDataLink");
|
|
4
|
-
describe('CustomDataLink', () => {
|
|
5
|
-
it('Should return mocked resource', async () => {
|
|
6
|
-
const link = new _CustomDataLink.CustomDataLink({
|
|
7
|
-
foo: 'bar'
|
|
8
|
-
});
|
|
9
|
-
expect(link.executeResourceQuery('read', {
|
|
10
|
-
resource: 'foo'
|
|
11
|
-
}, {})).resolves.toBe('bar');
|
|
12
|
-
});
|
|
13
|
-
it('Should throw error on mock miss', async () => {
|
|
14
|
-
const link = new _CustomDataLink.CustomDataLink({
|
|
15
|
-
foo: 'bar'
|
|
16
|
-
});
|
|
17
|
-
expect(link.executeResourceQuery('read', {
|
|
18
|
-
resource: 'something'
|
|
19
|
-
}, {})).rejects.toMatchInlineSnapshot(`[Error: No data provided for resource type something!]`);
|
|
20
|
-
});
|
|
21
|
-
it('Should swallow miss error with failOnMiss=false', async () => {
|
|
22
|
-
const link = new _CustomDataLink.CustomDataLink({
|
|
23
|
-
foo: 'bar'
|
|
24
|
-
}, {
|
|
25
|
-
failOnMiss: false
|
|
26
|
-
});
|
|
27
|
-
expect(link.executeResourceQuery('read', {
|
|
28
|
-
resource: 'something'
|
|
29
|
-
}, {})).resolves.toBe(null);
|
|
30
|
-
});
|
|
31
|
-
it('Should resolve functional resource', async () => {
|
|
32
|
-
const link = new _CustomDataLink.CustomDataLink({
|
|
33
|
-
foo: async () => 'bar'
|
|
34
|
-
});
|
|
35
|
-
expect(link.executeResourceQuery('read', {
|
|
36
|
-
resource: 'foo'
|
|
37
|
-
}, {})).resolves.toBe('bar');
|
|
38
|
-
});
|
|
39
|
-
it('Should throw if resolves to undefined', async () => {
|
|
40
|
-
const link = new _CustomDataLink.CustomDataLink({
|
|
41
|
-
foo: async () => undefined
|
|
42
|
-
});
|
|
43
|
-
expect(link.executeResourceQuery('read', {
|
|
44
|
-
resource: 'foo'
|
|
45
|
-
}, {})).rejects.toMatchInlineSnapshot(`[Error: The custom function for resource foo must always return a value but returned undefined]`);
|
|
46
|
-
});
|
|
47
|
-
it('Should swallow functional miss if failOnMiss=false', async () => {
|
|
48
|
-
const link = new _CustomDataLink.CustomDataLink({
|
|
49
|
-
foo: async () => undefined
|
|
50
|
-
}, {
|
|
51
|
-
failOnMiss: false
|
|
52
|
-
});
|
|
53
|
-
expect(link.executeResourceQuery('read', {
|
|
54
|
-
resource: 'foo'
|
|
55
|
-
}, {})).resolves.toBe(null);
|
|
56
|
-
});
|
|
57
|
-
it('Should wait forever with loadForever=true', async () => {
|
|
58
|
-
jest.useFakeTimers();
|
|
59
|
-
const link = new _CustomDataLink.CustomDataLink({}, {
|
|
60
|
-
loadForever: true
|
|
61
|
-
});
|
|
62
|
-
let done = false;
|
|
63
|
-
link.executeResourceQuery('read', {
|
|
64
|
-
resource: 'foo'
|
|
65
|
-
}, {}).then(() => {
|
|
66
|
-
done = true;
|
|
67
|
-
}).catch(() => {
|
|
68
|
-
done = true;
|
|
69
|
-
});
|
|
70
|
-
jest.advanceTimersByTime(100);
|
|
71
|
-
expect(done).toBe(false);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ErrorLink = void 0;
|
|
7
|
-
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; }
|
|
8
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
9
|
-
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); }
|
|
10
|
-
class ErrorLink {
|
|
11
|
-
constructor(errorMessage) {
|
|
12
|
-
_defineProperty(this, "errorMessage", void 0);
|
|
13
|
-
this.errorMessage = errorMessage;
|
|
14
|
-
}
|
|
15
|
-
executeResourceQuery() {
|
|
16
|
-
console.error(this.errorMessage);
|
|
17
|
-
return Promise.reject(this.errorMessage);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.ErrorLink = ErrorLink;
|