@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.
Files changed (180) hide show
  1. package/build/cjs/__tests__/integration.test.js +10 -16
  2. package/build/cjs/__tests__/mutations.test.js +5 -8
  3. package/build/cjs/index.js +16 -44
  4. package/build/cjs/react/components/CustomDataProvider.js +9 -11
  5. package/build/cjs/react/components/DataMutation.js +7 -8
  6. package/build/cjs/react/components/DataProvider.js +3 -4
  7. package/build/cjs/react/components/DataProvider.test.js +3 -4
  8. package/build/cjs/react/components/DataQuery.js +8 -9
  9. package/build/cjs/react/components/index.js +33 -0
  10. package/build/cjs/react/context/DataContext.js +2 -2
  11. package/build/cjs/react/context/defaultDataContext.js +13 -0
  12. package/build/cjs/react/context/{defaultContext.test.js → defaultDataContext.test.js} +3 -3
  13. package/build/cjs/react/hooks/index.js +26 -0
  14. package/build/cjs/react/hooks/useDataMutation.js +6 -7
  15. package/build/cjs/react/hooks/useDataMutation.test.js +44 -71
  16. package/build/cjs/react/hooks/useDataQuery.js +10 -14
  17. package/build/cjs/react/hooks/useDataQuery.test.js +172 -265
  18. package/build/cjs/react/hooks/useQueryExecutor.js +11 -13
  19. package/build/cjs/react/hooks/useQueryExecutor.test.js +12 -16
  20. package/build/cjs/react/hooks/useStaticInput.js +4 -5
  21. package/build/cjs/react/hooks/useStaticInput.test.js +24 -39
  22. package/build/cjs/react/index.js +22 -77
  23. package/build/es/__tests__/integration.test.js +10 -16
  24. package/build/es/__tests__/mutations.test.js +5 -8
  25. package/build/es/index.js +2 -3
  26. package/build/es/react/components/CustomDataProvider.js +7 -9
  27. package/build/es/react/components/DataMutation.js +7 -8
  28. package/build/es/react/components/DataProvider.js +1 -2
  29. package/build/es/react/components/DataProvider.test.js +1 -2
  30. package/build/es/react/components/DataQuery.js +8 -9
  31. package/build/es/react/components/index.js +4 -0
  32. package/build/es/react/context/DataContext.js +2 -2
  33. package/build/es/react/context/{defaultContext.js → defaultDataContext.js} +2 -3
  34. package/build/es/react/context/{defaultContext.test.js → defaultDataContext.test.js} +3 -3
  35. package/build/es/react/hooks/index.js +3 -0
  36. package/build/es/react/hooks/useDataMutation.js +6 -7
  37. package/build/es/react/hooks/useDataMutation.test.js +44 -71
  38. package/build/es/react/hooks/useDataQuery.js +10 -14
  39. package/build/es/react/hooks/useDataQuery.test.js +172 -265
  40. package/build/es/react/hooks/useQueryExecutor.js +10 -12
  41. package/build/es/react/hooks/useQueryExecutor.test.js +12 -16
  42. package/build/es/react/hooks/useStaticInput.js +4 -5
  43. package/build/es/react/hooks/useStaticInput.test.js +24 -39
  44. package/build/es/react/index.js +3 -11
  45. package/build/types/index.d.ts +2 -3
  46. package/build/types/react/components/CustomDataProvider.d.ts +1 -1
  47. package/build/types/react/components/DataMutation.d.ts +1 -1
  48. package/build/types/react/components/DataQuery.d.ts +1 -1
  49. package/build/types/react/components/index.d.ts +4 -0
  50. package/build/types/react/context/defaultDataContext.d.ts +4 -0
  51. package/build/types/react/hooks/index.d.ts +3 -0
  52. package/build/types/react/hooks/mergeAndCompareVariables.d.ts +1 -1
  53. package/build/types/react/hooks/useDataEngine.d.ts +1 -1
  54. package/build/types/react/hooks/useDataMutation.d.ts +1 -1
  55. package/build/types/react/hooks/useDataQuery.d.ts +1 -1
  56. package/build/types/react/index.d.ts +2 -11
  57. package/build/types/types.d.ts +2 -7
  58. package/package.json +4 -3
  59. package/build/cjs/engine/DataEngine.js +0 -73
  60. package/build/cjs/engine/DataEngine.test.js +0 -156
  61. package/build/cjs/engine/helpers/getMutationFetchType.js +0 -8
  62. package/build/cjs/engine/helpers/getMutationFetchType.test.js +0 -39
  63. package/build/cjs/engine/helpers/resolveDynamicQuery.js +0 -21
  64. package/build/cjs/engine/helpers/resolveDynamicQuery.test.js +0 -63
  65. package/build/cjs/engine/helpers/validate.js +0 -62
  66. package/build/cjs/engine/helpers/validate.test.js +0 -206
  67. package/build/cjs/engine/index.js +0 -104
  68. package/build/cjs/engine/types/DataEngineLink.js +0 -1
  69. package/build/cjs/engine/types/ExecuteOptions.js +0 -1
  70. package/build/cjs/engine/types/FetchError.js +0 -24
  71. package/build/cjs/engine/types/FetchError.test.js +0 -14
  72. package/build/cjs/engine/types/InvalidQueryError.js +0 -18
  73. package/build/cjs/engine/types/JsonValue.js +0 -1
  74. package/build/cjs/engine/types/Mutation.js +0 -1
  75. package/build/cjs/engine/types/PossiblyDynamic.js +0 -1
  76. package/build/cjs/engine/types/Query.js +0 -1
  77. package/build/cjs/engine/types/QueryParameters.js +0 -1
  78. package/build/cjs/links/CustomDataLink.js +0 -51
  79. package/build/cjs/links/CustomDataLink.test.js +0 -73
  80. package/build/cjs/links/ErrorLink.js +0 -20
  81. package/build/cjs/links/RestAPILink/fetchData.js +0 -80
  82. package/build/cjs/links/RestAPILink/fetchData.test.js +0 -132
  83. package/build/cjs/links/RestAPILink/metadataResources.js +0 -22
  84. package/build/cjs/links/RestAPILink/path.js +0 -14
  85. package/build/cjs/links/RestAPILink/path.test.js +0 -16
  86. package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +0 -58
  87. package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.test.js +0 -73
  88. package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.js +0 -80
  89. package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +0 -120
  90. package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +0 -170
  91. package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.test.js +0 -246
  92. package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +0 -14
  93. package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.test.js +0 -20
  94. package/build/cjs/links/RestAPILink/queryToRequestOptions.js +0 -34
  95. package/build/cjs/links/RestAPILink/queryToRequestOptions.test.js +0 -107
  96. package/build/cjs/links/RestAPILink/queryToResourcePath.js +0 -82
  97. package/build/cjs/links/RestAPILink/queryToResourcePath.test.js +0 -173
  98. package/build/cjs/links/RestAPILink/validateQuery.js +0 -59
  99. package/build/cjs/links/RestAPILink/validateQuery.test.js +0 -209
  100. package/build/cjs/links/RestAPILink.js +0 -33
  101. package/build/cjs/links/RestAPILink.test.js +0 -21
  102. package/build/cjs/links/index.js +0 -38
  103. package/build/cjs/locales/en/translations.json +0 -3
  104. package/build/cjs/locales/index.js +0 -21
  105. package/build/cjs/react/context/defaultContext.js +0 -14
  106. package/build/es/engine/DataEngine.js +0 -66
  107. package/build/es/engine/DataEngine.test.js +0 -154
  108. package/build/es/engine/helpers/getMutationFetchType.js +0 -1
  109. package/build/es/engine/helpers/getMutationFetchType.test.js +0 -37
  110. package/build/es/engine/helpers/resolveDynamicQuery.js +0 -14
  111. package/build/es/engine/helpers/resolveDynamicQuery.test.js +0 -61
  112. package/build/es/engine/helpers/validate.js +0 -53
  113. package/build/es/engine/helpers/validate.test.js +0 -204
  114. package/build/es/engine/index.js +0 -10
  115. package/build/es/engine/types/DataEngineLink.js +0 -1
  116. package/build/es/engine/types/ExecuteOptions.js +0 -1
  117. package/build/es/engine/types/FetchError.js +0 -17
  118. package/build/es/engine/types/FetchError.test.js +0 -12
  119. package/build/es/engine/types/InvalidQueryError.js +0 -11
  120. package/build/es/engine/types/JsonValue.js +0 -1
  121. package/build/es/engine/types/Mutation.js +0 -1
  122. package/build/es/engine/types/PossiblyDynamic.js +0 -1
  123. package/build/es/engine/types/Query.js +0 -1
  124. package/build/es/engine/types/QueryParameters.js +0 -1
  125. package/build/es/links/CustomDataLink.js +0 -44
  126. package/build/es/links/CustomDataLink.test.js +0 -71
  127. package/build/es/links/ErrorLink.js +0 -13
  128. package/build/es/links/RestAPILink/fetchData.js +0 -71
  129. package/build/es/links/RestAPILink/fetchData.test.js +0 -130
  130. package/build/es/links/RestAPILink/metadataResources.js +0 -16
  131. package/build/es/links/RestAPILink/path.js +0 -7
  132. package/build/es/links/RestAPILink/path.test.js +0 -14
  133. package/build/es/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +0 -47
  134. package/build/es/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.test.js +0 -71
  135. package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.js +0 -70
  136. package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +0 -118
  137. package/build/es/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +0 -151
  138. package/build/es/links/RestAPILink/queryToRequestOptions/textPlainMatchers.test.js +0 -244
  139. package/build/es/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +0 -7
  140. package/build/es/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.test.js +0 -18
  141. package/build/es/links/RestAPILink/queryToRequestOptions.js +0 -27
  142. package/build/es/links/RestAPILink/queryToRequestOptions.test.js +0 -105
  143. package/build/es/links/RestAPILink/queryToResourcePath.js +0 -75
  144. package/build/es/links/RestAPILink/queryToResourcePath.test.js +0 -171
  145. package/build/es/links/RestAPILink/validateQuery.js +0 -52
  146. package/build/es/links/RestAPILink/validateQuery.test.js +0 -207
  147. package/build/es/links/RestAPILink.js +0 -26
  148. package/build/es/links/RestAPILink.test.js +0 -19
  149. package/build/es/links/index.js +0 -4
  150. package/build/es/locales/en/translations.json +0 -3
  151. package/build/es/locales/index.js +0 -13
  152. package/build/types/engine/DataEngine.d.ts +0 -13
  153. package/build/types/engine/helpers/getMutationFetchType.d.ts +0 -3
  154. package/build/types/engine/helpers/resolveDynamicQuery.d.ts +0 -2
  155. package/build/types/engine/helpers/validate.d.ts +0 -4
  156. package/build/types/engine/index.d.ts +0 -9
  157. package/build/types/engine/types/DataEngineLink.d.ts +0 -9
  158. package/build/types/engine/types/ExecuteOptions.d.ts +0 -9
  159. package/build/types/engine/types/FetchError.d.ts +0 -19
  160. package/build/types/engine/types/InvalidQueryError.d.ts +0 -5
  161. package/build/types/engine/types/JsonValue.d.ts +0 -6
  162. package/build/types/engine/types/Mutation.d.ts +0 -29
  163. package/build/types/engine/types/PossiblyDynamic.d.ts +0 -1
  164. package/build/types/engine/types/Query.d.ts +0 -24
  165. package/build/types/engine/types/QueryParameters.d.ts +0 -12
  166. package/build/types/links/CustomDataLink.d.ts +0 -17
  167. package/build/types/links/ErrorLink.d.ts +0 -6
  168. package/build/types/links/RestAPILink/fetchData.d.ts +0 -4
  169. package/build/types/links/RestAPILink/metadataResources.d.ts +0 -2
  170. package/build/types/links/RestAPILink/path.d.ts +0 -1
  171. package/build/types/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.d.ts +0 -6
  172. package/build/types/links/RestAPILink/queryToRequestOptions/requestContentType.d.ts +0 -6
  173. package/build/types/links/RestAPILink/queryToRequestOptions/textPlainMatchers.d.ts +0 -14
  174. package/build/types/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.d.ts +0 -2
  175. package/build/types/links/RestAPILink/queryToRequestOptions.d.ts +0 -2
  176. package/build/types/links/RestAPILink/queryToResourcePath.d.ts +0 -3
  177. package/build/types/links/RestAPILink/validateQuery.d.ts +0 -2
  178. package/build/types/links/RestAPILink.d.ts +0 -10
  179. package/build/types/links/index.d.ts +0 -3
  180. package/build/types/react/context/defaultContext.d.ts +0 -4
