@esri/solution-common 5.2.2 → 5.2.3

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 (205) hide show
  1. package/dist/esm/formHelpers.d.ts +41 -0
  2. package/dist/esm/formHelpers.js +71 -0
  3. package/dist/esm/formHelpers.js.map +1 -0
  4. package/dist/esm/generalHelpers.d.ts +23 -2
  5. package/dist/esm/generalHelpers.js +30 -3
  6. package/dist/esm/generalHelpers.js.map +1 -1
  7. package/dist/esm/index.d.ts +1 -0
  8. package/dist/esm/index.js +1 -0
  9. package/dist/esm/index.js.map +1 -1
  10. package/dist/esm/interfaces.d.ts +18 -0
  11. package/dist/esm/interfaces.js.map +1 -1
  12. package/dist/esm/templatization.js +5 -3
  13. package/dist/esm/templatization.js.map +1 -1
  14. package/dist/esm/workflowHelpers.js +2 -7
  15. package/dist/esm/workflowHelpers.js.map +1 -1
  16. package/dist/esm/zip-utils.d.ts +35 -24
  17. package/dist/esm/zip-utils.js +69 -47
  18. package/dist/esm/zip-utils.js.map +1 -1
  19. package/package.json +3 -3
  20. package/dist/cjs/completeItem.d.ts +0 -29
  21. package/dist/cjs/completeItem.js +0 -92
  22. package/dist/cjs/completeItem.js.map +0 -1
  23. package/dist/cjs/create-hub-request-options.d.ts +0 -29
  24. package/dist/cjs/create-hub-request-options.js +0 -64
  25. package/dist/cjs/create-hub-request-options.js.map +0 -1
  26. package/dist/cjs/deleteHelpers/deleteEmptyGroups.d.ts +0 -24
  27. package/dist/cjs/deleteHelpers/deleteEmptyGroups.js +0 -42
  28. package/dist/cjs/deleteHelpers/deleteEmptyGroups.js.map +0 -1
  29. package/dist/cjs/deleteHelpers/deleteGroupIfEmpty.d.ts +0 -27
  30. package/dist/cjs/deleteHelpers/deleteGroupIfEmpty.js +0 -97
  31. package/dist/cjs/deleteHelpers/deleteGroupIfEmpty.js.map +0 -1
  32. package/dist/cjs/deleteHelpers/deleteSolutionContents.d.ts +0 -38
  33. package/dist/cjs/deleteHelpers/deleteSolutionContents.js +0 -130
  34. package/dist/cjs/deleteHelpers/deleteSolutionContents.js.map +0 -1
  35. package/dist/cjs/deleteHelpers/deleteSolutionFolder.d.ts +0 -29
  36. package/dist/cjs/deleteHelpers/deleteSolutionFolder.js +0 -79
  37. package/dist/cjs/deleteHelpers/deleteSolutionFolder.js.map +0 -1
  38. package/dist/cjs/deleteHelpers/deleteSolutionItem.d.ts +0 -30
  39. package/dist/cjs/deleteHelpers/deleteSolutionItem.js +0 -54
  40. package/dist/cjs/deleteHelpers/deleteSolutionItem.js.map +0 -1
  41. package/dist/cjs/deleteHelpers/index.d.ts +0 -22
  42. package/dist/cjs/deleteHelpers/index.js +0 -26
  43. package/dist/cjs/deleteHelpers/index.js.map +0 -1
  44. package/dist/cjs/deleteHelpers/reconstructBuildOrderIds.d.ts +0 -27
  45. package/dist/cjs/deleteHelpers/reconstructBuildOrderIds.js +0 -34
  46. package/dist/cjs/deleteHelpers/reconstructBuildOrderIds.js.map +0 -1
  47. package/dist/cjs/deleteHelpers/removeItems.d.ts +0 -34
  48. package/dist/cjs/deleteHelpers/removeItems.js +0 -112
  49. package/dist/cjs/deleteHelpers/removeItems.js.map +0 -1
  50. package/dist/cjs/deleteHelpers/reportProgress.d.ts +0 -27
  51. package/dist/cjs/deleteHelpers/reportProgress.js +0 -46
  52. package/dist/cjs/deleteHelpers/reportProgress.js.map +0 -1
  53. package/dist/cjs/deleteSolution.d.ts +0 -55
  54. package/dist/cjs/deleteSolution.js +0 -107
  55. package/dist/cjs/deleteSolution.js.map +0 -1
  56. package/dist/cjs/dependencies.d.ts +0 -26
  57. package/dist/cjs/dependencies.js +0 -171
  58. package/dist/cjs/dependencies.js.map +0 -1
  59. package/dist/cjs/featureServiceHelpers.d.ts +0 -799
  60. package/dist/cjs/featureServiceHelpers.js +0 -2438
  61. package/dist/cjs/featureServiceHelpers.js.map +0 -1
  62. package/dist/cjs/generalHelpers.d.ts +0 -412
  63. package/dist/cjs/generalHelpers.js +0 -895
  64. package/dist/cjs/generalHelpers.js.map +0 -1
  65. package/dist/cjs/get-subscription-info.d.ts +0 -27
  66. package/dist/cjs/get-subscription-info.js +0 -39
  67. package/dist/cjs/get-subscription-info.js.map +0 -1
  68. package/dist/cjs/getDeletableSolutionInfo.d.ts +0 -29
  69. package/dist/cjs/getDeletableSolutionInfo.js +0 -53
  70. package/dist/cjs/getDeletableSolutionInfo.js.map +0 -1
  71. package/dist/cjs/getItemTypeAbbrev.d.ts +0 -19
  72. package/dist/cjs/getItemTypeAbbrev.js +0 -186
  73. package/dist/cjs/getItemTypeAbbrev.js.map +0 -1
  74. package/dist/cjs/getSolutionSummary.d.ts +0 -27
  75. package/dist/cjs/getSolutionSummary.js +0 -101
  76. package/dist/cjs/getSolutionSummary.js.map +0 -1
  77. package/dist/cjs/index.d.ts +0 -45
  78. package/dist/cjs/index.js +0 -49
  79. package/dist/cjs/index.js.map +0 -1
  80. package/dist/cjs/interfaces.d.ts +0 -1344
  81. package/dist/cjs/interfaces.js +0 -77
  82. package/dist/cjs/interfaces.js.map +0 -1
  83. package/dist/cjs/libConnectors.d.ts +0 -73
  84. package/dist/cjs/libConnectors.js +0 -115
  85. package/dist/cjs/libConnectors.js.map +0 -1
  86. package/dist/cjs/migrations/apply-schema.d.ts +0 -24
  87. package/dist/cjs/migrations/apply-schema.js +0 -36
  88. package/dist/cjs/migrations/apply-schema.js.map +0 -1
  89. package/dist/cjs/migrations/is-legacy-solution.d.ts +0 -24
  90. package/dist/cjs/migrations/is-legacy-solution.js +0 -40
  91. package/dist/cjs/migrations/is-legacy-solution.js.map +0 -1
  92. package/dist/cjs/migrations/upgrade-three-dot-one.d.ts +0 -27
  93. package/dist/cjs/migrations/upgrade-three-dot-one.js +0 -49
  94. package/dist/cjs/migrations/upgrade-three-dot-one.js.map +0 -1
  95. package/dist/cjs/migrations/upgrade-three-dot-zero.d.ts +0 -27
  96. package/dist/cjs/migrations/upgrade-three-dot-zero.js +0 -43
  97. package/dist/cjs/migrations/upgrade-three-dot-zero.js.map +0 -1
  98. package/dist/cjs/migrations/upgrade-two-dot-five.d.ts +0 -24
  99. package/dist/cjs/migrations/upgrade-two-dot-five.js +0 -73
  100. package/dist/cjs/migrations/upgrade-two-dot-five.js.map +0 -1
  101. package/dist/cjs/migrations/upgrade-two-dot-four.d.ts +0 -24
  102. package/dist/cjs/migrations/upgrade-two-dot-four.js +0 -72
  103. package/dist/cjs/migrations/upgrade-two-dot-four.js.map +0 -1
  104. package/dist/cjs/migrations/upgrade-two-dot-one.d.ts +0 -7
  105. package/dist/cjs/migrations/upgrade-two-dot-one.js +0 -39
  106. package/dist/cjs/migrations/upgrade-two-dot-one.js.map +0 -1
  107. package/dist/cjs/migrations/upgrade-two-dot-seven.d.ts +0 -23
  108. package/dist/cjs/migrations/upgrade-two-dot-seven.js +0 -58
  109. package/dist/cjs/migrations/upgrade-two-dot-seven.js.map +0 -1
  110. package/dist/cjs/migrations/upgrade-two-dot-six.d.ts +0 -27
  111. package/dist/cjs/migrations/upgrade-two-dot-six.js +0 -61
  112. package/dist/cjs/migrations/upgrade-two-dot-six.js.map +0 -1
  113. package/dist/cjs/migrations/upgrade-two-dot-three.d.ts +0 -23
  114. package/dist/cjs/migrations/upgrade-two-dot-three.js +0 -55
  115. package/dist/cjs/migrations/upgrade-two-dot-three.js.map +0 -1
  116. package/dist/cjs/migrations/upgrade-two-dot-two.d.ts +0 -23
  117. package/dist/cjs/migrations/upgrade-two-dot-two.js +0 -58
  118. package/dist/cjs/migrations/upgrade-two-dot-two.js.map +0 -1
  119. package/dist/cjs/migrations/upgrade-two-dot-zero.d.ts +0 -44
  120. package/dist/cjs/migrations/upgrade-two-dot-zero.js +0 -95
  121. package/dist/cjs/migrations/upgrade-two-dot-zero.js.map +0 -1
  122. package/dist/cjs/migrator.d.ts +0 -25
  123. package/dist/cjs/migrator.js +0 -77
  124. package/dist/cjs/migrator.js.map +0 -1
  125. package/dist/cjs/resourceHelpers.d.ts +0 -191
  126. package/dist/cjs/resourceHelpers.js +0 -384
  127. package/dist/cjs/resourceHelpers.js.map +0 -1
  128. package/dist/cjs/resources/add-resource-from-blob.d.ts +0 -26
  129. package/dist/cjs/resources/add-resource-from-blob.js +0 -52
  130. package/dist/cjs/resources/add-resource-from-blob.js.map +0 -1
  131. package/dist/cjs/resources/addMetadataFromBlob.d.ts +0 -25
  132. package/dist/cjs/resources/addMetadataFromBlob.js +0 -43
  133. package/dist/cjs/resources/addMetadataFromBlob.js.map +0 -1
  134. package/dist/cjs/resources/convert-item-resource-to-storage-resource.d.ts +0 -32
  135. package/dist/cjs/resources/convert-item-resource-to-storage-resource.js +0 -70
  136. package/dist/cjs/resources/convert-item-resource-to-storage-resource.js.map +0 -1
  137. package/dist/cjs/resources/convert-storage-resource-to-item-resource.d.ts +0 -29
  138. package/dist/cjs/resources/convert-storage-resource-to-item-resource.js +0 -70
  139. package/dist/cjs/resources/convert-storage-resource-to-item-resource.js.map +0 -1
  140. package/dist/cjs/resources/copyAssociatedFiles.d.ts +0 -67
  141. package/dist/cjs/resources/copyAssociatedFiles.js +0 -304
  142. package/dist/cjs/resources/copyAssociatedFiles.js.map +0 -1
  143. package/dist/cjs/resources/copyDataIntoItem.d.ts +0 -33
  144. package/dist/cjs/resources/copyDataIntoItem.js +0 -62
  145. package/dist/cjs/resources/copyDataIntoItem.js.map +0 -1
  146. package/dist/cjs/resources/copyMetadataIntoItem.d.ts +0 -26
  147. package/dist/cjs/resources/copyMetadataIntoItem.js +0 -46
  148. package/dist/cjs/resources/copyMetadataIntoItem.js.map +0 -1
  149. package/dist/cjs/resources/copyResourceIntoZip.d.ts +0 -33
  150. package/dist/cjs/resources/copyResourceIntoZip.js +0 -78
  151. package/dist/cjs/resources/copyResourceIntoZip.js.map +0 -1
  152. package/dist/cjs/resources/copyZipIntoItem.d.ts +0 -25
  153. package/dist/cjs/resources/copyZipIntoItem.js +0 -54
  154. package/dist/cjs/resources/copyZipIntoItem.js.map +0 -1
  155. package/dist/cjs/resources/createCopyResults.d.ts +0 -25
  156. package/dist/cjs/resources/createCopyResults.js +0 -36
  157. package/dist/cjs/resources/createCopyResults.js.map +0 -1
  158. package/dist/cjs/resources/get-blob.d.ts +0 -26
  159. package/dist/cjs/resources/get-blob.js +0 -27
  160. package/dist/cjs/resources/get-blob.js.map +0 -1
  161. package/dist/cjs/resources/getItemResourcesFilesFromPaths.d.ts +0 -24
  162. package/dist/cjs/resources/getItemResourcesFilesFromPaths.js +0 -49
  163. package/dist/cjs/resources/getItemResourcesFilesFromPaths.js.map +0 -1
  164. package/dist/cjs/resources/getItemResourcesPaths.d.ts +0 -26
  165. package/dist/cjs/resources/getItemResourcesPaths.js +0 -76
  166. package/dist/cjs/resources/getItemResourcesPaths.js.map +0 -1
  167. package/dist/cjs/resources/index.d.ts +0 -29
  168. package/dist/cjs/resources/index.js +0 -33
  169. package/dist/cjs/resources/index.js.map +0 -1
  170. package/dist/cjs/resources/solution-resource.d.ts +0 -35
  171. package/dist/cjs/resources/solution-resource.js +0 -31
  172. package/dist/cjs/resources/solution-resource.js.map +0 -1
  173. package/dist/cjs/resources/transform-resource-paths-to-solution-resources.d.ts +0 -56
  174. package/dist/cjs/resources/transform-resource-paths-to-solution-resources.js +0 -146
  175. package/dist/cjs/resources/transform-resource-paths-to-solution-resources.js.map +0 -1
  176. package/dist/cjs/restHelpers.d.ts +0 -607
  177. package/dist/cjs/restHelpers.js +0 -1954
  178. package/dist/cjs/restHelpers.js.map +0 -1
  179. package/dist/cjs/restHelpersGet.d.ts +0 -288
  180. package/dist/cjs/restHelpersGet.js +0 -804
  181. package/dist/cjs/restHelpersGet.js.map +0 -1
  182. package/dist/cjs/sharing/index.d.ts +0 -16
  183. package/dist/cjs/sharing/index.js +0 -20
  184. package/dist/cjs/sharing/index.js.map +0 -1
  185. package/dist/cjs/sharing/share-item-to-groups.d.ts +0 -26
  186. package/dist/cjs/sharing/share-item-to-groups.js +0 -44
  187. package/dist/cjs/sharing/share-item-to-groups.js.map +0 -1
  188. package/dist/cjs/templatization.d.ts +0 -139
  189. package/dist/cjs/templatization.js +0 -314
  190. package/dist/cjs/templatization.js.map +0 -1
  191. package/dist/cjs/trackingHelpers.d.ts +0 -116
  192. package/dist/cjs/trackingHelpers.js +0 -217
  193. package/dist/cjs/trackingHelpers.js.map +0 -1
  194. package/dist/cjs/velocityHelpers.d.ts +0 -57
  195. package/dist/cjs/velocityHelpers.js +0 -135
  196. package/dist/cjs/velocityHelpers.js.map +0 -1
  197. package/dist/cjs/workflowHelpers.d.ts +0 -37
  198. package/dist/cjs/workflowHelpers.js +0 -82
  199. package/dist/cjs/workflowHelpers.js.map +0 -1
  200. package/dist/cjs/workforceHelpers.d.ts +0 -115
  201. package/dist/cjs/workforceHelpers.js +0 -749
  202. package/dist/cjs/workforceHelpers.js.map +0 -1
  203. package/dist/cjs/zip-utils.d.ts +0 -65
  204. package/dist/cjs/zip-utils.js +0 -118
  205. package/dist/cjs/zip-utils.js.map +0 -1
