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