@@ -1,151 +0,0 @@
1
- /*
2
- * Requests that expect a "text/plain" Content-Type have been collected by scanning
3
- * the developer documentation:
4
- * https://docs.dhis2.org/master/en/developer/html/dhis2_developer_manual_full.html
5
- *
6
- * Note that currently it is not allowed to include an id property on a "create"
7
- * mutation object. This means that currently the `id` will always be included in
8
- * the resource property (string). If we decide to allow the `id` property for
9
- * "create" mutation-objects, we will have to include additional checks below.
10
- */
11
-
12
- // POST to `messageConversations/${id}` (reply to a messagConversation)
13
- export const isReplyToMessageConversation = (type, _ref) => {
14
- let {
15
- resource
16
- } = _ref;
17
- const pattern = /^messageConversations\/[a-zA-Z0-9]{11}$/;
18
- return type === 'create' && pattern.test(resource);
19
- };
20
-
21
- // POST to 'messageConversations/feedback' (create a feedback message)
22
- export const isCreateFeedbackMessage = (type, _ref2) => {
23
- let {
24
- resource
25
- } = _ref2;
26
- return type === 'create' && resource === 'messageConversations/feedback';
27
- };
28
-
29
- // POST `interpretations/${objectType}/${id}` (add an interpretation to a visualization)
30
- export const isCreateInterpretation = (type, _ref3) => {
31
- let {
32
- resource
33
- } = _ref3;
34
- const pattern = /^interpretations\/(?:reportTable|chart|visualization|map|eventVisualization|eventReport|eventChart|dataSetReport)\/[a-zA-Z0-9]{11}$/;
35
- return type === 'create' && pattern.test(resource);
36
- };
37
-
38
- // PUT to `interpretations/${id}` (update an interpretation)
39
- export const isUpdateInterpretation = (type, _ref4) => {
40
- let {
41
- resource,
42
- id
43
- } = _ref4;
44
- if (type !== 'replace') {
45
- return false;
46
- }
47
- let resourcePattern;
48
- if (id) {
49
- resourcePattern = /^interpretations$/;
50
- const idPattern = /^[a-zA-Z0-9]{11}$/;
51
- return resourcePattern.test(resource) && idPattern.test(id);
52
- }
53
- resourcePattern = /^interpretations\/[a-zA-Z0-9]{11}$/;
54
- return resourcePattern.test(resource);
55
- };
56
-
57
- // POST to `interpretations/${id}/comments` (comment on an interpretation)
58
- export const isCommentOnInterpretation = (type, _ref5) => {
59
- let {
60
- resource
61
- } = _ref5;
62
- const pattern = /^interpretations\/[a-zA-Z0-9]{11}\/comments$/;
63
- return type === 'create' && pattern.test(resource);
64
- };
65
-
66
- // PUT to `interpretations/${interpretationId}/comments/${commentId}`
67
- // (update an interpretation comment)
68
- export const isInterpretationCommentUpdate = (type, _ref6) => {
69
- let {
70
- resource,
71
- id
72
- } = _ref6;
73
- if (type !== 'replace') {
74
- return false;
75
- }
76
- if (id) {
77
- const idPatternLong = /^[a-zA-Z0-9]{11}\/comments\/[a-zA-Z0-9]{11}$/;
78
- const idPatternShort = /^[a-zA-Z0-9]{11}$/;
79
- const resourcePattern = /^interpretations\/[a-zA-Z0-9]{11}\/comments$/;
80
- return resource === 'interpretations' && idPatternLong.test(id) || resourcePattern.test(resource) && idPatternShort.test(id);
81
- }
82
- const pattern = /^interpretations\/[a-zA-Z0-9]{11}\/comments\/[a-zA-Z0-9]{11}$/;
83
- return pattern.test(resource);
84
- };
85
-
86
- // POST to `systemSettings/${settingKey}` or `userSettings/${settingKey}`
87
- // (add or update a single system or user setting)
88
- export const isAddOrUpdateSystemOrUserSetting = (type, _ref7) => {
89
- let {
90
- resource
91
- } = _ref7;
92
- // At least 4 chars because the all start with 'key' (i.e. keyStyle)
93
- const pattern = /^(?:systemSettings|userSettings)\/[a-zA-Z]{4,}$/;
94
- return type === 'create' && pattern.test(resource);
95
- };
96
-
97
- // POST to `configuration/${configurationProperty}`
98
- // (add or update a single configuration property)
99
- export const addOrUpdateConfigurationProperty = (type, _ref8) => {
100
- let {
101
- resource
102
- } = _ref8;
103
- // NOTE: The corsWhitelist property does expect "application/json"
104
- const pattern = /^(configuration)\/([a-zA-Z]{1,50})$/;
105
- const match = resource.match(pattern);
106
- return type === 'create' && !!match && match[2] !== 'corsWhitelist';
107
- };
108
-
109
- // POST to 'synchronization/metadataPull' (install a metadata package)
110
- export const isMetadataPackageInstallation = (type, _ref9) => {
111
- let {
112
- resource
113
- } = _ref9;
114
- return type === 'create' && resource === 'synchronization/metadataPull';
115
- };
116
-
117
- // POST to '*/expression/description', (indicators,programIndicators,validationRules,predictors) (validate an expression)
118
- export const isExpressionDescriptionValidation = (type, _ref0) => {
119
- let {
120
- resource
121
- } = _ref0;
122
- const pattern = /^(indicators|programIndicators|validationRules|predictors)\/expression\/description$/;
123
- return type === 'create' && pattern.test(resource);
124
- };
125
-
126
- // POST to 'programIndicator/filter/description' (validate a filter)
127
- export const isFilterDescriptionValidation = (type, _ref1) => {
128
- let {
129
- resource
130
- } = _ref1;
131
- const pattern = /^programIndicators\/filter\/description$/;
132
- return type === 'create' && pattern.test(resource);
133
- };
134
-
135
- // POST to 'predictors/skipTest/description' (validate a filter)
136
- export const isSkipTestDescriptionValid = (type, _ref10) => {
137
- let {
138
- resource
139
- } = _ref10;
140
- const pattern = /^predictors\/skipTest\/description$/;
141
- return type === 'create' && pattern.test(resource);
142
- };
143
-
144
- // POST to 'programRules/condition/description' (validate a program rule condition)
145
- export const isConditionDescriptionValidation = (type, _ref11) => {
146
- let {
147
- resource
148
- } = _ref11;
149
- const pattern = /^programRules\/condition\/description$/;
150
- return type === 'create' && pattern.test(resource);
151
- };
@@ -1,244 +0,0 @@
1
- import { isReplyToMessageConversation, isCreateFeedbackMessage, isCreateInterpretation, isUpdateInterpretation, isCommentOnInterpretation, isInterpretationCommentUpdate, isAddOrUpdateSystemOrUserSetting, addOrUpdateConfigurationProperty, isMetadataPackageInstallation, isExpressionDescriptionValidation, isFilterDescriptionValidation, isSkipTestDescriptionValid, isConditionDescriptionValidation } from './textPlainMatchers';
2
- describe('isReplyToMessageConversation', () => {
3
- it('retuns true for POST to `messageConversations/${id}`', () => {
4
- expect(isReplyToMessageConversation('create', {
5
- resource: 'messageConversations/oXD88WWSQpR'
6
- })).toBe(true);
7
- });
8
- it('retuns false for a POST to a different resource', () => {
9
- expect(isReplyToMessageConversation('create', {
10
- resource: 'test/oXD88WWSQpR'
11
- })).toBe(false);
12
- });
13
- });
14
- describe('isCreateFeedbackMessage', () => {
15
- it('returns true for a POST to "messageConversations/feedback"', () => {
16
- expect(isCreateFeedbackMessage('create', {
17
- resource: 'messageConversations/feedback'
18
- })).toBe(true);
19
- });
20
- it('retuns false for a POST to a different resource', () => {
21
- expect(isCreateFeedbackMessage('create', {
22
- resource: 'messageConversations/somethingelse'
23
- })).toBe(false);
24
- });
25
- });
26
- describe('isCreateInterpretation', () => {
27
- it('returns true for a POST to "interpretations/chart/${id}"', () => {
28
- expect(isCreateInterpretation('create', {
29
- resource: 'interpretations/chart/oXD88WWSQpR'
30
- })).toBe(true);
31
- });
32
- it('returns false for a PUT to "interpretations/chart/${id}"', () => {
33
- expect(isCreateInterpretation('replace', {
34
- resource: 'interpretations/chart/oXD88WWSQpR'
35
- })).toBe(false);
36
- });
37
- it('retuns false for PATCH requests with a valid query', () => {
38
- expect(isCreateInterpretation('update', {
39
- resource: 'interpretations/chart/oXD88WWSQpR'
40
- })).toBe(false);
41
- });
42
- it('returns false for a request to a different resource', () => {
43
- expect(isCreateInterpretation('create', {
44
- resource: 'interpretations/dummy/oXD88WWSQpR'
45
- })).toBe(false);
46
- });
47
- });
48
- describe('isUpdateInterpretation', () => {
49
- it('returns true for a PUT to "interpretations/${id}"', () => {
50
- expect(isUpdateInterpretation('replace', {
51
- resource: 'interpretations/oXD88WWSQpR'
52
- })).toBe(true);
53
- });
54
- it('returns true for PUT with populated query.id', () => {
55
- expect(isUpdateInterpretation('replace', {
56
- resource: 'interpretations',
57
- id: 'oXD88WWSQpR'
58
- })).toBe(true);
59
- });
60
- it('returns false for a POST to "interpretations/${id}"', () => {
61
- expect(isUpdateInterpretation('create', {
62
- resource: 'interpretations/oXD88WWSQpR'
63
- })).toBe(false);
64
- });
65
- it('returns false for a PATCH to "interpretations/${id}"', () => {
66
- expect(isUpdateInterpretation('update', {
67
- resource: 'interpretations/oXD88WWSQpR'
68
- })).toBe(false);
69
- });
70
- it('returns false for PATCH with populated query.id', () => {
71
- expect(isUpdateInterpretation('update', {
72
- resource: 'interpretations',
73
- id: 'oXD88WWSQpR'
74
- })).toBe(false);
75
- });
76
- it('returns false for a request to a different resource', () => {
77
- expect(isUpdateInterpretation('create', {
78
- resource: 'interpretations/dummy/oXD88WWSQpR'
79
- })).toBe(false);
80
- });
81
- });
82
- describe('isCommentOnInterpretation', () => {
83
- it('retuns true for POST to `interpretations/${id}/comments`', () => {
84
- expect(isCommentOnInterpretation('create', {
85
- resource: 'interpretations/oXD88WWSQpR/comments'
86
- })).toBe(true);
87
- });
88
- it('retuns false for a POST to a different resource', () => {
89
- expect(isCommentOnInterpretation('create', {
90
- resource: 'test/oXD88WWSQpR/comments'
91
- })).toBe(false);
92
- });
93
- });
94
- describe('isInterpretationCommentUpdate', () => {
95
- it('returns true for a PUT to `interpretations/${interpretationId}/comments/${commentId}`', () => {
96
- expect(isInterpretationCommentUpdate('replace', {
97
- resource: 'interpretations/oXD88WWSQpR/comments/oXD88WWSQpR'
98
- })).toBe(true);
99
- });
100
- it('returns true for PUT with populated query.id', () => {
101
- expect(isInterpretationCommentUpdate('replace', {
102
- resource: 'interpretations',
103
- id: 'oXD88WWSQpR/comments/oXD88WWSQpR'
104
- })).toBe(true);
105
- expect(isInterpretationCommentUpdate('replace', {
106
- resource: 'interpretations/oXD88WWSQpR/comments',
107
- id: 'oXD88WWSQpR'
108
- })).toBe(true);
109
- });
110
- it('retuns false for PATCH requests with a valid query', () => {
111
- expect(isInterpretationCommentUpdate('update', {
112
- resource: 'interpretations/oXD88WWSQpR/comments/oXD88WWSQpR'
113
- })).toBe(false);
114
- });
115
- it('returns false for a request to a different resource', () => {
116
- expect(isInterpretationCommentUpdate('create', {
117
- resource: 'interpretations/oXD88WWSQpR/dummy/oXD88WWSQpR'
118
- })).toBe(false);
119
- });
120
- });
121
- describe('isAddOrUpdateSystemOrUserSetting', () => {
122
- it('retuns true for POST to `systemSettings/${settingKey}`', () => {
123
- expect(isAddOrUpdateSystemOrUserSetting('create', {
124
- resource: 'systemSettings/keyWhatever'
125
- })).toBe(true);
126
- });
127
- it('retuns true for POST to `userSettings/${settingKey}`', () => {
128
- expect(isAddOrUpdateSystemOrUserSetting('create', {
129
- resource: 'userSettings/keyWhatever'
130
- })).toBe(true);
131
- });
132
- it('retuns false for a POST to a different resource', () => {
133
- expect(isAddOrUpdateSystemOrUserSetting('create', {
134
- resource: 'test/keyWhatever'
135
- })).toBe(false);
136
- });
137
- });
138
- describe('addOrUpdateConfigurationProperty', () => {
139
- it('retuns true for POST to `configuration/${property}`', () => {
140
- expect(addOrUpdateConfigurationProperty('create', {
141
- resource: 'configuration/whatever'
142
- })).toBe(true);
143
- });
144
- it('retuns false for POST to `configuration/corsWhitelist`, which needs "application/json"', () => {
145
- expect(addOrUpdateConfigurationProperty('create', {
146
- resource: 'configuration/corsWhitelist'
147
- })).toBe(false);
148
- });
149
- it('retuns false for a POST to a different resource', () => {
150
- expect(addOrUpdateConfigurationProperty('create', {
151
- resource: 'test/whatever'
152
- })).toBe(false);
153
- });
154
- });
155
- describe('isMetadataPackageInstallation', () => {
156
- it('returns true for a POST to "synchronization/metadataPull"', () => {
157
- expect(isMetadataPackageInstallation('create', {
158
- resource: 'synchronization/metadataPull'
159
- })).toBe(true);
160
- });
161
- it('retuns false for a POST to a different resource', () => {
162
- expect(isMetadataPackageInstallation('create', {
163
- resource: 'synchronization/somethingelse'
164
- })).toBe(false);
165
- });
166
- });
167
- describe('isExpressionDescriptionValidation', () => {
168
- it('returns true for a POST to "indicators/expression/description"', () => {
169
- expect(isExpressionDescriptionValidation('create', {
170
- resource: 'indicators/expression/description'
171
- })).toBe(true);
172
- });
173
- it('retuns false for a POST to a different resource', () => {
174
- expect(isExpressionDescriptionValidation('create', {
175
- resource: 'indicators/expression/somethingelse'
176
- })).toBe(false);
177
- });
178
- it('returns true for a POST to "programIndicators/expression/description"', () => {
179
- expect(isExpressionDescriptionValidation('create', {
180
- resource: 'programIndicators/expression/description'
181
- })).toBe(true);
182
- });
183
- it('retuns false for a POST to a different resource', () => {
184
- expect(isExpressionDescriptionValidation('create', {
185
- resource: 'programIndicators/expression/somethingelse'
186
- })).toBe(false);
187
- });
188
- it('returns true for a POST to "validationRules/expression/description"', () => {
189
- expect(isExpressionDescriptionValidation('create', {
190
- resource: 'validationRules/expression/description'
191
- })).toBe(true);
192
- });
193
- it('retuns false for a POST to a different validationRules resource', () => {
194
- expect(isExpressionDescriptionValidation('create', {
195
- resource: 'validationRules/expression/somethingelse'
196
- })).toBe(false);
197
- });
198
- it('returns true for a POST to "predictors/expression/description"', () => {
199
- expect(isExpressionDescriptionValidation('create', {
200
- resource: 'predictors/expression/description'
201
- })).toBe(true);
202
- });
203
- it('retuns false for a POST to a different predictors resource', () => {
204
- expect(isExpressionDescriptionValidation('create', {
205
- resource: 'predictors/expression/somethingelse'
206
- })).toBe(false);
207
- });
208
- });
209
- describe('isFilterDescriptionValidation', () => {
210
- it('returns true for a POST to "programIndicators/filter/description"', () => {
211
- expect(isFilterDescriptionValidation('create', {
212
- resource: 'programIndicators/filter/description'
213
- })).toBe(true);
214
- });
215
- it('retuns false for a POST to a different resource', () => {
216
- expect(isFilterDescriptionValidation('create', {
217
- resource: 'programIndicators/filter/somethingelse'
218
- })).toBe(false);
219
- });
220
- });
221
- describe('isSkipTestDescriptionValid', () => {
222
- it('returns true for a POST to "predictors/skipTest/description"', () => {
223
- expect(isSkipTestDescriptionValid('create', {
224
- resource: 'predictors/skipTest/description'
225
- })).toBe(true);
226
- });
227
- it('retuns false for a POST to a different resource', () => {
228
- expect(isSkipTestDescriptionValid('create', {
229
- resource: 'predictors/skipTest/somethingelse'
230
- })).toBe(false);
231
- });
232
- });
233
- describe('isConditionDescriptionValidation', () => {
234
- it('returns true for a POST to "programRules/condition/description"', () => {
235
- expect(isConditionDescriptionValidation('create', {
236
- resource: 'programRules/condition/description'
237
- })).toBe(true);
238
- });
239
- it('retuns false for a POST to a different resource', () => {
240
- expect(isConditionDescriptionValidation('create', {
241
- resource: 'programRules/condition/somethingelse'
242
- })).toBe(false);
243
- });
244
- });
@@ -1,7 +0,0 @@
1
- // POST to convert an SVG file
2
- export const isSvgConversion = (type, _ref) => {
3
- let {
4
- resource
5
- } = _ref;
6
- return type === 'create' && (resource === 'svg.png' || resource === 'svg.pdf');
7
- };
@@ -1,18 +0,0 @@
1
- import { isSvgConversion } from './xWwwFormUrlencodedMatchers';
2
- describe('isSvgConversion', () => {
3
- it('returns true for a POST to "svg.png"', () => {
4
- expect(isSvgConversion('create', {
5
- resource: 'svg.png'
6
- })).toBe(true);
7
- });
8
- it('returns true for a POST to "svg.pdf"', () => {
9
- expect(isSvgConversion('create', {
10
- resource: 'svg.pdf'
11
- })).toBe(true);
12
- });
13
- it('retuns false for a POST to a different resource', () => {
14
- expect(isSvgConversion('create', {
15
- resource: 'notSvg'
16
- })).toBe(false);
17
- });
18
- });
@@ -1,27 +0,0 @@
1
- import { requestContentType, requestBodyForContentType, requestHeadersForContentType } from './queryToRequestOptions/requestContentType';
2
- const getMethod = type => {
3
- switch (type) {
4
- case 'create':
5
- return 'POST';
6
- case 'read':
7
- return 'GET';
8
- case 'update':
9
- case 'json-patch':
10
- return 'PATCH';
11
- case 'replace':
12
- return 'PUT';
13
- case 'delete':
14
- return 'DELETE';
15
- default:
16
- throw new Error(`Unknown type ${type}`);
17
- }
18
- };
19
- export const queryToRequestOptions = (type, query, signal) => {
20
- const contentType = requestContentType(type, query);
21
- return {
22
- method: getMethod(type),
23
- body: requestBodyForContentType(contentType, query),
24
- headers: requestHeadersForContentType(contentType),
25
- signal
26
- };
27
- };
@@ -1,105 +0,0 @@
1
- import { queryToRequestOptions } from './queryToRequestOptions';
2
- describe('queryToRequestOptions', () => {
3
- it('should return a valid Fetch option object for read request', () => {
4
- const options = queryToRequestOptions('read', {
5
- resource: 'test'
6
- });
7
- expect(options).toMatchInlineSnapshot(`
8
- Object {
9
- "body": undefined,
10
- "headers": undefined,
11
- "method": "GET",
12
- "signal": undefined,
13
- }
14
- `);
15
- });
16
- it('should return a valid Fetch option object for create request', () => {
17
- const options = queryToRequestOptions('create', {
18
- resource: 'test',
19
- data: {
20
- answer: 42,
21
- foo: 'bar'
22
- }
23
- });
24
- expect(options).toMatchInlineSnapshot(`
25
- Object {
26
- "body": "{\\"answer\\":42,\\"foo\\":\\"bar\\"}",
27
- "headers": Object {
28
- "Content-Type": "application/json",
29
- },
30
- "method": "POST",
31
- "signal": undefined,
32
- }
33
- `);
34
- });
35
- it('should return a valid Fetch option object for update request', () => {
36
- const options = queryToRequestOptions('update', {
37
- resource: 'test',
38
- data: {
39
- answer: 42,
40
- foo: 'bar'
41
- }
42
- });
43
- expect(options).toMatchInlineSnapshot(`
44
- Object {
45
- "body": "{\\"answer\\":42,\\"foo\\":\\"bar\\"}",
46
- "headers": Object {
47
- "Content-Type": "application/json",
48
- },
49
- "method": "PATCH",
50
- "signal": undefined,
51
- }
52
- `);
53
- });
54
- it('should return a valid Fetch option object for json-patch request', () => {
55
- const options = queryToRequestOptions('json-patch', {
56
- resource: 'test',
57
- data: {
58
- answer: 42,
59
- foo: 'bar'
60
- }
61
- });
62
- expect(options).toMatchInlineSnapshot(`
63
- Object {
64
- "body": "{\\"answer\\":42,\\"foo\\":\\"bar\\"}",
65
- "headers": Object {
66
- "Content-Type": "application/json-patch+json",
67
- },
68
- "method": "PATCH",
69
- "signal": undefined,
70
- }
71
- `);
72
- });
73
- it('should return a valid Fetch option object for replace request', () => {
74
- const options = queryToRequestOptions('replace', {
75
- resource: 'test',
76
- data: {
77
- answer: 42,
78
- foo: 'bar'
79
- }
80
- });
81
- expect(options).toMatchInlineSnapshot(`
82
- Object {
83
- "body": "{\\"answer\\":42,\\"foo\\":\\"bar\\"}",
84
- "headers": Object {
85
- "Content-Type": "application/json",
86
- },
87
- "method": "PUT",
88
- "signal": undefined,
89
- }
90
- `);
91
- });
92
- it('should return a valid Fetch option object for delete request', () => {
93
- const options = queryToRequestOptions('delete', {
94
- resource: 'test'
95
- });
96
- expect(options).toMatchInlineSnapshot(`
97
- Object {
98
- "body": undefined,
99
- "headers": undefined,
100
- "method": "DELETE",
101
- "signal": undefined,
102
- }
103
- `);
104
- });
105
- });
@@ -1,75 +0,0 @@
1
- import { joinPath } from './path';
2
- import { validateResourceQuery } from './validateQuery';
3
- const encodeQueryParameter = param => {
4
- if (Array.isArray(param)) {
5
- return param.map(encodeQueryParameter).join(',');
6
- }
7
- if (typeof param === 'string') {
8
- return encodeURIComponent(param);
9
- }
10
- if (typeof param === 'number' || typeof param === 'boolean') {
11
- return String(param);
12
- }
13
- if (typeof param === 'object') {
14
- throw new Error('Object parameter mappings not yet implemented');
15
- }
16
- throw new Error('Unknown parameter type');
17
- };
18
- const queryParametersMapToArray = params => Object.keys(params).reduce((out, key) => {
19
- const value = params[key];
20
- if (key === 'filter' && Array.isArray(value)) {
21
- value.forEach(item => {
22
- out.push({
23
- key: 'filter',
24
- value: item
25
- });
26
- });
27
- } else if (params[key] !== null && params[key] !== undefined) {
28
- out.push({
29
- key,
30
- value: params[key]
31
- });
32
- }
33
- return out;
34
- }, []);
35
- const queryParametersToQueryString = params => {
36
- const expandedParams = queryParametersMapToArray(params);
37
- return expandedParams.map(_ref => {
38
- let {
39
- key,
40
- value
41
- } = _ref;
42
- return `${encodeURIComponent(key)}=${encodeQueryParameter(value)}`;
43
- }).join('&');
44
- };
45
- const actionPrefix = 'action::';
46
- const isAction = resource => resource.startsWith(actionPrefix);
47
- const makeActionPath = resource => joinPath('dhis-web-commons', `${resource.substr(actionPrefix.length)}.action`);
48
- const skipApiVersion = (resource, config) => {
49
- if (resource === 'tracker' || resource.startsWith('tracker/')) {
50
- var _config$serverVersion, _config$serverVersion2;
51
- if (!((_config$serverVersion = config.serverVersion) !== null && _config$serverVersion !== void 0 && _config$serverVersion.minor) || ((_config$serverVersion2 = config.serverVersion) === null || _config$serverVersion2 === void 0 ? void 0 : _config$serverVersion2.minor) < 38) {
52
- return true;
53
- }
54
- }
55
-
56
- // The `/api/ping` endpoint is unversioned
57
- if (resource === 'ping') {
58
- return true;
59
- }
60
- return false;
61
- };
62
- export const queryToResourcePath = (link, query, type) => {
63
- const {
64
- resource,
65
- id,
66
- params = {}
67
- } = query;
68
- const apiBase = skipApiVersion(resource, link.config) ? link.unversionedApiPath : link.versionedApiPath;
69
- const base = isAction(resource) ? makeActionPath(resource) : joinPath(apiBase, resource, id);
70
- validateResourceQuery(query, type);
71
- if (Object.keys(params).length) {
72
- return `${base}?${queryParametersToQueryString(params)}`;
73
- }
74
- return base;
75
- };