@@ -1,895 +0,0 @@
1
- "use strict";
2
- /** @license
3
- * Copyright 2018 Esri
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports._padPositiveNum = exports._getRandomNumberInRange = exports.regExTest = exports.getTemplateById = exports.cleanLayerId = exports.cleanLayerBasedItemId = exports.cleanItemId = exports.hasDatasource = exports.globalStringReplace = exports.getUniqueTitle = exports.hasTypeKeyword = exports.hasAnyKeyword = exports.getUTCTimestamp = exports.setProp = exports.setCreateProp = exports.idTest = exports.getPropWithDefault = exports.getProps = exports.getProp = exports.getIDs = exports.getSubgroupIds = exports.failWithIds = exports.fail = exports.deleteProps = exports.deleteProp = exports.deleteItemProps = exports.sanitizeJSONAndReportChanges = exports.compareJSONProperties = exports.compareJSONNoEmptyStrings = exports.compareJSON = exports.cloneObject = exports.saveBlobAsFile = exports.jsonToJson = exports.jsonToFile = exports.jsonToBlob = exports.getAgoIdTemplateRegEx = exports.getAgoIdRegEx = exports.generateEmptyCreationResponse = exports.dedupe = exports.createShortId = exports.createLongId = exports.convertIModel = exports.checkUrlPathTermination = exports.blobToText = exports.blobToFile = exports.blobToJson = exports.appendQueryParam = void 0;
19
- /**
20
- * Provides general helper functions.
21
- *
22
- * @module generalHelpers
23
- */
24
- const hub_common_1 = require("@esri/hub-common");
25
- const libConnectors_1 = require("./libConnectors");
26
- // ------------------------------------------------------------------------------------------------------------------ //
27
- /**
28
- * Returns a URL with a query parameter appended
29
- *
30
- * @param url URL to append to
31
- * @param parameter Query parameter to append, prefixed with "?" or "&" as appropriate to what url already has
32
- * @returns New URL combining url and parameter
33
- */
34
- function appendQueryParam(url, parameter) {
35
- return url + (url.indexOf("?") === -1 ? "?" : "&") + parameter;
36
- }
37
- exports.appendQueryParam = appendQueryParam;
38
- /**
39
- * Extracts JSON from a Blob.
40
- *
41
- * @param blob Blob to use as source
42
- * @returns A promise that will resolve with JSON or null
43
- */
44
- function blobToJson(blob) {
45
- return new Promise(resolve => {
46
- blobToText(blob).then(blobContents => {
47
- try {
48
- resolve(JSON.parse(blobContents));
49
- }
50
- catch (err) {
51
- resolve(null);
52
- }
53
- }, () => resolve(null));
54
- });
55
- }
56
- exports.blobToJson = blobToJson;
57
- /**
58
- * Converts a Blob to a File.
59
- *
60
- * @param blob Blob to use as source
61
- * @param filename Name to use for file
62
- * @param mimeType MIME type to override blob's MIME type
63
- * @returns File created out of Blob and filename
64
- */
65
- function blobToFile(blob, filename, mimeType) {
66
- return new File([blob], filename ? filename : "", {
67
- type: mimeType ?? blob.type // Blobs default to type=""
68
- });
69
- }
70
- exports.blobToFile = blobToFile;
71
- /**
72
- * Extracts text from a Blob.
73
- *
74
- * @param blob Blob to use as source
75
- * @returns A promise that will resolve with text read from blob
76
- */
77
- function blobToText(blob) {
78
- return new Promise(resolve => {
79
- const reader = new FileReader();
80
- reader.onload = function (evt) {
81
- // Disable needed because Node requires cast
82
- const blobContents = evt.target.result;
83
- resolve(blobContents ? blobContents : ""); // not handling ArrayContents variant
84
- };
85
- reader.readAsText(blob);
86
- });
87
- }
88
- exports.blobToText = blobToText;
89
- /**
90
- * Checks that a URL path ends with a slash.
91
- *
92
- * @param url URL to check
93
- * @returns URL, appended with slash if missing
94
- */
95
- function checkUrlPathTermination(url) {
96
- return url ? (url.endsWith("/") ? url : url + "/") : url;
97
- }
98
- exports.checkUrlPathTermination = checkUrlPathTermination;
99
- /**
100
- * Converts a hub-style item into a solutions-style item, the difference being handling of resources.
101
- *
102
- * @param hubModel Hub-style item
103
- * @return solutions-style item
104
- */
105
- function convertIModel(hubModel) {
106
- const item = {
107
- ...hubModel
108
- };
109
- item.resources = hubModel?.resources ? Object.values(hubModel.resources) : [];
110
- return item;
111
- }
112
- exports.convertIModel = convertIModel;
113
- /**
114
- * Creates a random 32-character alphanumeric string.
115
- *
116
- * @returns A lowercase 32-char alphanumeric string
117
- * @internal
118
- */
119
- function createLongId() {
120
- // createId gets a random number, converts it to base 36 representation, then grabs chars 2-8
121
- return (0, hub_common_1.createId)("") + (0, hub_common_1.createId)("") + (0, hub_common_1.createId)("") + (0, hub_common_1.createId)("");
122
- }
123
- exports.createLongId = createLongId;
124
- /**
125
- * Creates a random 8-character alphanumeric string that begins with an alphabetic character.
126
- *
127
- * @returns An alphanumeric string in the range [a0000000..zzzzzzzz]
128
- */
129
- function createShortId() {
130
- // Return a random number, but beginning with an alphabetic character so that it can be used as a valid
131
- // dotable property name. Used for unique identifiers that do not require the rigor of a full UUID -
132
- // i.e. node ids, process ids, etc.
133
- const min = 0.2777777777777778; // 0.a in base 36
134
- const max = 0.9999999999996456; // 0.zzzzzzzz in base 36
135
- return (_getRandomNumberInRange(min, max).toString(36) + "0000000").substr(2, 8);
136
- }
137
- exports.createShortId = createShortId;
138
- /**
139
- * Copies an input list removing duplicates.
140
- *
141
- * @param input List to be deduped
142
- * @returns Deduped list; order of items in input is not maintained
143
- */
144
- function dedupe(input = []) {
145
- if (input.length === 0) {
146
- return [];
147
- }
148
- const dedupedList = new Set(input);
149
- const output = [];
150
- dedupedList.forEach((value) => output.push(value));
151
- return output;
152
- }
153
- exports.dedupe = dedupe;
154
- /**
155
- * Flags a failure to create an item from a template.
156
- *
157
- * @param itemType The AGO item type
158
- * @param id Item id to include in response
159
- * @returns Empty creation response
160
- */
161
- function generateEmptyCreationResponse(itemType, id = "") {
162
- return {
163
- item: null,
164
- id,
165
- type: itemType,
166
- postProcess: false
167
- };
168
- }
169
- exports.generateEmptyCreationResponse = generateEmptyCreationResponse;
170
- /**
171
- * Returns a regular expression matching a 32-character AGO-style id.
172
- *
173
- * @returns Regular expression
174
- */
175
- function getAgoIdRegEx() {
176
- return /\b([0-9A-Fa-f]){32}\b/g;
177
- }
178
- exports.getAgoIdRegEx = getAgoIdRegEx;
179
- /**
180
- * Returns a regular expression matching a 32-character AGO-style id as a Solution template variable.
181
- *
182
- * @returns Regular expression
183
- */
184
- function getAgoIdTemplateRegEx() {
185
- return /{{\b([0-9A-Fa-f]){32}\b}}/g;
186
- }
187
- exports.getAgoIdTemplateRegEx = getAgoIdTemplateRegEx;
188
- /**
189
- * Converts JSON to a Blob.
190
- *
191
- * @param json JSON to use as source
192
- * @returns A blob from the source JSON
193
- */
194
- function jsonToBlob(json) {
195
- const uint8array = new TextEncoder().encode(JSON.stringify(json));
196
- const blobOptions = { type: "application/octet-stream" };
197
- return new Blob([uint8array], blobOptions);
198
- }
199
- exports.jsonToBlob = jsonToBlob;
200
- /**
201
- * Converts JSON to a File.
202
- *
203
- * @param json JSON to use as source
204
- * @param filename Name to use for file
205
- * @param mimeType MIME type to override blob's MIME type
206
- * @returns File created out of JSON and filename
207
- */
208
- function jsonToFile(json, filename, mimeType = "application/json") {
209
- return blobToFile(jsonToBlob(json), filename, mimeType);
210
- }
211
- exports.jsonToFile = jsonToFile;
212
- /**
213
- * Makes a unique copy of JSON by stringifying and parsing.
214
- *
215
- * @param json JSON to use as source
216
- * @returns A JSON object from the source JSON
217
- */
218
- function jsonToJson(json) {
219
- return JSON.parse(JSON.stringify(json));
220
- }
221
- exports.jsonToJson = jsonToJson;
222
- /**
223
- * Saves a blob to a file.
224
- *
225
- * @param filename Name to give file
226
- * @param blob Blob to save
227
- * @returns Promise resolving when operation is complete
228
- */
229
- // Function is only used for live testing, so excluding it from coverage for now
230
- /* istanbul ignore next */
231
- function saveBlobAsFile(filename, blob) {
232
- return new Promise(resolve => {
233
- const dataUrl = URL.createObjectURL(blob);
234
- const linkElement = document.createElement("a");
235
- linkElement.setAttribute("href", dataUrl);
236
- linkElement.setAttribute("download", filename);
237
- linkElement.style.display = "none";
238
- document.body.appendChild(linkElement);
239
- linkElement.click();
240
- document.body.removeChild(linkElement);
241
- setTimeout(() => {
242
- URL.revokeObjectURL(dataUrl);
243
- resolve(null);
244
- }, 500);
245
- });
246
- }
247
- exports.saveBlobAsFile = saveBlobAsFile;
248
- /**
249
- * Makes a deep clone, including arrays but not functions.
250
- *
251
- * @param obj Object to be cloned
252
- * @returns Clone of obj
253
- * @example
254
- * ```js
255
- * import { cloneObject } from "utils/object-helpers";
256
- * const original = { foo: "bar" }
257
- * const copy = cloneObject(original)
258
- * copy.foo // "bar"
259
- * copy === original // false
260
- * ```
261
- */
262
- function cloneObject(obj) {
263
- let clone = {};
264
- // first check array
265
- if (Array.isArray(obj)) {
266
- clone = obj.map(cloneObject);
267
- }
268
- else if (typeof obj === "object") {
269
- if (obj instanceof File) {
270
- const fileOptions = obj.type ? { type: obj.type } : undefined;
271
- clone = new File([obj], obj.name, fileOptions);
272
- }
273
- else {
274
- for (const i in obj) {
275
- if (obj[i] != null && typeof obj[i] === "object") {
276
- clone[i] = cloneObject(obj[i]);
277
- }
278
- else {
279
- clone[i] = obj[i];
280
- }
281
- }
282
- }
283
- }
284
- else {
285
- clone = obj;
286
- }
287
- return clone;
288
- }
289
- exports.cloneObject = cloneObject;
290
- /**
291
- * Compares two JSON objects using JSON.stringify.
292
- *
293
- * @param json1 First object
294
- * @param json2 Second object
295
- * @returns True if objects are the same
296
- */
297
- function compareJSON(json1, json2) {
298
- return JSON.stringify(json1) === JSON.stringify(json2);
299
- }
300
- exports.compareJSON = compareJSON;
301
- /**
302
- * Compares two JSON objects using JSON.stringify, converting empty strings to nulls.
303
- *
304
- * @param json1 First object
305
- * @param json2 Second object
306
- * @returns True if objects are the same
307
- */
308
- function compareJSONNoEmptyStrings(json1, json2) {
309
- const jsonStr1 = JSON.stringify(json1).replace(/":""/g, '":null');
310
- const jsonStr2 = JSON.stringify(json2).replace(/":""/g, '":null');
311
- return jsonStr1 === jsonStr2;
312
- }
313
- exports.compareJSONNoEmptyStrings = compareJSONNoEmptyStrings;
314
- /**
315
- * Compares two JSON objects property by property and reports each mismatch.
316
- *
317
- * @param json1 First object
318
- * @param json2 Second object
319
- * @returns A list of mismatch report strings
320
- */
321
- function compareJSONProperties(json1, json2) {
322
- let mismatches = [];
323
- const type1 = _typeof_null(json1);
324
- const type2 = _typeof_null(json2);
325
- if (type1 !== type2) {
326
- // Ignore "undefined" vs. "null" and vice versa
327
- /* istanbul ignore else */
328
- if ((type1 !== "undefined" && type1 !== "null") ||
329
- (type2 !== "null" && type2 !== "undefined")) {
330
- mismatches.push("Type difference: " + type1 + " vs. " + type2);
331
- }
332
- }
333
- else {
334
- if (json1 !== json2) {
335
- switch (type1) {
336
- case "boolean":
337
- mismatches.push("Value difference: " + json1 + " vs. " + json2);
338
- break;
339
- case "number":
340
- mismatches.push("Value difference: " + json1 + " vs. " + json2);
341
- break;
342
- case "string":
343
- mismatches.push('String difference: "' + json1 + '" vs. "' + json2 + '"');
344
- break;
345
- case "object":
346
- const keys1 = Object.keys(json1);
347
- const keys2 = Object.keys(json2);
348
- if (keys1.length !== keys2.length ||
349
- JSON.stringify(keys1) !== JSON.stringify(keys2)) {
350
- if (Array.isArray(json1) && Array.isArray(json2)) {
351
- mismatches.push("Array length difference: [" +
352
- keys1.length +
353
- "] vs. [" +
354
- keys2.length +
355
- "]");
356
- }
357
- else {
358
- mismatches.push("Props difference: " +
359
- JSON.stringify(keys1) +
360
- " vs. " +
361
- JSON.stringify(keys2));
362
- }
363
- }
364
- else {
365
- for (let k = 0; k < keys1.length; ++k) {
366
- const submismatches = compareJSONProperties(json1[keys1[k]], json2[keys2[k]]);
367
- if (submismatches.length > 0) {
368
- mismatches = mismatches.concat(submismatches);
369
- }
370
- }
371
- }
372
- break;
373
- }
374
- }
375
- }
376
- return mismatches;
377
- }
378
- exports.compareJSONProperties = compareJSONProperties;
379
- /**
380
- * Sanitizes JSON and echoes changes to console.
381
- *
382
- * @param json JSON to sanitize
383
- * @param sanitizer Instance of Sanitizer class
384
- * @returns Sanitized version of `json`
385
- * @see https://github.com/esri/arcgis-html-sanitizer#sanitize-json
386
- */
387
- function sanitizeJSONAndReportChanges(json, sanitizer) {
388
- const sanitizedJSON = (0, libConnectors_1.sanitizeJSON)(json, sanitizer);
389
- const mismatches = compareJSONProperties(json, sanitizedJSON);
390
- if (mismatches.length > 0) {
391
- console.warn("Changed " +
392
- mismatches.length +
393
- (mismatches.length === 1 ? " property" : " properties"));
394
- mismatches.forEach(mismatch => console.warn(" " + mismatch));
395
- }
396
- return sanitizedJSON;
397
- }
398
- exports.sanitizeJSONAndReportChanges = sanitizeJSONAndReportChanges;
399
- function deleteItemProps(itemTemplate) {
400
- const propsToRetain = [
401
- "accessInformation",
402
- "appCategories",
403
- "banner",
404
- "categories",
405
- "culture",
406
- "description",
407
- "documentation",
408
- "extent",
409
- "groupDesignations",
410
- "industries",
411
- "languages",
412
- "licenseInfo",
413
- "listed",
414
- "name",
415
- "properties",
416
- "proxyFilter",
417
- "screenshots",
418
- "size",
419
- "snippet",
420
- "spatialReference",
421
- "tags",
422
- "title",
423
- "type",
424
- "typeKeywords",
425
- "url"
426
- ];
427
- const propsToDelete = Object.keys(itemTemplate).filter(k => propsToRetain.indexOf(k) < 0);
428
- deleteProps(itemTemplate, propsToDelete);
429
- return itemTemplate;
430
- }
431
- exports.deleteItemProps = deleteItemProps;
432
- /**
433
- * Deletes a property from an object.
434
- *
435
- * @param obj Object with property to delete
436
- * @param path Path into an object to property, e.g., "data.values.webmap", where "data" is a top-level property
437
- * in obj
438
- */
439
- function deleteProp(obj, path) {
440
- const pathParts = path.split(".");
441
- if (Array.isArray(obj)) {
442
- obj.forEach((child) => deleteProp(child, path));
443
- }
444
- else {
445
- const subpath = pathParts.slice(1).join(".");
446
- if (typeof obj[pathParts[0]] !== "undefined") {
447
- if (pathParts.length === 1) {
448
- delete obj[path];
449
- }
450
- else {
451
- deleteProp(obj[pathParts[0]], subpath);
452
- }
453
- }
454
- }
455
- }
456
- exports.deleteProp = deleteProp;
457
- /**
458
- * Deletes properties from an object.
459
- *
460
- * @param obj Object with properties to delete
461
- * @param props Array of properties on object that should be deleted
462
- */
463
- function deleteProps(obj, props) {
464
- props.forEach(prop => {
465
- deleteProp(obj, prop);
466
- });
467
- }
468
- exports.deleteProps = deleteProps;
469
- /**
470
- * Creates an AGO-style JSON failure response with success property.
471
- *
472
- * @param e Optional error information
473
- * @returns JSON structure with property success set to false and optionally including `e`
474
- */
475
- function fail(e) {
476
- if (e) {
477
- return { success: false, error: e.response?.error || e.error || e };
478
- }
479
- else {
480
- return { success: false };
481
- }
482
- }
483
- exports.fail = fail;
484
- /**
485
- * Creates an AGO-style JSON failure response with success property and extended with ids list.
486
- *
487
- * @param ids List of ids
488
- * @param e Optional error information
489
- * @returns JSON structure with property success set to false and optionally including `e`
490
- */
491
- function failWithIds(itemIds, e) {
492
- if (e) {
493
- return { success: false, itemIds, error: e.error || e };
494
- }
495
- else {
496
- return { success: false, itemIds };
497
- }
498
- }
499
- exports.failWithIds = failWithIds;
500
- /**
501
- * Extracts subgroup ids from item tags
502
- *
503
- * @param tags Tags in an item
504
- * @returns List of subgroup ids; subgroups are identified using tags that begin with "group." and end with a group id,
505
- * e.g., "group.8d515625ee9f49d7b4f6c6cb2a389151"; non-matching tags are ignored
506
- */
507
- function getSubgroupIds(tags) {
508
- if (tags) {
509
- const containedGroupPrefix = "group.";
510
- return tags
511
- .filter(tag => tag.startsWith(containedGroupPrefix))
512
- .map(tag => tag.substring(containedGroupPrefix.length));
513
- }
514
- else {
515
- return [];
516
- }
517
- }
518
- exports.getSubgroupIds = getSubgroupIds;
519
- /**
520
- * Extracts the ids from a string
521
- *
522
- * @param v String to examine
523
- * @returns List of id strings found
524
- * @example
525
- * get id from
526
- * bad3483e025c47338d43df308c117308
527
- * {bad3483e025c47338d43df308c117308
528
- * =bad3483e025c47338d43df308c117308
529
- * do not get id from
530
- * http: *something/name_bad3483e025c47338d43df308c117308
531
- * {{bad3483e025c47338d43df308c117308.itemId}}
532
- * bad3483e025c47338d43df308c117308bad3483e025c47338d43df308c117308
533
- */
534
- function getIDs(v) {
535
- // lookbehind is not supported in safari
536
- // cannot use /(?<!_)(?<!{{)\b[0-9A-F]{32}/gi
537
- // use groups and filter out the ids that start with {{
538
- return regExTest(v, /({*)(\b[0-9A-F]{32}\b)/gi).reduce(function (acc, _v) {
539
- /* istanbul ignore else */
540
- if (_v.indexOf("{{") < 0) {
541
- acc.push(_v.replace("{", ""));
542
- }
543
- return acc;
544
- }, []);
545
- }
546
- exports.getIDs = getIDs;
547
- /**
548
- * Gets a property out of a deeply nested object.
549
- * Does not handle anything but nested object graph
550
- *
551
- * @param obj Object to retrieve value from
552
- * @param path Path into an object, e.g., "data.values.webmap", where "data" is a top-level property
553
- * in obj
554
- * @returns Value at end of path
555
- */
556
- function getProp(obj, path) {
557
- return path.split(".").reduce(function (prev, curr) {
558
- /* istanbul ignore next no need to test undefined scenario */
559
- return prev ? prev[curr] : undefined;
560
- }, obj);
561
- }
562
- exports.getProp = getProp;
563
- /**
564
- * Returns an array of values from an object based on an array of property paths.
565
- *
566
- * @param obj Object to retrieve values from
567
- * @param props Array of paths into the object e.g., "data.values.webmap", where "data" is a top-level property
568
- * @returns Array of the values plucked from the object; only defined values are returned
569
- */
570
- function getProps(obj, props) {
571
- return props.reduce((a, p) => {
572
- const v = getProp(obj, p);
573
- if (v) {
574
- a.push(v);
575
- }
576
- return a;
577
- }, []);
578
- }
579
- exports.getProps = getProps;
580
- /**
581
- * Get a property out of a deeply nested object
582
- * Does not handle anything but nested object graph
583
- *
584
- * @param obj Object to retrieve value from
585
- * @param path Path into an object, e.g., "data.values.webmap", where "data" is a top-level property
586
- * in obj
587
- * @param defaultV Optional value to use if any part of path--including final value--is undefined
588
- * @returns Value at end of path
589
- */
590
- function getPropWithDefault(obj, path, defaultV) {
591
- const value = path.split(".").reduce(function (prev, curr) {
592
- /* istanbul ignore next no need to test undefined scenario */
593
- return prev ? prev[curr] : undefined;
594
- }, obj);
595
- if (typeof value === "undefined") {
596
- return defaultV;
597
- }
598
- else {
599
- return value;
600
- }
601
- }
602
- exports.getPropWithDefault = getPropWithDefault;
603
- /**
604
- * Updates a list of the items dependencies if more are found in the
605
- * provided value.
606
- *
607
- * @param v a string value to check for ids
608
- * @param deps a list of the items dependencies
609
- */
610
- function idTest(v, deps) {
611
- const ids = getIDs(v);
612
- ids.forEach(id => {
613
- /* istanbul ignore else */
614
- if (deps.indexOf(id) === -1) {
615
- deps.push(id);
616
- }
617
- });
618
- }
619
- exports.idTest = idTest;
620
- /**
621
- * Sets a deeply nested property of an object.
622
- * Creates the full path if it does not exist.
623
- *
624
- * @param obj Object to set value of
625
- * @param path Path into an object, e.g., "data.values.webmap", where "data" is a top-level property in obj
626
- * @param value The value to set at the end of the path
627
- */
628
- function setCreateProp(obj, path, value) {
629
- const pathParts = path.split(".");
630
- pathParts.reduce((a, b, c) => {
631
- if (c === pathParts.length - 1) {
632
- a[b] = value;
633
- return value;
634
- }
635
- else {
636
- if (!a[b]) {
637
- a[b] = {};
638
- }
639
- return a[b];
640
- }
641
- }, obj);
642
- }
643
- exports.setCreateProp = setCreateProp;
644
- /**
645
- * Sets a deeply nested property of an object.
646
- * Does nothing if the full path does not exist.
647
- *
648
- * @param obj Object to set value of
649
- * @param path Path into an object, e.g., "data.values.webmap", where "data" is a top-level property in obj
650
- * @param value The value to set at the end of the path
651
- */
652
- function setProp(obj, path, value) {
653
- if (getProp(obj, path)) {
654
- const pathParts = path.split(".");
655
- pathParts.reduce((a, b, c) => {
656
- if (c === pathParts.length - 1) {
657
- a[b] = value;
658
- return value;
659
- }
660
- else {
661
- return a[b];
662
- }
663
- }, obj);
664
- }
665
- }
666
- exports.setProp = setProp;
667
- /**
668
- * Creates a timestamp string using the current UTC date and time.
669
- *
670
- * @returns Timestamp formatted as YYYYMMDD_hhmm_ssmmm, with month one-based and all values padded with zeroes on the
671
- * left as needed (`ssmmm` stands for seconds from 0..59 and milliseconds from 0..999)
672
- * @private
673
- */
674
- function getUTCTimestamp() {
675
- const now = new Date();
676
- return (_padPositiveNum(now.getUTCFullYear(), 4) +
677
- _padPositiveNum(now.getUTCMonth() + 1, 2) +
678
- _padPositiveNum(now.getUTCDate(), 2) +
679
- "_" +
680
- _padPositiveNum(now.getUTCHours(), 2) +
681
- _padPositiveNum(now.getUTCMinutes(), 2) +
682
- "_" +
683
- _padPositiveNum(now.getUTCSeconds(), 2) +
684
- _padPositiveNum(now.getUTCMilliseconds(), 3));
685
- }
686
- exports.getUTCTimestamp = getUTCTimestamp;
687
- /**
688
- * Tests if an object's `item.typeKeywords` or `typeKeywords` properties has any of a set of keywords.
689
- *
690
- * @param jsonObj Object to test
691
- * @param keywords List of keywords to look for in jsonObj
692
- * @returns Boolean indicating result
693
- */
694
- function hasAnyKeyword(jsonObj, keywords) {
695
- const typeKeywords = getProp(jsonObj, "item.typeKeywords") || jsonObj.typeKeywords || [];
696
- return keywords.reduce((a, kw) => {
697
- if (!a) {
698
- a = typeKeywords.includes(kw);
699
- }
700
- return a;
701
- }, false);
702
- }
703
- exports.hasAnyKeyword = hasAnyKeyword;
704
- /**
705
- * Tests if an object's `item.typeKeywords` or `typeKeywords` properties has a specific keyword.
706
- *
707
- * @param jsonObj Object to test
708
- * @param keyword Keyword to look for in jsonObj
709
- * @returns Boolean indicating result
710
- */
711
- function hasTypeKeyword(jsonObj, keyword) {
712
- const typeKeywords = getProp(jsonObj, "item.typeKeywords") || jsonObj.typeKeywords || [];
713
- return typeKeywords.includes(keyword);
714
- }
715
- exports.hasTypeKeyword = hasTypeKeyword;
716
- /**
717
- * Will return the provided title if it does not exist as a property
718
- * in one of the objects at the defined path. Otherwise the title will
719
- * have a numerical value attached.
720
- *
721
- * @param title The root title to test
722
- * @param templateDictionary Hash of the facts
723
- * @param path to the objects to evaluate for potantial name clashes
724
- * @returns string The unique title to use
725
- */
726
- function getUniqueTitle(title, templateDictionary, path) {
727
- title = title ? title.trim() : "_";
728
- const objs = getProp(templateDictionary, path) || [];
729
- const titles = objs.map(obj => {
730
- return obj.title;
731
- });
732
- let newTitle = title;
733
- let i = 0;
734
- while (titles.indexOf(newTitle) > -1) {
735
- i++;
736
- newTitle = title + " " + i;
737
- }
738
- return newTitle;
739
- }
740
- exports.getUniqueTitle = getUniqueTitle;
741
- /**
742
- * Performs string replacement on every string in an object.
743
- *
744
- * @param obj Object to scan and to modify
745
- * @param pattern Search pattern in each string
746
- * @param replacement Replacement for matches to search pattern
747
- * @returns Modified obj is returned
748
- */
749
- function globalStringReplace(obj, pattern, replacement) {
750
- if (obj) {
751
- Object.keys(obj).forEach(prop => {
752
- const propObj = obj[prop];
753
- if (propObj) {
754
- /* istanbul ignore else */
755
- if (typeof propObj === "object") {
756
- globalStringReplace(propObj, pattern, replacement);
757
- }
758
- else if (typeof propObj === "string") {
759
- obj[prop] = obj[prop].replace(pattern, replacement);
760
- }
761
- }
762
- });
763
- }
764
- return obj;
765
- }
766
- exports.globalStringReplace = globalStringReplace;
767
- /**
768
- * Tests if an array of DatasourceInfos has a given item and layer id already.
769
- *
770
- * @param datasourceInfos Array of DatasourceInfos to evaluate
771
- * @param itemId The items id to check for
772
- * @param layerId The layers id to check for
773
- * @returns Boolean indicating result
774
- */
775
- function hasDatasource(datasourceInfos, itemId, layerId) {
776
- return datasourceInfos.some(ds => ds.itemId === itemId && ds.layerId === layerId);
777
- }
778
- exports.hasDatasource = hasDatasource;
779
- /**
780
- * remove templatization from item id to compare
781
- *
782
- * @example
783
- * \{\{934a9ef8efa7448fa8ddf7b13cef0240.itemId\}\}
784
- * returns 934a9ef8efa7448fa8ddf7b13cef0240
785
- */
786
- function cleanItemId(id) {
787
- return id ? id.replace("{{", "").replace(".itemId}}", "") : id;
788
- }
789
- exports.cleanItemId = cleanItemId;
790
- /**
791
- * remove templatization from layer based item id to compare
792
- *
793
- * @example
794
- * \{\{934a9ef8efa7448fa8ddf7b13cef0240.layer0.itemId\}\}
795
- * returns 934a9ef8efa7448fa8ddf7b13cef0240
796
- */
797
- function cleanLayerBasedItemId(id) {
798
- return id
799
- ? id
800
- .replace("{{", "")
801
- .replace(/([.]layer([0-9]|[1-9][0-9])[.](item|layer)Id)[}]{2}/, "")
802
- : id;
803
- }
804
- exports.cleanLayerBasedItemId = cleanLayerBasedItemId;
805
- /**
806
- * remove templatization from layer id to compare
807
- *
808
- * @example
809
- * \{\{934a9ef8efa7448fa8ddf7b13cef0240.layer0.layerId\}\}
810
- * returns 0
811
- */
812
- function cleanLayerId(id) {
813
- return id?.toString()
814
- ? parseInt(id
815
- .toString()
816
- .replace(/[{]{2}.{32}[.]layer/, "")
817
- .replace(/[.]layerId[}]{2}/, ""), 10)
818
- : id;
819
- }
820
- exports.cleanLayerId = cleanLayerId;
821
- /**
822
- * Get template from list of templates by ID
823
- *
824
- * @param templates Array of item templates to search
825
- * @param id of template we are searching for
826
- *
827
- * @returns Template associated with the user provided id argument
828
- */
829
- function getTemplateById(templates, id) {
830
- let template;
831
- templates.some(_template => {
832
- if (_template.itemId === id) {
833
- template = _template;
834
- return true;
835
- }
836
- return false;
837
- });
838
- return template;
839
- }
840
- exports.getTemplateById = getTemplateById;
841
- /**
842
- * Evaluates a value with a regular expression
843
- *
844
- * @param v a string value to test with the expression
845
- * @param ex the regular expresion to test with
846
- * @returns an array of matches
847
- */
848
- function regExTest(v, ex) {
849
- return v && ex.test(v) ? v.match(ex) : [];
850
- }
851
- exports.regExTest = regExTest;
852
- // ------------------------------------------------------------------------------------------------------------------ //
853
- /**
854
- * Creates a random number between two values.
855
- *
856
- * @param min Inclusive minimum desired value
857
- * @param max Non-inclusive maximum desired value
858
- * @returns Random number in the range [min, max)
859
- */
860
- function _getRandomNumberInRange(min, max) {
861
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#Getting_a_random_number_between_two_values
862
- // © 2006 IvanWills
863
- // MIT license https://opensource.org/licenses/mit-license.php
864
- return Math.random() * (max - min) + min;
865
- }
866
- exports._getRandomNumberInRange = _getRandomNumberInRange;
867
- /**
868
- * Pads the string representation of a number to a minimum width. Requires modern browser.
869
- *
870
- * @param n Number to pad
871
- * @param totalSize Desired *minimum* width of number after padding with zeroes
872
- * @returns Number converted to string and padded on the left as needed
873
- * @private
874
- */
875
- function _padPositiveNum(n, totalSize) {
876
- let numStr = n.toString();
877
- const numPads = totalSize - numStr.length;
878
- if (numPads > 0) {
879
- numStr = "0".repeat(numPads) + numStr; // TODO IE11 does not support repeat()
880
- }
881
- return numStr;
882
- }
883
- exports._padPositiveNum = _padPositiveNum;
884
- /**
885
- * Implements rejected ECMA proposal to change `typeof null` from "object" to "null".
886
- *
887
- * @param value Value whose type is sought
888
- * @returns "null" if `value` is null; `typeof value` otherwise
889
- * @see https://web.archive.org/web/20160331031419/http://wiki.ecmascript.org:80/doku.php?id=harmony:typeof_null
890
- * @private
891
- */
892
- function _typeof_null(value) {
893
- return value === null ? "null" : typeof value;
894
- }
895
- //# sourceMappingURL=generalHelpers.js.map