@esri/solution-common 6.1.3 → 6.1.4

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 (404) hide show
  1. package/dist/cjs/arcgisRestJS.d.ts +63 -0
  2. package/dist/cjs/arcgisRestJS.js +158 -0
  3. package/dist/cjs/arcgisRestJS.js.map +1 -0
  4. package/dist/cjs/completeItem.d.ts +30 -0
  5. package/dist/cjs/completeItem.js +72 -0
  6. package/dist/cjs/completeItem.js.map +1 -0
  7. package/dist/cjs/create-hub-request-options.d.ts +29 -0
  8. package/dist/cjs/create-hub-request-options.js +64 -0
  9. package/dist/cjs/create-hub-request-options.js.map +1 -0
  10. package/dist/cjs/deleteHelpers/deleteEmptyGroups.d.ts +24 -0
  11. package/dist/cjs/deleteHelpers/deleteEmptyGroups.js +42 -0
  12. package/dist/cjs/deleteHelpers/deleteEmptyGroups.js.map +1 -0
  13. package/dist/cjs/deleteHelpers/deleteGroupIfEmpty.d.ts +27 -0
  14. package/dist/cjs/deleteHelpers/deleteGroupIfEmpty.js +99 -0
  15. package/dist/cjs/deleteHelpers/deleteGroupIfEmpty.js.map +1 -0
  16. package/dist/cjs/deleteHelpers/deleteSolutionContents.d.ts +39 -0
  17. package/dist/cjs/deleteHelpers/deleteSolutionContents.js +127 -0
  18. package/dist/cjs/deleteHelpers/deleteSolutionContents.js.map +1 -0
  19. package/dist/cjs/deleteHelpers/deleteSolutionFolder.d.ts +29 -0
  20. package/dist/cjs/deleteHelpers/deleteSolutionFolder.js +81 -0
  21. package/dist/cjs/deleteHelpers/deleteSolutionFolder.js.map +1 -0
  22. package/dist/cjs/deleteHelpers/deleteSolutionItem.d.ts +31 -0
  23. package/dist/cjs/deleteHelpers/deleteSolutionItem.js +52 -0
  24. package/dist/cjs/deleteHelpers/deleteSolutionItem.js.map +1 -0
  25. package/dist/cjs/deleteHelpers/index.d.ts +22 -0
  26. package/dist/cjs/deleteHelpers/index.js +26 -0
  27. package/dist/cjs/deleteHelpers/index.js.map +1 -0
  28. package/dist/cjs/deleteHelpers/reconstructBuildOrderIds.d.ts +27 -0
  29. package/dist/cjs/deleteHelpers/reconstructBuildOrderIds.js +34 -0
  30. package/dist/cjs/deleteHelpers/reconstructBuildOrderIds.js.map +1 -0
  31. package/dist/cjs/deleteHelpers/removeItems.d.ts +35 -0
  32. package/dist/cjs/deleteHelpers/removeItems.js +116 -0
  33. package/dist/cjs/deleteHelpers/removeItems.js.map +1 -0
  34. package/dist/cjs/deleteHelpers/reportProgress.d.ts +27 -0
  35. package/dist/cjs/deleteHelpers/reportProgress.js +46 -0
  36. package/dist/cjs/deleteHelpers/reportProgress.js.map +1 -0
  37. package/dist/cjs/deleteSolution.d.ts +56 -0
  38. package/dist/cjs/deleteSolution.js +107 -0
  39. package/dist/cjs/deleteSolution.js.map +1 -0
  40. package/dist/cjs/dependencies.d.ts +26 -0
  41. package/dist/cjs/dependencies.js +171 -0
  42. package/dist/cjs/dependencies.js.map +1 -0
  43. package/dist/cjs/featureServiceHelpers.d.ts +847 -0
  44. package/dist/cjs/featureServiceHelpers.js +2553 -0
  45. package/dist/cjs/featureServiceHelpers.js.map +1 -0
  46. package/dist/cjs/formHelpers.d.ts +26 -0
  47. package/dist/cjs/formHelpers.js +40 -0
  48. package/dist/cjs/formHelpers.js.map +1 -0
  49. package/dist/cjs/generalHelpers.d.ts +447 -0
  50. package/dist/cjs/generalHelpers.js +959 -0
  51. package/dist/cjs/generalHelpers.js.map +1 -0
  52. package/dist/cjs/get-subscription-info.d.ts +27 -0
  53. package/dist/cjs/get-subscription-info.js +38 -0
  54. package/dist/cjs/get-subscription-info.js.map +1 -0
  55. package/dist/cjs/getDeletableSolutionInfo.d.ts +30 -0
  56. package/dist/cjs/getDeletableSolutionInfo.js +53 -0
  57. package/dist/cjs/getDeletableSolutionInfo.js.map +1 -0
  58. package/dist/cjs/getItemTypeAbbrev.d.ts +19 -0
  59. package/dist/cjs/getItemTypeAbbrev.js +186 -0
  60. package/dist/cjs/getItemTypeAbbrev.js.map +1 -0
  61. package/dist/cjs/getSolutionSummary.d.ts +28 -0
  62. package/dist/cjs/getSolutionSummary.js +100 -0
  63. package/dist/cjs/getSolutionSummary.js.map +1 -0
  64. package/dist/cjs/index.d.ts +49 -0
  65. package/dist/cjs/index.js +53 -0
  66. package/dist/cjs/index.js.map +1 -0
  67. package/dist/cjs/interfaces.d.ts +1446 -0
  68. package/dist/cjs/interfaces.js +72 -0
  69. package/dist/cjs/interfaces.js.map +1 -0
  70. package/dist/cjs/item-reuse.d.ts +140 -0
  71. package/dist/cjs/item-reuse.js +176 -0
  72. package/dist/cjs/item-reuse.js.map +1 -0
  73. package/dist/cjs/libConnectors.d.ts +73 -0
  74. package/dist/cjs/libConnectors.js +115 -0
  75. package/dist/cjs/libConnectors.js.map +1 -0
  76. package/dist/cjs/migrations/apply-schema.d.ts +24 -0
  77. package/dist/cjs/migrations/apply-schema.js +36 -0
  78. package/dist/cjs/migrations/apply-schema.js.map +1 -0
  79. package/dist/cjs/migrations/is-legacy-solution.d.ts +24 -0
  80. package/dist/cjs/migrations/is-legacy-solution.js +39 -0
  81. package/dist/cjs/migrations/is-legacy-solution.js.map +1 -0
  82. package/dist/cjs/migrations/upgrade-three-dot-one.d.ts +26 -0
  83. package/dist/cjs/migrations/upgrade-three-dot-one.js +48 -0
  84. package/dist/cjs/migrations/upgrade-three-dot-one.js.map +1 -0
  85. package/dist/cjs/migrations/upgrade-three-dot-zero.d.ts +27 -0
  86. package/dist/cjs/migrations/upgrade-three-dot-zero.js +43 -0
  87. package/dist/cjs/migrations/upgrade-three-dot-zero.js.map +1 -0
  88. package/dist/cjs/migrations/upgrade-two-dot-five.d.ts +24 -0
  89. package/dist/cjs/migrations/upgrade-two-dot-five.js +73 -0
  90. package/dist/cjs/migrations/upgrade-two-dot-five.js.map +1 -0
  91. package/dist/cjs/migrations/upgrade-two-dot-four.d.ts +24 -0
  92. package/dist/cjs/migrations/upgrade-two-dot-four.js +72 -0
  93. package/dist/cjs/migrations/upgrade-two-dot-four.js.map +1 -0
  94. package/dist/cjs/migrations/upgrade-two-dot-one.d.ts +7 -0
  95. package/dist/cjs/migrations/upgrade-two-dot-one.js +39 -0
  96. package/dist/cjs/migrations/upgrade-two-dot-one.js.map +1 -0
  97. package/dist/cjs/migrations/upgrade-two-dot-seven.d.ts +23 -0
  98. package/dist/cjs/migrations/upgrade-two-dot-seven.js +58 -0
  99. package/dist/cjs/migrations/upgrade-two-dot-seven.js.map +1 -0
  100. package/dist/cjs/migrations/upgrade-two-dot-six.d.ts +27 -0
  101. package/dist/cjs/migrations/upgrade-two-dot-six.js +61 -0
  102. package/dist/cjs/migrations/upgrade-two-dot-six.js.map +1 -0
  103. package/dist/cjs/migrations/upgrade-two-dot-three.d.ts +23 -0
  104. package/dist/cjs/migrations/upgrade-two-dot-three.js +55 -0
  105. package/dist/cjs/migrations/upgrade-two-dot-three.js.map +1 -0
  106. package/dist/cjs/migrations/upgrade-two-dot-two.d.ts +23 -0
  107. package/dist/cjs/migrations/upgrade-two-dot-two.js +58 -0
  108. package/dist/cjs/migrations/upgrade-two-dot-two.js.map +1 -0
  109. package/dist/cjs/migrations/upgrade-two-dot-zero.d.ts +44 -0
  110. package/dist/cjs/migrations/upgrade-two-dot-zero.js +95 -0
  111. package/dist/cjs/migrations/upgrade-two-dot-zero.js.map +1 -0
  112. package/dist/cjs/migrator.d.ts +25 -0
  113. package/dist/cjs/migrator.js +75 -0
  114. package/dist/cjs/migrator.js.map +1 -0
  115. package/dist/cjs/resourceHelpers.d.ts +192 -0
  116. package/dist/cjs/resourceHelpers.js +380 -0
  117. package/dist/cjs/resourceHelpers.js.map +1 -0
  118. package/dist/cjs/resources/add-resource.d.ts +38 -0
  119. package/dist/cjs/resources/add-resource.js +84 -0
  120. package/dist/cjs/resources/add-resource.js.map +1 -0
  121. package/dist/cjs/resources/addMetadataFromBlob.d.ts +25 -0
  122. package/dist/cjs/resources/addMetadataFromBlob.js +43 -0
  123. package/dist/cjs/resources/addMetadataFromBlob.js.map +1 -0
  124. package/dist/cjs/resources/convert-item-resource-to-storage-resource.d.ts +32 -0
  125. package/dist/cjs/resources/convert-item-resource-to-storage-resource.js +70 -0
  126. package/dist/cjs/resources/convert-item-resource-to-storage-resource.js.map +1 -0
  127. package/dist/cjs/resources/convert-storage-resource-to-item-resource.d.ts +29 -0
  128. package/dist/cjs/resources/convert-storage-resource-to-item-resource.js +70 -0
  129. package/dist/cjs/resources/convert-storage-resource-to-item-resource.js.map +1 -0
  130. package/dist/cjs/resources/copyAssociatedFiles.d.ts +79 -0
  131. package/dist/cjs/resources/copyAssociatedFiles.js +348 -0
  132. package/dist/cjs/resources/copyAssociatedFiles.js.map +1 -0
  133. package/dist/cjs/resources/copyDataIntoItem.d.ts +34 -0
  134. package/dist/cjs/resources/copyDataIntoItem.js +45 -0
  135. package/dist/cjs/resources/copyDataIntoItem.js.map +1 -0
  136. package/dist/cjs/resources/copyMetadataIntoItem.d.ts +27 -0
  137. package/dist/cjs/resources/copyMetadataIntoItem.js +44 -0
  138. package/dist/cjs/resources/copyMetadataIntoItem.js.map +1 -0
  139. package/dist/cjs/resources/copyResourceIntoZip.d.ts +34 -0
  140. package/dist/cjs/resources/copyResourceIntoZip.js +74 -0
  141. package/dist/cjs/resources/copyResourceIntoZip.js.map +1 -0
  142. package/dist/cjs/resources/copyZipIntoItem.d.ts +26 -0
  143. package/dist/cjs/resources/copyZipIntoItem.js +53 -0
  144. package/dist/cjs/resources/copyZipIntoItem.js.map +1 -0
  145. package/dist/cjs/resources/createCopyResults.d.ts +25 -0
  146. package/dist/cjs/resources/createCopyResults.js +36 -0
  147. package/dist/cjs/resources/createCopyResults.js.map +1 -0
  148. package/dist/cjs/resources/get-blob.d.ts +25 -0
  149. package/dist/cjs/resources/get-blob.js +42 -0
  150. package/dist/cjs/resources/get-blob.js.map +1 -0
  151. package/dist/cjs/resources/getItemResourcesFilesFromPaths.d.ts +25 -0
  152. package/dist/cjs/resources/getItemResourcesFilesFromPaths.js +49 -0
  153. package/dist/cjs/resources/getItemResourcesFilesFromPaths.js.map +1 -0
  154. package/dist/cjs/resources/getItemResourcesPaths.d.ts +27 -0
  155. package/dist/cjs/resources/getItemResourcesPaths.js +80 -0
  156. package/dist/cjs/resources/getItemResourcesPaths.js.map +1 -0
  157. package/dist/cjs/resources/index.d.ts +30 -0
  158. package/dist/cjs/resources/index.js +34 -0
  159. package/dist/cjs/resources/index.js.map +1 -0
  160. package/dist/cjs/resources/solution-resource.d.ts +35 -0
  161. package/dist/cjs/resources/solution-resource.js +31 -0
  162. package/dist/cjs/resources/solution-resource.js.map +1 -0
  163. package/dist/cjs/resources/transform-resource-paths-to-solution-resources.d.ts +56 -0
  164. package/dist/cjs/resources/transform-resource-paths-to-solution-resources.js +140 -0
  165. package/dist/cjs/resources/transform-resource-paths-to-solution-resources.js.map +1 -0
  166. package/dist/cjs/resources/update-resource.d.ts +27 -0
  167. package/dist/cjs/resources/update-resource.js +52 -0
  168. package/dist/cjs/resources/update-resource.js.map +1 -0
  169. package/dist/cjs/restHelpers.d.ts +634 -0
  170. package/dist/cjs/restHelpers.js +2008 -0
  171. package/dist/cjs/restHelpers.js.map +1 -0
  172. package/dist/cjs/restHelpersGet.d.ts +303 -0
  173. package/dist/cjs/restHelpersGet.js +835 -0
  174. package/dist/cjs/restHelpersGet.js.map +1 -0
  175. package/dist/cjs/sharing/index.d.ts +16 -0
  176. package/dist/cjs/sharing/index.js +20 -0
  177. package/dist/cjs/sharing/index.js.map +1 -0
  178. package/dist/cjs/sharing/share-item-to-groups.d.ts +26 -0
  179. package/dist/cjs/sharing/share-item-to-groups.js +44 -0
  180. package/dist/cjs/sharing/share-item-to-groups.js.map +1 -0
  181. package/dist/cjs/templatization.d.ts +139 -0
  182. package/dist/cjs/templatization.js +311 -0
  183. package/dist/cjs/templatization.js.map +1 -0
  184. package/dist/cjs/trackingHelpers.d.ts +115 -0
  185. package/dist/cjs/trackingHelpers.js +212 -0
  186. package/dist/cjs/trackingHelpers.js.map +1 -0
  187. package/dist/cjs/velocityHelpers.d.ts +68 -0
  188. package/dist/cjs/velocityHelpers.js +151 -0
  189. package/dist/cjs/velocityHelpers.js.map +1 -0
  190. package/dist/cjs/webtoolHelpers.d.ts +57 -0
  191. package/dist/cjs/webtoolHelpers.js +102 -0
  192. package/dist/cjs/webtoolHelpers.js.map +1 -0
  193. package/dist/cjs/workflowHelpers.d.ts +112 -0
  194. package/dist/cjs/workflowHelpers.js +284 -0
  195. package/dist/cjs/workflowHelpers.js.map +1 -0
  196. package/dist/cjs/workforceHelpers.d.ts +121 -0
  197. package/dist/cjs/workforceHelpers.js +720 -0
  198. package/dist/cjs/workforceHelpers.js.map +1 -0
  199. package/dist/cjs/zip-utils.d.ts +85 -0
  200. package/dist/cjs/zip-utils.js +154 -0
  201. package/dist/cjs/zip-utils.js.map +1 -0
  202. package/dist/esm/arcgisRestJS.d.ts +63 -0
  203. package/dist/esm/arcgisRestJS.js +110 -0
  204. package/dist/esm/arcgisRestJS.js.map +1 -0
  205. package/dist/esm/completeItem.d.ts +30 -0
  206. package/dist/esm/completeItem.js +67 -0
  207. package/dist/esm/completeItem.js.map +1 -0
  208. package/dist/esm/create-hub-request-options.d.ts +29 -0
  209. package/dist/esm/create-hub-request-options.js +60 -0
  210. package/dist/esm/create-hub-request-options.js.map +1 -0
  211. package/dist/esm/deleteHelpers/deleteEmptyGroups.d.ts +24 -0
  212. package/dist/esm/deleteHelpers/deleteEmptyGroups.js +38 -0
  213. package/dist/esm/deleteHelpers/deleteEmptyGroups.js.map +1 -0
  214. package/dist/esm/deleteHelpers/deleteGroupIfEmpty.d.ts +27 -0
  215. package/dist/esm/deleteHelpers/deleteGroupIfEmpty.js +95 -0
  216. package/dist/esm/deleteHelpers/deleteGroupIfEmpty.js.map +1 -0
  217. package/dist/esm/deleteHelpers/deleteSolutionContents.d.ts +39 -0
  218. package/dist/esm/deleteHelpers/deleteSolutionContents.js +122 -0
  219. package/dist/esm/deleteHelpers/deleteSolutionContents.js.map +1 -0
  220. package/dist/esm/deleteHelpers/deleteSolutionFolder.d.ts +29 -0
  221. package/dist/esm/deleteHelpers/deleteSolutionFolder.js +77 -0
  222. package/dist/esm/deleteHelpers/deleteSolutionFolder.js.map +1 -0
  223. package/dist/esm/deleteHelpers/deleteSolutionItem.d.ts +31 -0
  224. package/dist/esm/deleteHelpers/deleteSolutionItem.js +48 -0
  225. package/dist/esm/deleteHelpers/deleteSolutionItem.js.map +1 -0
  226. package/dist/esm/deleteHelpers/index.d.ts +22 -0
  227. package/dist/esm/deleteHelpers/index.js +23 -0
  228. package/dist/esm/deleteHelpers/index.js.map +1 -0
  229. package/dist/esm/deleteHelpers/reconstructBuildOrderIds.d.ts +27 -0
  230. package/dist/esm/deleteHelpers/reconstructBuildOrderIds.js +29 -0
  231. package/dist/esm/deleteHelpers/reconstructBuildOrderIds.js.map +1 -0
  232. package/dist/esm/deleteHelpers/removeItems.d.ts +35 -0
  233. package/dist/esm/deleteHelpers/removeItems.js +111 -0
  234. package/dist/esm/deleteHelpers/removeItems.js.map +1 -0
  235. package/dist/esm/deleteHelpers/reportProgress.d.ts +27 -0
  236. package/dist/esm/deleteHelpers/reportProgress.js +42 -0
  237. package/dist/esm/deleteHelpers/reportProgress.js.map +1 -0
  238. package/dist/esm/deleteSolution.d.ts +56 -0
  239. package/dist/esm/deleteSolution.js +101 -0
  240. package/dist/esm/deleteSolution.js.map +1 -0
  241. package/dist/esm/dependencies.d.ts +26 -0
  242. package/dist/esm/dependencies.js +167 -0
  243. package/dist/esm/dependencies.js.map +1 -0
  244. package/dist/esm/featureServiceHelpers.d.ts +847 -0
  245. package/dist/esm/featureServiceHelpers.js +2466 -0
  246. package/dist/esm/featureServiceHelpers.js.map +1 -0
  247. package/dist/esm/formHelpers.d.ts +26 -0
  248. package/dist/esm/formHelpers.js +35 -0
  249. package/dist/esm/formHelpers.js.map +1 -0
  250. package/dist/esm/generalHelpers.d.ts +447 -0
  251. package/dist/esm/generalHelpers.js +903 -0
  252. package/dist/esm/generalHelpers.js.map +1 -0
  253. package/dist/esm/get-subscription-info.d.ts +27 -0
  254. package/dist/esm/get-subscription-info.js +34 -0
  255. package/dist/esm/get-subscription-info.js.map +1 -0
  256. package/dist/esm/getDeletableSolutionInfo.d.ts +30 -0
  257. package/dist/esm/getDeletableSolutionInfo.js +48 -0
  258. package/dist/esm/getDeletableSolutionInfo.js.map +1 -0
  259. package/dist/esm/getItemTypeAbbrev.d.ts +19 -0
  260. package/dist/esm/getItemTypeAbbrev.js +182 -0
  261. package/dist/esm/getItemTypeAbbrev.js.map +1 -0
  262. package/dist/esm/getSolutionSummary.d.ts +28 -0
  263. package/dist/esm/getSolutionSummary.js +95 -0
  264. package/dist/esm/getSolutionSummary.js.map +1 -0
  265. package/dist/esm/index.d.ts +49 -0
  266. package/dist/esm/index.js +50 -0
  267. package/dist/esm/index.js.map +1 -0
  268. package/dist/esm/interfaces.d.ts +1446 -0
  269. package/dist/esm/interfaces.js +69 -0
  270. package/dist/esm/interfaces.js.map +1 -0
  271. package/dist/esm/item-reuse.d.ts +140 -0
  272. package/dist/esm/item-reuse.js +167 -0
  273. package/dist/esm/item-reuse.js.map +1 -0
  274. package/dist/esm/libConnectors.d.ts +73 -0
  275. package/dist/esm/libConnectors.js +105 -0
  276. package/dist/esm/libConnectors.js.map +1 -0
  277. package/dist/esm/migrations/apply-schema.d.ts +24 -0
  278. package/dist/esm/migrations/apply-schema.js +32 -0
  279. package/dist/esm/migrations/apply-schema.js.map +1 -0
  280. package/dist/esm/migrations/is-legacy-solution.d.ts +24 -0
  281. package/dist/esm/migrations/is-legacy-solution.js +35 -0
  282. package/dist/esm/migrations/is-legacy-solution.js.map +1 -0
  283. package/dist/esm/migrations/upgrade-three-dot-one.d.ts +26 -0
  284. package/dist/esm/migrations/upgrade-three-dot-one.js +44 -0
  285. package/dist/esm/migrations/upgrade-three-dot-one.js.map +1 -0
  286. package/dist/esm/migrations/upgrade-three-dot-zero.d.ts +27 -0
  287. package/dist/esm/migrations/upgrade-three-dot-zero.js +39 -0
  288. package/dist/esm/migrations/upgrade-three-dot-zero.js.map +1 -0
  289. package/dist/esm/migrations/upgrade-two-dot-five.d.ts +24 -0
  290. package/dist/esm/migrations/upgrade-two-dot-five.js +69 -0
  291. package/dist/esm/migrations/upgrade-two-dot-five.js.map +1 -0
  292. package/dist/esm/migrations/upgrade-two-dot-four.d.ts +24 -0
  293. package/dist/esm/migrations/upgrade-two-dot-four.js +68 -0
  294. package/dist/esm/migrations/upgrade-two-dot-four.js.map +1 -0
  295. package/dist/esm/migrations/upgrade-two-dot-one.d.ts +7 -0
  296. package/dist/esm/migrations/upgrade-two-dot-one.js +35 -0
  297. package/dist/esm/migrations/upgrade-two-dot-one.js.map +1 -0
  298. package/dist/esm/migrations/upgrade-two-dot-seven.d.ts +23 -0
  299. package/dist/esm/migrations/upgrade-two-dot-seven.js +54 -0
  300. package/dist/esm/migrations/upgrade-two-dot-seven.js.map +1 -0
  301. package/dist/esm/migrations/upgrade-two-dot-six.d.ts +27 -0
  302. package/dist/esm/migrations/upgrade-two-dot-six.js +57 -0
  303. package/dist/esm/migrations/upgrade-two-dot-six.js.map +1 -0
  304. package/dist/esm/migrations/upgrade-two-dot-three.d.ts +23 -0
  305. package/dist/esm/migrations/upgrade-two-dot-three.js +51 -0
  306. package/dist/esm/migrations/upgrade-two-dot-three.js.map +1 -0
  307. package/dist/esm/migrations/upgrade-two-dot-two.d.ts +23 -0
  308. package/dist/esm/migrations/upgrade-two-dot-two.js +54 -0
  309. package/dist/esm/migrations/upgrade-two-dot-two.js.map +1 -0
  310. package/dist/esm/migrations/upgrade-two-dot-zero.d.ts +44 -0
  311. package/dist/esm/migrations/upgrade-two-dot-zero.js +88 -0
  312. package/dist/esm/migrations/upgrade-two-dot-zero.js.map +1 -0
  313. package/dist/esm/migrator.d.ts +25 -0
  314. package/dist/esm/migrator.js +71 -0
  315. package/dist/esm/migrator.js.map +1 -0
  316. package/dist/esm/resourceHelpers.d.ts +192 -0
  317. package/dist/esm/resourceHelpers.js +361 -0
  318. package/dist/esm/resourceHelpers.js.map +1 -0
  319. package/dist/esm/resources/add-resource.d.ts +38 -0
  320. package/dist/esm/resources/add-resource.js +79 -0
  321. package/dist/esm/resources/add-resource.js.map +1 -0
  322. package/dist/esm/resources/addMetadataFromBlob.d.ts +25 -0
  323. package/dist/esm/resources/addMetadataFromBlob.js +39 -0
  324. package/dist/esm/resources/addMetadataFromBlob.js.map +1 -0
  325. package/dist/esm/resources/convert-item-resource-to-storage-resource.d.ts +32 -0
  326. package/dist/esm/resources/convert-item-resource-to-storage-resource.js +66 -0
  327. package/dist/esm/resources/convert-item-resource-to-storage-resource.js.map +1 -0
  328. package/dist/esm/resources/convert-storage-resource-to-item-resource.d.ts +29 -0
  329. package/dist/esm/resources/convert-storage-resource-to-item-resource.js +66 -0
  330. package/dist/esm/resources/convert-storage-resource-to-item-resource.js.map +1 -0
  331. package/dist/esm/resources/copyAssociatedFiles.d.ts +79 -0
  332. package/dist/esm/resources/copyAssociatedFiles.js +339 -0
  333. package/dist/esm/resources/copyAssociatedFiles.js.map +1 -0
  334. package/dist/esm/resources/copyDataIntoItem.d.ts +34 -0
  335. package/dist/esm/resources/copyDataIntoItem.js +40 -0
  336. package/dist/esm/resources/copyDataIntoItem.js.map +1 -0
  337. package/dist/esm/resources/copyMetadataIntoItem.d.ts +27 -0
  338. package/dist/esm/resources/copyMetadataIntoItem.js +40 -0
  339. package/dist/esm/resources/copyMetadataIntoItem.js.map +1 -0
  340. package/dist/esm/resources/copyResourceIntoZip.d.ts +34 -0
  341. package/dist/esm/resources/copyResourceIntoZip.js +69 -0
  342. package/dist/esm/resources/copyResourceIntoZip.js.map +1 -0
  343. package/dist/esm/resources/copyZipIntoItem.d.ts +26 -0
  344. package/dist/esm/resources/copyZipIntoItem.js +49 -0
  345. package/dist/esm/resources/copyZipIntoItem.js.map +1 -0
  346. package/dist/esm/resources/createCopyResults.d.ts +25 -0
  347. package/dist/esm/resources/createCopyResults.js +32 -0
  348. package/dist/esm/resources/createCopyResults.js.map +1 -0
  349. package/dist/esm/resources/get-blob.d.ts +25 -0
  350. package/dist/esm/resources/get-blob.js +38 -0
  351. package/dist/esm/resources/get-blob.js.map +1 -0
  352. package/dist/esm/resources/getItemResourcesFilesFromPaths.d.ts +25 -0
  353. package/dist/esm/resources/getItemResourcesFilesFromPaths.js +45 -0
  354. package/dist/esm/resources/getItemResourcesFilesFromPaths.js.map +1 -0
  355. package/dist/esm/resources/getItemResourcesPaths.d.ts +27 -0
  356. package/dist/esm/resources/getItemResourcesPaths.js +76 -0
  357. package/dist/esm/resources/getItemResourcesPaths.js.map +1 -0
  358. package/dist/esm/resources/index.d.ts +30 -0
  359. package/dist/esm/resources/index.js +31 -0
  360. package/dist/esm/resources/index.js.map +1 -0
  361. package/dist/esm/resources/solution-resource.d.ts +35 -0
  362. package/dist/esm/resources/solution-resource.js +28 -0
  363. package/dist/esm/resources/solution-resource.js.map +1 -0
  364. package/dist/esm/resources/transform-resource-paths-to-solution-resources.d.ts +56 -0
  365. package/dist/esm/resources/transform-resource-paths-to-solution-resources.js +132 -0
  366. package/dist/esm/resources/transform-resource-paths-to-solution-resources.js.map +1 -0
  367. package/dist/esm/resources/update-resource.d.ts +27 -0
  368. package/dist/esm/resources/update-resource.js +48 -0
  369. package/dist/esm/resources/update-resource.js.map +1 -0
  370. package/dist/esm/restHelpers.d.ts +634 -0
  371. package/dist/esm/restHelpers.js +1943 -0
  372. package/dist/esm/restHelpers.js.map +1 -0
  373. package/dist/esm/restHelpersGet.d.ts +303 -0
  374. package/dist/esm/restHelpersGet.js +793 -0
  375. package/dist/esm/restHelpersGet.js.map +1 -0
  376. package/dist/esm/sharing/index.d.ts +16 -0
  377. package/dist/esm/sharing/index.js +17 -0
  378. package/dist/esm/sharing/index.js.map +1 -0
  379. package/dist/esm/sharing/share-item-to-groups.d.ts +26 -0
  380. package/dist/esm/sharing/share-item-to-groups.js +40 -0
  381. package/dist/esm/sharing/share-item-to-groups.js.map +1 -0
  382. package/dist/esm/templatization.d.ts +139 -0
  383. package/dist/esm/templatization.js +291 -0
  384. package/dist/esm/templatization.js.map +1 -0
  385. package/dist/esm/trackingHelpers.d.ts +115 -0
  386. package/dist/esm/trackingHelpers.js +200 -0
  387. package/dist/esm/trackingHelpers.js.map +1 -0
  388. package/dist/esm/velocityHelpers.d.ts +68 -0
  389. package/dist/esm/velocityHelpers.js +144 -0
  390. package/dist/esm/velocityHelpers.js.map +1 -0
  391. package/dist/esm/webtoolHelpers.d.ts +57 -0
  392. package/dist/esm/webtoolHelpers.js +95 -0
  393. package/dist/esm/webtoolHelpers.js.map +1 -0
  394. package/dist/esm/workflowHelpers.d.ts +112 -0
  395. package/dist/esm/workflowHelpers.js +270 -0
  396. package/dist/esm/workflowHelpers.js.map +1 -0
  397. package/dist/esm/workforceHelpers.d.ts +121 -0
  398. package/dist/esm/workforceHelpers.js +691 -0
  399. package/dist/esm/workforceHelpers.js.map +1 -0
  400. package/dist/esm/zip-utils.d.ts +85 -0
  401. package/dist/esm/zip-utils.js +142 -0
  402. package/dist/esm/zip-utils.js.map +1 -0
  403. package/dist/solution.js_commit.txt +7 -0
  404. package/package.json +2 -2
@@ -0,0 +1,2553 @@
1
+ "use strict";
2
+ /** @license
3
+ * Copyright 2019 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._validateEditFieldsInfo = exports._validateTypesTemplates = exports._validateTemplatesFields = exports._validateIndexes = exports._validateDisplayField = exports._validateFields = exports._templatizeLayer = exports._templatizeProperty = exports._templatize = exports.updatePopupInfo = exports._validateViewDomainFields = exports.postProcessFields = exports.updateLayerFieldReferences = exports._getSourceSpatialReferenceAndExtent = exports.validateSpatialReferenceAndExtent = exports.setDefaultSpatialReference = exports._updateTemplateDictionaryFields = exports._updateGeomFieldName = exports._updateSourceLayerFields = exports._updateItemFields = exports._getDynamicFieldNames = exports._getFieldNames = exports._updateForPortal = exports.removeLayerOptimization = exports._isSelfReferential = exports._updateAddOptions = exports._updateOrder = exports.addFeatureServiceDefinition = exports.addFeatureServiceLayersAndTables = exports.getExistingLayersAndTables = exports.getLayersAndTables = exports.deTemplatizeFieldInfos = exports.processContingentValues = exports.updateTemplateForInvalidDesignations = exports.updateSettingsFieldInfos = exports.setNamesAndTitles = exports.getLayerSettings = exports._setTrackingViewLayerSettings = exports._updateTypeKeywords = exports.updateTemplate = exports.cacheLayerInfo = exports._cachePopupInfo = exports.cachePopupInfos = exports._cacheFieldInfo = exports.cacheIndexes = exports.cacheContingentValues = exports.cacheFieldInfos = exports.deleteViewProps = exports.templatize = exports.getFeatureServiceRelatedRecords = void 0;
19
+ exports._getLayerChunkSize = exports._getNameMapping = exports._templatizeDefinitionQuery = exports._templatizeTimeInfo = exports._templatizeKeys = exports._templatizeTypeTemplates = exports._templatizeTemplates = exports._templatizeLabelingInfo = exports._templatizeArcadeExpressions = exports._templatizeAuthoringInfo = exports._templatizeTemporalRenderer = exports._templatizeGenRenderer = exports._templatizeRenderer = exports._templatizeDrawingInfo = exports._templatizeSimpleName = exports._templatizeDefinitionExpression = exports._templatizeDefinitionEditor = exports._templatizeMediaInfos = exports._templatizePopupElements = exports._templatizeExpressionInfos = exports._templatizeFieldName = exports._templatizePopupInfoFieldInfos = exports._templatizeName = exports._templatizePopupInfo = exports._templatizeRelationshipFields = exports._templatizeTopFilter = exports._templatizeAdminSourceLayerFields = exports._getDependantItemId = exports._templatizeAdminLayerInfoFields = exports._templatizeSourceServiceName = exports._processAdminObject = exports._templatizeAdminLayerInfo = exports._templatizeLayerFieldReferences = void 0;
20
+ /**
21
+ * Provides general helper functions.
22
+ *
23
+ * @module featureServiceHelpers
24
+ */
25
+ // ------------------------------------------------------------------------------------------------------------------ //
26
+ //#region Imports -------------------------------------------------------------------------------------------------------//
27
+ const interfaces_1 = require("./interfaces");
28
+ const generalHelpers_1 = require("./generalHelpers");
29
+ const templatization_1 = require("./templatization");
30
+ const restHelpers_1 = require("./restHelpers");
31
+ const trackingHelpers_1 = require("./trackingHelpers");
32
+ const arcgisRestJS_1 = require("./arcgisRestJS");
33
+ //#endregion ------------------------------------------------------------------------------------------------------------//
34
+ //#region Public functions ----------------------------------------------------------------------------------------------//
35
+ /**
36
+ * Get the related records for a feature service.
37
+ *
38
+ * @param url Feature service's URL, e.g., layer.url
39
+ * @param relationshipId Id of relationship
40
+ * @param objectIds Objects in the feature service whose related records are sought
41
+ */
42
+ function getFeatureServiceRelatedRecords(url, relationshipId, objectIds) {
43
+ const options = {
44
+ url: url + `/${relationshipId}`,
45
+ relationshipId,
46
+ objectIds,
47
+ };
48
+ return (0, arcgisRestJS_1.queryRelated)(options);
49
+ }
50
+ exports.getFeatureServiceRelatedRecords = getFeatureServiceRelatedRecords;
51
+ /**
52
+ * Templatize the ID, url, field references ect
53
+ *
54
+ * @param itemTemplate Template for feature service item
55
+ * @param dependencies Array of IDependency for name mapping
56
+ * @param templatizeFieldReferences Templatize all field references within a layer
57
+ * @param templateDictionary Hash mapping property names to replacement values
58
+ * @returns A promise that will resolve when template has been updated
59
+ * @private
60
+ */
61
+ function templatize(itemTemplate, dependencies, templatizeFieldReferences, templateDictionary) {
62
+ templateDictionary = templateDictionary || {};
63
+ // Common templatizations
64
+ const id = itemTemplate.item.id;
65
+ const fsUrl = itemTemplate.item.url;
66
+ itemTemplate.item = {
67
+ ...itemTemplate.item,
68
+ id: (0, templatization_1.templatizeTerm)(id, id, ".itemId"),
69
+ url: _templatize(id, "url"),
70
+ typeKeywords: (0, templatization_1.templatizeIds)(itemTemplate.item.typeKeywords),
71
+ };
72
+ // special handeling if we are dealing with a tracker view
73
+ (0, trackingHelpers_1.templatizeTracker)(itemTemplate);
74
+ // added for issue #928
75
+ (0, generalHelpers_1.deleteProp)(itemTemplate, "properties.service.size");
76
+ const jsonLayers = itemTemplate.properties.layers || [];
77
+ const jsonTables = itemTemplate.properties.tables || [];
78
+ const jsonItems = jsonLayers.concat(jsonTables);
79
+ const data = itemTemplate.data || {};
80
+ const layers = data.layers || [];
81
+ const tables = data.tables || [];
82
+ const _items = layers.concat(tables);
83
+ // Set up symbols for the URL of the feature service and its layers and tables
84
+ templateDictionary[fsUrl] = itemTemplate.item.url; // map FS URL to its templatized form
85
+ jsonItems.concat(_items).forEach((layer) => {
86
+ templateDictionary[fsUrl + "/" + layer.id] = _templatize(id, "layer" + layer.id + ".url");
87
+ });
88
+ // templatize the service references serviceItemId
89
+ itemTemplate.properties.service.serviceItemId = (0, templatization_1.templatizeTerm)(itemTemplate.properties.service.serviceItemId, itemTemplate.properties.service.serviceItemId, ".itemId");
90
+ const initialExtent = (0, generalHelpers_1.getProp)(itemTemplate, "properties.service.initialExtent");
91
+ /* istanbul ignore else */
92
+ if (initialExtent) {
93
+ itemTemplate.properties.service.initialExtent = (0, templatization_1.templatizeTerm)(id, id, ".solutionExtent");
94
+ }
95
+ const fullExtent = (0, generalHelpers_1.getProp)(itemTemplate, "properties.service.fullExtent");
96
+ /* istanbul ignore else */
97
+ if (fullExtent) {
98
+ itemTemplate.properties.service.fullExtent = (0, templatization_1.templatizeTerm)(id, id, ".solutionExtent");
99
+ }
100
+ // this default extent will be used in cases where it does not make sense to apply the orgs
101
+ // extent to a service with a local spatial reference
102
+ itemTemplate.properties.defaultExtent = initialExtent || fullExtent;
103
+ // in some cases a service does not have a spatial reference defined
104
+ // added for issue #699
105
+ if (!(0, generalHelpers_1.getProp)(itemTemplate, "properties.service.spatialReference") &&
106
+ (0, generalHelpers_1.getProp)(itemTemplate, "properties.defaultExtent.spatialReference")) {
107
+ (0, generalHelpers_1.setCreateProp)(itemTemplate, "properties.service.spatialReference", itemTemplate.properties.defaultExtent.spatialReference);
108
+ }
109
+ // if any layer hasZ enabled then we need to set
110
+ // enableZDefaults and zDefault to deploy to enterprise
111
+ let hasZ = false;
112
+ jsonItems.forEach((jsonItem) => {
113
+ // get the source service json for the given data item
114
+ const matchingItems = _items.filter((item) => {
115
+ return jsonItem.id === item.id;
116
+ });
117
+ // templatize the source service json
118
+ const _item = matchingItems.length === 1 ? matchingItems[0] : undefined;
119
+ _templatizeLayer(_item, jsonItem, itemTemplate, dependencies, templatizeFieldReferences, templateDictionary);
120
+ hasZ = jsonItem.hasZ || (_item && _item.hasZ) ? true : hasZ;
121
+ });
122
+ if (hasZ) {
123
+ itemTemplate.properties.service.enableZDefaults = true;
124
+ itemTemplate.properties.service.zDefault = 0;
125
+ }
126
+ return itemTemplate;
127
+ }
128
+ exports.templatize = templatize;
129
+ /**
130
+ * Delete key properties that are system managed
131
+ *
132
+ * @param layer The data layer instance with field name references within
133
+ * @param isPortal When true we are deploying to portal
134
+ */
135
+ function deleteViewProps(layer, isPortal) {
136
+ const props = ["definitionQuery"];
137
+ const portalOnlyProps = ["indexes"];
138
+ props.forEach((prop) => (0, generalHelpers_1.deleteProp)(layer, prop));
139
+ if (isPortal) {
140
+ portalOnlyProps.forEach((prop) => {
141
+ (0, generalHelpers_1.deleteProp)(layer, prop);
142
+ });
143
+ }
144
+ }
145
+ exports.deleteViewProps = deleteViewProps;
146
+ /**
147
+ * Cache properties that contain field references
148
+ *
149
+ * removeProp added for issue #644
150
+ * setting all props on add for online now
151
+ * investigating if we can also just allow them to be set during add for portal
152
+ *
153
+ * @param layer The data layer instance with field name references within
154
+ * @param fieldInfos the object that stores the cached field infos
155
+ * @param isView When true the current layer is a view and does not need to cache subtype details
156
+ * @param isPortal When true we are deploying to portal
157
+ * @returns An updated instance of the fieldInfos
158
+ */
159
+ function cacheFieldInfos(layer, fieldInfos, isView, isPortal) {
160
+ // cache the source fields as they are in the original source
161
+ if (layer && layer.fields) {
162
+ fieldInfos[layer.id] = {
163
+ sourceFields: JSON.parse(JSON.stringify(layer.fields)),
164
+ type: layer.type,
165
+ id: layer.id,
166
+ };
167
+ /* istanbul ignore else */
168
+ if (!isView && isPortal) {
169
+ fieldInfos[layer.id].subtypes = layer.subtypes;
170
+ fieldInfos[layer.id].subtypeField = layer.subtypeField;
171
+ fieldInfos[layer.id].defaultSubtypeCode = layer.defaultSubtypeCode;
172
+ }
173
+ }
174
+ // cache each of these properties as they each can contain field references
175
+ // and will have associated updateDefinition calls when deploying to portal
176
+ // as well as online for relationships...as relationships added with addToDef will cause failure
177
+ // https://devtopia.esri.com/WebGIS/solutions-development-support/issues/299
178
+ // subtypes, subtypeField, and defaultSubtypeCode should not exist in initial addToDef call and
179
+ // should be added with subsequent add and update calls in a specific order
180
+ const props = {
181
+ editFieldsInfo: false,
182
+ types: false,
183
+ templates: false,
184
+ relationships: true,
185
+ drawingInfo: false,
186
+ timeInfo: false,
187
+ viewDefinitionQuery: false,
188
+ };
189
+ /* istanbul ignore else */
190
+ if (!isView && isPortal) {
191
+ props["subtypes"] = true;
192
+ props["subtypeField"] = true;
193
+ props["defaultSubtypeCode"] = true;
194
+ }
195
+ Object.keys(props).forEach((k) => {
196
+ _cacheFieldInfo(layer, k, fieldInfos, props[k]);
197
+ });
198
+ return fieldInfos;
199
+ }
200
+ exports.cacheFieldInfos = cacheFieldInfos;
201
+ /**
202
+ * Cache the stored contingent values so we can add them in subsequent addToDef calls
203
+ *
204
+ * @param id The layer id for the associated values to be stored with
205
+ * @param fieldInfos The object that stores the cached field infos
206
+ * @param itemTemplate The current itemTemplate being processed
207
+ * @returns An updated instance of the fieldInfos
208
+ */
209
+ function cacheContingentValues(id, fieldInfos, itemTemplate) {
210
+ const contingentValues = (0, generalHelpers_1.getProp)(itemTemplate, "properties.contingentValues");
211
+ if (contingentValues && contingentValues[id]) {
212
+ fieldInfos[id]["contingentValues"] = contingentValues[id];
213
+ }
214
+ return fieldInfos;
215
+ }
216
+ exports.cacheContingentValues = cacheContingentValues;
217
+ /**
218
+ * Cache the stored contingent values so we can add them in subsequent addToDef calls
219
+ *
220
+ * @param layer The current layer to check indexes on
221
+ * @param fieldInfos The object that stores the cached field infos
222
+ * @returns An updated instance of the fieldInfos
223
+ */
224
+ function cacheIndexes(layer, fieldInfos, isView, isMsView) {
225
+ /* istanbul ignore else */
226
+ if (!isView && !isMsView && Array.isArray(layer.indexes)) {
227
+ const oidField = layer.objectIdField;
228
+ const guidField = layer.globalIdField;
229
+ fieldInfos[layer.id].indexes = layer.indexes.filter((i) => {
230
+ if ((i.isUnique && i.fields !== oidField && i.fields !== guidField) || i.indexType === "FullText") {
231
+ if (i.name) {
232
+ delete i.name;
233
+ }
234
+ return i;
235
+ }
236
+ });
237
+ delete layer.indexes;
238
+ }
239
+ return fieldInfos;
240
+ }
241
+ exports.cacheIndexes = cacheIndexes;
242
+ /**
243
+ * Helper function to cache a single property into the fieldInfos object
244
+ * This property will be removed from the layer instance.
245
+ *
246
+ * @param layer the data layer being cloned
247
+ * @param prop the property name used to cache
248
+ * @param fieldInfos the object that will store the cached property
249
+ * @param removeProp when true relationships prop will be set to null and subtype props will be deleted
250
+ * @private
251
+ */
252
+ function _cacheFieldInfo(layer, prop, fieldInfos, removeProp) {
253
+ /* istanbul ignore else */
254
+ if (layer && layer.hasOwnProperty(prop) && fieldInfos && fieldInfos.hasOwnProperty(layer.id)) {
255
+ fieldInfos[layer.id][prop] = layer[prop];
256
+ // editFieldsInfo does not come through unless its with the layer
257
+ // when it's being added
258
+ /* istanbul ignore else */
259
+ if (removeProp && prop === "relationships") {
260
+ layer[prop] = null;
261
+ }
262
+ else if (removeProp) {
263
+ delete layer[prop];
264
+ }
265
+ }
266
+ }
267
+ exports._cacheFieldInfo = _cacheFieldInfo;
268
+ /**
269
+ * Cache popup info that can contain field references
270
+ *
271
+ * @param data The items data property
272
+ * @returns An updated instance of the popupInfos
273
+ */
274
+ function cachePopupInfos(data) {
275
+ // store any popupInfo so we can update after any potential name changes
276
+ const popupInfos = {
277
+ layers: {},
278
+ tables: {},
279
+ };
280
+ if (data && data.layers && data.layers.length > 0) {
281
+ _cachePopupInfo(popupInfos, "layers", data.layers);
282
+ }
283
+ if (data && data.tables && data.tables.length > 0) {
284
+ _cachePopupInfo(popupInfos, "tables", data.tables);
285
+ }
286
+ return popupInfos;
287
+ }
288
+ exports.cachePopupInfos = cachePopupInfos;
289
+ /**
290
+ * Helper function to cache a single popupInfo
291
+ * This property will be reset on the layer
292
+ *
293
+ * @param popupInfos object to store the cahced popupInfo
294
+ * @param type is it a layer or table
295
+ * @param _items list or either layers or tables
296
+ * @private
297
+ */
298
+ function _cachePopupInfo(popupInfos, type, _items) {
299
+ _items.forEach((item) => {
300
+ if (item && item.hasOwnProperty("popupInfo")) {
301
+ popupInfos[type][item.id] = item.popupInfo;
302
+ item.popupInfo = {};
303
+ }
304
+ });
305
+ }
306
+ exports._cachePopupInfo = _cachePopupInfo;
307
+ /**
308
+ * Store basic layer information for potential replacement if we are unable to access a given service
309
+ * added for issue #859
310
+ *
311
+ * @param layerId the id for the layer
312
+ * @param itemId the id for the item
313
+ * @param url the url for the layer
314
+ * @param templateDictionary Hash of key details used for variable replacement
315
+ * @returns templatized itemTemplate
316
+ */
317
+ function cacheLayerInfo(layerId, itemId, url, templateDictionary) {
318
+ if (layerId) {
319
+ const layerIdVar = `layer${layerId}`;
320
+ // need to structure these differently so they are not used for standard replacement calls
321
+ // this now adds additional vars that are not needing replacement unless we fail to fetch the service
322
+ const newVars = (0, generalHelpers_1.getProp)(templateDictionary, `${interfaces_1.UNREACHABLE}.${itemId}`) || {
323
+ itemId,
324
+ };
325
+ newVars[layerIdVar] = (0, generalHelpers_1.getProp)(newVars, layerIdVar) || {
326
+ layerId,
327
+ itemId,
328
+ };
329
+ if (url !== "") {
330
+ newVars[layerIdVar]["url"] = url;
331
+ }
332
+ const unreachableVars = {};
333
+ unreachableVars[itemId] = newVars;
334
+ templateDictionary[interfaces_1.UNREACHABLE] = {
335
+ ...templateDictionary[interfaces_1.UNREACHABLE],
336
+ ...unreachableVars,
337
+ };
338
+ }
339
+ }
340
+ exports.cacheLayerInfo = cacheLayerInfo;
341
+ /**
342
+ * Creates an item in a specified folder (except for Group item type).
343
+ *
344
+ * @param itemTemplate Item to be created; n.b.: this item is modified
345
+ * @param templateDictionary Hash mapping property names to replacement values
346
+ * @param createResponse Response from create service
347
+ * @returns An updated instance of the template
348
+ * @private
349
+ */
350
+ function updateTemplate(itemTemplate, templateDictionary, createResponse) {
351
+ // Update the item with any typeKeywords that were added on create
352
+ _updateTypeKeywords(itemTemplate, createResponse);
353
+ // Add the new item to the template dictionary
354
+ templateDictionary[itemTemplate.itemId] = Object.assign(templateDictionary[itemTemplate.itemId] || {}, {
355
+ itemId: createResponse.serviceItemId,
356
+ url: (0, generalHelpers_1.checkUrlPathTermination)(createResponse.serviceurl),
357
+ name: createResponse.name,
358
+ });
359
+ // Update the item template now that the new service has been created
360
+ itemTemplate.itemId = createResponse.serviceItemId;
361
+ return (0, templatization_1.replaceInTemplate)(itemTemplate, templateDictionary);
362
+ }
363
+ exports.updateTemplate = updateTemplate;
364
+ /**
365
+ * Updates the items typeKeywords to include any typeKeywords that
366
+ * were added by the create service request
367
+ *
368
+ * @param itemTemplate Item to be created; n.b.: this item is modified
369
+ * @param createResponse Response from create service
370
+ * @returns An updated instance of the template
371
+ * @private
372
+ */
373
+ function _updateTypeKeywords(itemTemplate, createResponse) {
374
+ // https://github.com/Esri/solution.js/issues/589
375
+ const iKwords = (0, generalHelpers_1.getProp)(itemTemplate, "item.typeKeywords");
376
+ const cKwords = (0, generalHelpers_1.getProp)(createResponse, "typeKeywords");
377
+ if (iKwords && cKwords) {
378
+ (0, generalHelpers_1.setProp)(itemTemplate, "item.typeKeywords", iKwords.concat(cKwords.filter((k) => iKwords.indexOf(k) < 0)));
379
+ }
380
+ return itemTemplate;
381
+ }
382
+ exports._updateTypeKeywords = _updateTypeKeywords;
383
+ /**
384
+ * Add layer urls from tracking views to the templateDictionary to be used for adlib replacements
385
+ *
386
+ * @param itemTemplate Item to be created; n.b.: this item is modified
387
+ * @param templateDictionary Hash mapping property names to replacement values
388
+ * @returns void
389
+ * @private
390
+ */
391
+ function _setTrackingViewLayerSettings(itemTemplate, templateDictionary) {
392
+ const url = itemTemplate.item.url;
393
+ const newId = itemTemplate.itemId;
394
+ let k;
395
+ Object.keys(templateDictionary).some((_k) => {
396
+ if (newId === templateDictionary[_k].itemId) {
397
+ k = _k;
398
+ return true;
399
+ }
400
+ });
401
+ itemTemplate.properties.layers.forEach((l) => {
402
+ const id = l.id.toString();
403
+ templateDictionary[k][`layer${id}`] = {
404
+ url: (0, generalHelpers_1.checkUrlPathTermination)(url) + id,
405
+ };
406
+ });
407
+ }
408
+ exports._setTrackingViewLayerSettings = _setTrackingViewLayerSettings;
409
+ /**
410
+ * Create the name mapping object that will allow for all templatized field
411
+ * references to be de-templatized.
412
+ * This also removes the stored sourceFields and newFields arrays from fieldInfos.
413
+ *
414
+ * @example
415
+ * \{ layer0: \{ fields: \{ lowerCaseSourceFieldName: newFieldNameAfterDeployment \} \} \}
416
+ *
417
+ * @param layerInfos The object that stores the cached layer properties and name mapping
418
+ * @returns The settings object that will be used to de-templatize the field references.
419
+ */
420
+ function getLayerSettings(layerInfos, url, itemId, enterpriseIDMapping) {
421
+ const settings = {};
422
+ const ids = Object.keys(layerInfos);
423
+ ids.forEach((id) => {
424
+ const _layerId = (0, generalHelpers_1.getProp)(layerInfos[id], "item.id");
425
+ const isNum = parseInt(_layerId, 10) > -1;
426
+ const layerId = isNum && enterpriseIDMapping ? enterpriseIDMapping[_layerId] : isNum ? _layerId : id;
427
+ settings[`layer${isNum ? _layerId : id}`] = {
428
+ fields: _getNameMapping(layerInfos, id),
429
+ url: (0, generalHelpers_1.checkUrlPathTermination)(url) + layerId,
430
+ layerId,
431
+ itemId,
432
+ };
433
+ (0, generalHelpers_1.deleteProp)(layerInfos[id], "newFields");
434
+ (0, generalHelpers_1.deleteProp)(layerInfos[id], "sourceFields");
435
+ });
436
+ return settings;
437
+ }
438
+ exports.getLayerSettings = getLayerSettings;
439
+ /**
440
+ * Set the names and titles for all feature services.
441
+ *
442
+ * This function will ensure that we have unique feature service names.
443
+ * The feature service name will have a generated GUID appended.
444
+ *
445
+ * @param templates A collection of AGO item templates.
446
+ * @returns An updated collection of AGO templates with unique feature service names.
447
+ */
448
+ function setNamesAndTitles(templates) {
449
+ const guid = (0, generalHelpers_1.generateGUID)();
450
+ const names = [];
451
+ return templates.map((t) => {
452
+ /* istanbul ignore else */
453
+ if (t.item.type === "Feature Service") {
454
+ // Retain the existing title but swap with name if it's missing
455
+ t.item.title = t.item.title || t.item.name;
456
+ /* istanbul ignore else */
457
+ if (!(0, trackingHelpers_1.isTrackingViewTemplate)(t)) {
458
+ // Need to set the service name: name + "_" + newItemId
459
+ let baseName = t.item.name || t.item.title;
460
+ // If the name already contains a GUID remove it
461
+ baseName = baseName.replace(/_[0-9A-F]{32}/gi, "");
462
+ // The name length limit is 98
463
+ // Limit the baseName to 50 characters before the _<guid>
464
+ const name = baseName.substring(0, 50) + "_" + guid;
465
+ // If the name + GUID already exists then append "_occurrenceCount"
466
+ t.item.name = names.indexOf(name) === -1 ? name : `${name}_${names.filter((n) => n === name).length}`;
467
+ names.push(name);
468
+ }
469
+ }
470
+ return t;
471
+ });
472
+ }
473
+ exports.setNamesAndTitles = setNamesAndTitles;
474
+ /**
475
+ * This is used when deploying views.
476
+ * We need to update fields referenced in adminLayerInfo for relationships prior to deploying the view.
477
+ * This moves the fieldInfos for the views source layers from the item settings for the source layer
478
+ * to the item settings for the view.
479
+ *
480
+ * @param itemTemplate The current itemTemplate being processed.
481
+ * @param settings The settings object used to de-templatize the various templates within the item.
482
+ */
483
+ function updateSettingsFieldInfos(itemTemplate, settings) {
484
+ const dependencies = itemTemplate.dependencies;
485
+ const id = itemTemplate.itemId;
486
+ const settingsKeys = Object.keys(settings);
487
+ settingsKeys.forEach((k) => {
488
+ if (id === settings[k].itemId) {
489
+ dependencies.forEach((d) => {
490
+ settingsKeys.forEach((_k) => {
491
+ /* istanbul ignore else */
492
+ if (d === _k) {
493
+ // combine for multi-source views
494
+ const fieldInfos = {};
495
+ fieldInfos[d] = (0, generalHelpers_1.getProp)(settings[_k], "fieldInfos");
496
+ settings[k]["sourceServiceFields"] = settings[k]["sourceServiceFields"]
497
+ ? { ...settings[k]["sourceServiceFields"], ...fieldInfos }
498
+ : fieldInfos;
499
+ const layerKeys = Object.keys(settings[_k]);
500
+ layerKeys.forEach((layerKey) => {
501
+ /* istanbul ignore else */
502
+ if (layerKey.startsWith("layer")) {
503
+ settings[k][layerKey] = settings[_k][layerKey];
504
+ }
505
+ });
506
+ }
507
+ });
508
+ });
509
+ }
510
+ });
511
+ }
512
+ exports.updateSettingsFieldInfos = updateSettingsFieldInfos;
513
+ /**
514
+ * Add flag to indicate item should be ignored.
515
+ * Construct template dictionary to detemplatize any references to this item by other items.
516
+ *
517
+ * @param template Template for feature service item
518
+ * @param authentication Credentials for the request
519
+ * @returns A promise that will resolve when template has been updated
520
+ * @private
521
+ */
522
+ function updateTemplateForInvalidDesignations(template, authentication) {
523
+ return new Promise((resolve, reject) => {
524
+ template.properties.hasInvalidDesignations = true;
525
+ if (template.item.url) {
526
+ // get the admin URL
527
+ const url = template.item.url;
528
+ (0, arcgisRestJS_1.request)(url + "?f=json", {
529
+ authentication: authentication,
530
+ }).then((serviceData) => {
531
+ const layerInfos = {};
532
+ const layersAndTables = (serviceData.layers || []).concat(serviceData.tables || []);
533
+ layersAndTables.forEach((l) => {
534
+ /* istanbul ignore else */
535
+ if (l && l.hasOwnProperty("id")) {
536
+ layerInfos[l.id] = l;
537
+ }
538
+ });
539
+ template.data[template.itemId] = Object.assign({
540
+ itemId: template.itemId,
541
+ }, getLayerSettings(layerInfos, url, template.itemId));
542
+ resolve(template);
543
+ }, (e) => reject((0, generalHelpers_1.fail)(e)));
544
+ }
545
+ else {
546
+ resolve(template);
547
+ }
548
+ });
549
+ }
550
+ exports.updateTemplateForInvalidDesignations = updateTemplateForInvalidDesignations;
551
+ /**
552
+ * Get the contingent values for each layer in the service.
553
+ * Remove key props that cannot be included with the addToDef call on deploy.
554
+ * Store the values alongside other key feature service properties in the template
555
+ *
556
+ * @param properties the current feature services properties
557
+ * @param adminUrl the current feature service url
558
+ * @param authentication Credentials for the request to AGOL
559
+ * @returns A promise that will resolve when the contingent values have been fetched.
560
+ * This function will update the provided properties argument when contingent values are found.
561
+ */
562
+ function processContingentValues(properties, adminUrl, authentication) {
563
+ return new Promise((resolve, reject) => {
564
+ if ((0, generalHelpers_1.getProp)(properties, "service.isView")) {
565
+ // views will inherit from the source service
566
+ resolve();
567
+ }
568
+ else {
569
+ const layersAndTables = (properties.layers || []).concat(properties.tables || []);
570
+ const layerIds = [];
571
+ const contingentValuePromises = layersAndTables.reduce((prev, cur) => {
572
+ /* istanbul ignore else */
573
+ if (cur.hasContingentValuesDefinition) {
574
+ prev.push((0, arcgisRestJS_1.request)(`${adminUrl}/${cur["id"]}/contingentValues?f=json`, {
575
+ authentication,
576
+ }));
577
+ layerIds.push(cur["id"]);
578
+ }
579
+ return prev;
580
+ }, []);
581
+ if (contingentValuePromises.length > 0) {
582
+ Promise.all(contingentValuePromises).then((results) => {
583
+ const contingentValues = {};
584
+ results.forEach((r, i) => {
585
+ (0, generalHelpers_1.deleteProp)(r, "typeCodes");
586
+ /* istanbul ignore else */
587
+ if ((0, generalHelpers_1.getProp)(r, "stringDicts") && (0, generalHelpers_1.getProp)(r, "contingentValuesDefinition")) {
588
+ r.contingentValuesDefinition["stringDicts"] = r.stringDicts;
589
+ (0, generalHelpers_1.deleteProp)(r, "stringDicts");
590
+ }
591
+ (0, generalHelpers_1.deleteProps)((0, generalHelpers_1.getProp)(r, "contingentValuesDefinition"), [
592
+ "layerID",
593
+ "layerName",
594
+ "geometryType",
595
+ "hasSubType",
596
+ ]);
597
+ contingentValues[layerIds[i]] = r;
598
+ });
599
+ properties.contingentValues = contingentValues;
600
+ resolve();
601
+ }, reject);
602
+ }
603
+ else {
604
+ resolve();
605
+ }
606
+ }
607
+ });
608
+ }
609
+ exports.processContingentValues = processContingentValues;
610
+ /**
611
+ * Replace the field name reference templates with the new field names after deployment.
612
+ *
613
+ * @param fieldInfos The object that stores the cached layer properties and name mapping
614
+ * @param popupInfos The object from the popupInfo property for the layer
615
+ * @param adminLayerInfos The object from the adminLayerInfo property for the layer
616
+ * @param settings The settings object that has all of the mappings for de-templatizing.
617
+ * @returns An object that contains updated instances of popupInfos, fieldInfos, and adminLayerInfos
618
+ */
619
+ function deTemplatizeFieldInfos(fieldInfos, popupInfos, adminLayerInfos, settings) {
620
+ const fieldInfoKeys = Object.keys(fieldInfos);
621
+ fieldInfoKeys.forEach((id) => {
622
+ if (fieldInfos[id].hasOwnProperty("templates")) {
623
+ fieldInfos[id].templates = JSON.parse((0, templatization_1.replaceInTemplate)(JSON.stringify(fieldInfos[id].templates), settings));
624
+ }
625
+ if (fieldInfos[id].hasOwnProperty("adminLayerInfo")) {
626
+ adminLayerInfos[id].viewLayerDefinition.table.relatedTables = fieldInfos[id].adminLayerInfo;
627
+ (0, generalHelpers_1.deleteProp)(fieldInfos[id], "adminLayerInfo");
628
+ }
629
+ if (fieldInfos[id].hasOwnProperty("types")) {
630
+ fieldInfos[id].types = JSON.parse((0, templatization_1.replaceInTemplate)(JSON.stringify(fieldInfos[id].types), settings));
631
+ }
632
+ });
633
+ return {
634
+ popupInfos: (0, templatization_1.replaceInTemplate)(popupInfos, settings),
635
+ fieldInfos: (0, templatization_1.replaceInTemplate)(fieldInfos, settings),
636
+ adminLayerInfos: (0, templatization_1.replaceInTemplate)(adminLayerInfos, settings),
637
+ };
638
+ }
639
+ exports.deTemplatizeFieldInfos = deTemplatizeFieldInfos;
640
+ /**
641
+ * This is used when deploying views.
642
+ * We need to update fields referenced in adminLayerInfo for relationships prior to deploying the view.
643
+ * This moves the fieldInfos for the views source layers from the item settings for the source layer
644
+ * to the item settings for the view.
645
+ *
646
+ * @param itemTemplate The current itemTemplate being processed.
647
+ * @returns array of layers and tables
648
+ */
649
+ function getLayersAndTables(itemTemplate) {
650
+ const properties = itemTemplate.properties;
651
+ const layersAndTables = [];
652
+ (properties.layers || []).forEach(function (layer) {
653
+ layersAndTables.push({
654
+ item: layer,
655
+ type: "layer",
656
+ });
657
+ });
658
+ (properties.tables || []).forEach(function (table) {
659
+ layersAndTables.push({
660
+ item: table,
661
+ type: "table",
662
+ });
663
+ });
664
+ return layersAndTables;
665
+ }
666
+ exports.getLayersAndTables = getLayersAndTables;
667
+ /**
668
+ * Fetch each layer and table from service so we can determine what fields they have.
669
+ * This is leveraged when we are using existing services so we can determine if we need to
670
+ * remove any fields from views that depend on these layers and tables.
671
+ *
672
+ * @param url Feature service endpoint
673
+ * @param ids layer and table ids
674
+ * @param authentication Credentials for the request
675
+ * @returns A promise that will resolve an array of promises with either a failure or the data
676
+ * @private
677
+ */
678
+ function getExistingLayersAndTables(url, ids, authentication) {
679
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
680
+ return new Promise((resolve) => {
681
+ const defs = ids.map((id) => {
682
+ return (0, arcgisRestJS_1.request)((0, generalHelpers_1.checkUrlPathTermination)(url) + id, {
683
+ authentication,
684
+ });
685
+ });
686
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
687
+ Promise.all(defs.map((p) => p.catch((e) => e))).then(resolve);
688
+ });
689
+ }
690
+ exports.getExistingLayersAndTables = getExistingLayersAndTables;
691
+ /**
692
+ * Adds the layers and tables of a feature service to it and restores their relationships.
693
+ *
694
+ * @param itemTemplate Feature service
695
+ * @param templateDictionary Hash mapping Solution source id to id of its clone (and name & URL for feature
696
+ * service)
697
+ * @param popupInfos the cached popup info from the layers
698
+ * @param authentication Credentials for the request
699
+ * @returns A promise that will resolve when all layers and tables have been added
700
+ * @private
701
+ */
702
+ function addFeatureServiceLayersAndTables(itemTemplate, templateDictionary, popupInfos, authentication) {
703
+ return new Promise((resolve, reject) => {
704
+ if ((0, trackingHelpers_1.isTrackingViewTemplate)(itemTemplate)) {
705
+ _setTrackingViewLayerSettings(itemTemplate, templateDictionary);
706
+ resolve(null);
707
+ }
708
+ else {
709
+ // Create a hash of various properties that contain field references
710
+ const fieldInfos = {};
711
+ const adminLayerInfos = {};
712
+ // Add the service's layers and tables to it
713
+ const layersAndTables = getLayersAndTables(itemTemplate);
714
+ if (layersAndTables.length > 0) {
715
+ addFeatureServiceDefinition(itemTemplate.item.url || "", layersAndTables, templateDictionary, authentication, itemTemplate.key, adminLayerInfos, fieldInfos, itemTemplate).then(() => {
716
+ // Detemplatize field references and update the layer properties
717
+ // Only failure path is handled by addFeatureServiceDefinition
718
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
719
+ updateLayerFieldReferences(itemTemplate, fieldInfos, popupInfos, adminLayerInfos, templateDictionary).then((r) => {
720
+ // Update relationships and layer definitions
721
+ const updates = (0, restHelpers_1.getLayerUpdates)({
722
+ message: "updated layer definition",
723
+ objects: r.layerInfos.fieldInfos,
724
+ itemTemplate: r.itemTemplate,
725
+ authentication,
726
+ }, templateDictionary.isPortal);
727
+ // Process the updates sequentially
728
+ updates
729
+ .reduce((prev, update) => {
730
+ return prev.then(() => {
731
+ return (0, restHelpers_1.getRequest)(update, false, false, templateDictionary.isPortal);
732
+ });
733
+ }, Promise.resolve(null))
734
+ .then(() => resolve(null), (e) => reject((0, generalHelpers_1.fail)(e)));
735
+ });
736
+ }, (e) => reject((0, generalHelpers_1.fail)(e)));
737
+ }
738
+ else {
739
+ resolve(null);
740
+ }
741
+ }
742
+ });
743
+ }
744
+ exports.addFeatureServiceLayersAndTables = addFeatureServiceLayersAndTables;
745
+ /**
746
+ * Updates a feature service with a list of layers and/or tables.
747
+ *
748
+ * @param serviceUrl URL of feature service
749
+ * @param listToAdd List of layers and/or tables to add
750
+ * @param templateDictionary Hash mapping Solution source id to id of its clone (and name & URL for feature
751
+ * service)
752
+ * @param authentication Credentials for the request
753
+ * @param key
754
+ * @param adminLayerInfos Hash map of a layers adminLayerInfo
755
+ * @param fieldInfos Hash map of properties that contain field references
756
+ * @param itemTemplate
757
+ * @returns A promise that will resolve when the feature service has been updated
758
+ * @private
759
+ */
760
+ function addFeatureServiceDefinition(serviceUrl, listToAdd, templateDictionary, authentication, key, adminLayerInfos, fieldInfos, itemTemplate) {
761
+ return new Promise((resolve, reject) => {
762
+ if ((0, trackingHelpers_1.isTrackingViewTemplate)(itemTemplate)) {
763
+ resolve(null);
764
+ }
765
+ else {
766
+ let options = {
767
+ layers: [],
768
+ tables: [],
769
+ authentication,
770
+ };
771
+ // if the service has veiws keep track of the fields so we can use them to
772
+ // compare with the view fields
773
+ /* istanbul ignore else */
774
+ if ((0, generalHelpers_1.getProp)(itemTemplate, "properties.service.hasViews")) {
775
+ _updateTemplateDictionaryFields(itemTemplate, templateDictionary);
776
+ }
777
+ const isSelfReferential = _isSelfReferential(listToAdd);
778
+ listToAdd = _updateOrder(listToAdd, isSelfReferential, itemTemplate);
779
+ const chunkSize = _getLayerChunkSize();
780
+ const layerChunks = [];
781
+ listToAdd.forEach((toAdd, i) => {
782
+ let item = toAdd.item;
783
+ const originalId = item.id;
784
+ const isView = itemTemplate.properties.service.isView;
785
+ const isMsView = itemTemplate.properties.service.isMultiServicesView;
786
+ const isPortal = templateDictionary.isPortal;
787
+ fieldInfos = cacheFieldInfos(item, fieldInfos, isView, isPortal);
788
+ // cache the values to be added in seperate addToDef calls
789
+ fieldInfos = cacheContingentValues(item.id, fieldInfos, itemTemplate);
790
+ // cache specific field indexes when deploying to ArcGIS Enterprise portal
791
+ if (isPortal) {
792
+ fieldInfos = cacheIndexes(item, fieldInfos, isView, isMsView);
793
+ }
794
+ /* istanbul ignore else */
795
+ if (item.isView) {
796
+ deleteViewProps(item, isPortal);
797
+ }
798
+ // when the item is a view we need to grab the supporting fieldInfos
799
+ /* istanbul ignore else */
800
+ if (isView) {
801
+ _updateGeomFieldName(item.adminLayerInfo, templateDictionary);
802
+ adminLayerInfos[originalId] = item.adminLayerInfo;
803
+ // need to update adminLayerInfo before adding to the service def
804
+ // bring over the fieldInfos from the source layer
805
+ updateSettingsFieldInfos(itemTemplate, templateDictionary);
806
+ // update adminLayerInfo before add to definition with view source fieldInfo settings
807
+ item.adminLayerInfo = (0, templatization_1.replaceInTemplate)(item.adminLayerInfo, templateDictionary);
808
+ /* istanbul ignore else */
809
+ if (fieldInfos && fieldInfos.hasOwnProperty(item.id)) {
810
+ Object.keys(templateDictionary).some((k) => {
811
+ if (templateDictionary[k].itemId === itemTemplate.itemId) {
812
+ fieldInfos[item.id]["sourceServiceFields"] = templateDictionary[k].sourceServiceFields;
813
+ return true;
814
+ }
815
+ else {
816
+ return false;
817
+ }
818
+ });
819
+ _validateViewDomainFields(item, isPortal, isMsView);
820
+ }
821
+ }
822
+ /* istanbul ignore else */
823
+ if (isPortal) {
824
+ item = _updateForPortal(item, itemTemplate, templateDictionary);
825
+ }
826
+ removeLayerOptimization(item);
827
+ // this can still chunk layers
828
+ options = _updateAddOptions(itemTemplate, options, layerChunks, isSelfReferential, authentication);
829
+ if (item.type === "Feature Layer") {
830
+ options.layers.push(item);
831
+ }
832
+ else {
833
+ options.tables.push(item);
834
+ }
835
+ // In general we are switching to not use chunking. Rather if we exceed the defined chunk size
836
+ // we will use an async request.
837
+ // Currently the only case that should chunk the requests is when we have a multisource view
838
+ // handled in _updateAddOptions above
839
+ /* istanbul ignore else */
840
+ if (i + 1 === listToAdd.length) {
841
+ layerChunks.push(Object.assign({}, options));
842
+ options = {
843
+ layers: [],
844
+ tables: [],
845
+ authentication,
846
+ };
847
+ }
848
+ });
849
+ // will use async by default rather than chunk the layer requests when we have more layers
850
+ // than the defined chunk size
851
+ const useAsync = listToAdd.length > chunkSize;
852
+ layerChunks
853
+ .reduce((prev, curr) => prev.then(() => (0, restHelpers_1.addToServiceDefinition)(serviceUrl, curr, false, useAsync)), Promise.resolve(null))
854
+ .then(() => resolve(null), (e) => reject((0, generalHelpers_1.fail)(e)));
855
+ }
856
+ });
857
+ }
858
+ exports.addFeatureServiceDefinition = addFeatureServiceDefinition;
859
+ /**
860
+ * When a view is a multi service view sort based on the id
861
+ * https://github.com/Esri/solution.js/issues/1048
862
+ *
863
+ * @param layersAndTables The list of layers and tables for the current template
864
+ * @param isSelfReferential Indicates if any layers or tables have relationships with other layers or tables in the same service
865
+ * @param itemTemplate The current itemTemplate being processed
866
+ *
867
+ * @returns Sorted list of layers and tables when using a multi-service view
868
+ * @private
869
+ */
870
+ function _updateOrder(layersAndTables, isSelfReferential, itemTemplate) {
871
+ const isMsView = (0, generalHelpers_1.getProp)(itemTemplate, "properties.service.isMultiServicesView") || false;
872
+ return isSelfReferential || isMsView ? layersAndTables.sort((a, b) => a.item.id - b.item.id) : layersAndTables;
873
+ }
874
+ exports._updateOrder = _updateOrder;
875
+ /**
876
+ * When a view is a multi service view add each layer separately
877
+ * https://github.com/Esri/solution.js/issues/871
878
+ *
879
+ * @param itemTemplate The current itemTemplate being processed
880
+ * @param options Add to service definition options
881
+ * @param layerChunks Groups of layers or tables to add to the service
882
+ * @param isSelfReferential Indicates if any layers or tables have relationships with other layers or tables in the same service
883
+ * @param authentication Credentials for the request
884
+ *
885
+ * @returns Add to service definition options
886
+ * @private
887
+ */
888
+ function _updateAddOptions(itemTemplate, options, layerChunks, isSelfReferential, authentication) {
889
+ const isMsView = (0, generalHelpers_1.getProp)(itemTemplate, "properties.service.isMultiServicesView") || false;
890
+ /* istanbul ignore else */
891
+ if (isMsView || isSelfReferential) {
892
+ // if we already have some layers or tables add them first
893
+ /* istanbul ignore else */
894
+ if (options.layers.length > 0 || options.tables.length > 0) {
895
+ layerChunks.push(Object.assign({}, options));
896
+ options = {
897
+ layers: [],
898
+ tables: [],
899
+ authentication,
900
+ };
901
+ }
902
+ }
903
+ return options;
904
+ }
905
+ exports._updateAddOptions = _updateAddOptions;
906
+ /**
907
+ * Determine if any layer or table within the service references
908
+ * other layers or tables within the same service
909
+ *
910
+ * @param layersAndTables the list of layers and tables from the service
911
+ *
912
+ * @returns true when valid internal references are found
913
+ * @private
914
+ */
915
+ function _isSelfReferential(layersAndTables) {
916
+ const names = layersAndTables.map((l) => l.item.name);
917
+ const srcTables = {};
918
+ return layersAndTables.some((l) => {
919
+ const table = l.item.adminLayerInfo?.viewLayerDefinition?.table;
920
+ if (table) {
921
+ const name = table.sourceServiceName;
922
+ const id = table.sourceLayerId;
923
+ if (name && id > -1) {
924
+ if (Object.keys(srcTables).indexOf(name) > -1) {
925
+ if (srcTables[name].indexOf(id) > -1) {
926
+ return true;
927
+ }
928
+ else {
929
+ srcTables[name].push(id);
930
+ }
931
+ }
932
+ else {
933
+ srcTables[name] = [id];
934
+ }
935
+ }
936
+ return (table.relatedTables || []).some((r) => names.indexOf(r.name) > -1);
937
+ }
938
+ });
939
+ }
940
+ exports._isSelfReferential = _isSelfReferential;
941
+ /**
942
+ * Remove "multiScaleGeometryInfo" for issue #526 to prevent invalid enablement of layer optimization
943
+ *
944
+ * @param layer the layer to evaluate
945
+ * @private
946
+ */
947
+ function removeLayerOptimization(layer) {
948
+ /* istanbul ignore else */
949
+ if (layer.multiScaleGeometryInfo) {
950
+ (0, generalHelpers_1.deleteProp)(layer, "multiScaleGeometryInfo");
951
+ }
952
+ }
953
+ exports.removeLayerOptimization = removeLayerOptimization;
954
+ /**
955
+ * Handle portal specific updates to the item
956
+ *
957
+ * @param item the item to update
958
+ * @param itemTemplate the item template
959
+ * @param templateDictionary Hash mapping Solution source id to id of its clone
960
+ *
961
+ * @returns the updated item
962
+ * @private
963
+ */
964
+ function _updateForPortal(item, itemTemplate, templateDictionary) {
965
+ // When deploying to portal we need to adjust the uniquie ID field up front
966
+ /* istanbul ignore else */
967
+ if (item.uniqueIdField && item.uniqueIdField.name) {
968
+ item.uniqueIdField.name = String(item.uniqueIdField.name).toLocaleLowerCase();
969
+ }
970
+ // Portal will fail if the geometryField is null
971
+ if (item.type === "Table" && item.adminLayerInfo) {
972
+ (0, generalHelpers_1.deleteProp)(item.adminLayerInfo, "geometryField");
973
+ }
974
+ // Portal will fail if the sourceFields in the viewLayerDef contain fields that are not in the source service
975
+ /* istanbul ignore else */
976
+ if (item.isView) {
977
+ const viewLayerDefTable = (0, generalHelpers_1.getProp)(item, "adminLayerInfo.viewLayerDefinition.table");
978
+ let fieldNames = [];
979
+ if (viewLayerDefTable) {
980
+ const tableFieldNames = _getFieldNames(viewLayerDefTable, itemTemplate, templateDictionary);
981
+ fieldNames = fieldNames.concat(tableFieldNames);
982
+ const dynamicFieldNames = _getDynamicFieldNames(viewLayerDefTable);
983
+ fieldNames = fieldNames.concat(dynamicFieldNames);
984
+ (0, generalHelpers_1.setProp)(item, "adminLayerInfo.viewLayerDefinition.table", _updateSourceLayerFields(viewLayerDefTable, fieldNames));
985
+ // Handle related also
986
+ /* istanbul ignore else */
987
+ if (Array.isArray(viewLayerDefTable.relatedTables)) {
988
+ viewLayerDefTable.relatedTables.map((relatedTable) => {
989
+ const relatedTableFieldNames = _getFieldNames(relatedTable, itemTemplate, templateDictionary);
990
+ fieldNames = fieldNames.concat(relatedTableFieldNames);
991
+ const dynamicRelatedFieldNames = _getDynamicFieldNames(relatedTable);
992
+ fieldNames = fieldNames.concat(dynamicRelatedFieldNames);
993
+ return _updateSourceLayerFields(relatedTable, [...relatedTableFieldNames, ...dynamicRelatedFieldNames]);
994
+ });
995
+ }
996
+ }
997
+ else {
998
+ Object.keys(templateDictionary).some((k) => {
999
+ /* istanbul ignore else */
1000
+ if (templateDictionary[k].itemId === item.serviceItemId) {
1001
+ const layerInfo = templateDictionary[k][`layer${item.id}`];
1002
+ /* istanbul ignore else */
1003
+ if (layerInfo && layerInfo.fields) {
1004
+ if (Array.isArray(layerInfo.fields)) {
1005
+ fieldNames = layerInfo.fields.map((f) => f.name);
1006
+ }
1007
+ else {
1008
+ fieldNames = Object.keys(layerInfo.fields);
1009
+ }
1010
+ }
1011
+ return true;
1012
+ }
1013
+ });
1014
+ }
1015
+ item = _updateItemFields(item, fieldNames);
1016
+ }
1017
+ // not allowed to set sourceSchemaChangesAllowed or isView for portal
1018
+ // these are set when you create the service
1019
+ (0, generalHelpers_1.deleteProp)(item, "isView");
1020
+ return item;
1021
+ }
1022
+ exports._updateForPortal = _updateForPortal;
1023
+ /**
1024
+ * Get a list of the source layer field names
1025
+ *
1026
+ * @param table the table instance to compare
1027
+ * @param itemTemplate the item template
1028
+ * @param templateDictionary Hash mapping Solution source id to id of its clone
1029
+ *
1030
+ * @returns an array of the source layers fields
1031
+ * @private
1032
+ */
1033
+ function _getFieldNames(table, itemTemplate, templateDictionary) {
1034
+ let sourceLayerFields = [];
1035
+ const viewSourceLayerId = table.sourceLayerId;
1036
+ /* istanbul ignore else */
1037
+ if (typeof viewSourceLayerId === "number") {
1038
+ // need to make sure these actually exist in the source..
1039
+ itemTemplate.dependencies.forEach((d) => {
1040
+ const layerInfo = templateDictionary[d][`layer${viewSourceLayerId}`];
1041
+ /* istanbul ignore else */
1042
+ if (layerInfo && layerInfo.fields && templateDictionary[d].name === table.sourceServiceName) {
1043
+ if (Array.isArray(layerInfo.fields)) {
1044
+ sourceLayerFields = sourceLayerFields.concat(layerInfo.fields.map((f) => f.name));
1045
+ }
1046
+ else {
1047
+ sourceLayerFields = sourceLayerFields.concat(Object.keys(layerInfo.fields));
1048
+ }
1049
+ }
1050
+ });
1051
+ return sourceLayerFields;
1052
+ }
1053
+ }
1054
+ exports._getFieldNames = _getFieldNames;
1055
+ /**
1056
+ * Get a list of any dynamically calculated fields
1057
+ * These fields are still valid but will not exist in the source service
1058
+ *
1059
+ * @param table the table instance to compare
1060
+ *
1061
+ * @returns an array of field names
1062
+ * @private
1063
+ */
1064
+ function _getDynamicFieldNames(table) {
1065
+ const fieldNames = table.sourceLayerFields.reduce((prev, cur) => {
1066
+ if (cur.statisticType) {
1067
+ prev.push(cur.name);
1068
+ }
1069
+ return prev;
1070
+ }, []);
1071
+ return [...new Set(fieldNames)];
1072
+ }
1073
+ exports._getDynamicFieldNames = _getDynamicFieldNames;
1074
+ /**
1075
+ * Remove fields references from fields and indexes that do not exist in the source service
1076
+ *
1077
+ * @param item Layer or table
1078
+ * @param templateDictionary Hash mapping Solution source id to id of its clone
1079
+ *
1080
+ * @returns updated layer or table
1081
+ * @private
1082
+ */
1083
+ function _updateItemFields(item, fieldNames) {
1084
+ /* istanbul ignore else */
1085
+ if (fieldNames.length > 0) {
1086
+ /* istanbul ignore else */
1087
+ if (item.fields) {
1088
+ item.fields = item.fields.filter((f) => fieldNames.indexOf(f.name) > -1);
1089
+ }
1090
+ /* istanbul ignore else */
1091
+ if (item.indexes) {
1092
+ item.indexes = item.indexes.filter((f) => fieldNames.indexOf(f.fields) > -1);
1093
+ }
1094
+ }
1095
+ return item;
1096
+ }
1097
+ exports._updateItemFields = _updateItemFields;
1098
+ /**
1099
+ * Filter the sourceLayerFields for the table
1100
+ *
1101
+ * @param table the table instance to evaluate
1102
+ * @param sourceLayerFields array of fields from the source service
1103
+ * @returns Updated instance of the table
1104
+ * @private
1105
+ */
1106
+ function _updateSourceLayerFields(table, sourceLayerFields) {
1107
+ /* istanbul ignore else */
1108
+ if (Array.isArray(table.sourceLayerFields) && table.sourceLayerFields.length > 0) {
1109
+ // need to make sure these actually exist in the source..
1110
+ /* istanbul ignore else */
1111
+ if (sourceLayerFields.length > 0) {
1112
+ (0, generalHelpers_1.setProp)(table, "sourceLayerFields", table.sourceLayerFields.filter((f) => sourceLayerFields.indexOf(f.source.toLowerCase()) > -1));
1113
+ }
1114
+ }
1115
+ return table;
1116
+ }
1117
+ exports._updateSourceLayerFields = _updateSourceLayerFields;
1118
+ /**
1119
+ * When the itemm is a view with a geometry field update the value to
1120
+ * use the table name from the view layer def
1121
+ *
1122
+ * @param item the item details from the current template
1123
+ * @param templateDictionary Hash mapping property names to replacement values
1124
+ * @private
1125
+ */
1126
+ function _updateGeomFieldName(adminLayerInfo, templateDictionary) {
1127
+ // issue #471
1128
+ const tableName = (0, generalHelpers_1.getProp)(adminLayerInfo, "viewLayerDefinition.table.name");
1129
+ const fieldName = (0, generalHelpers_1.getProp)(adminLayerInfo, "geometryField.name");
1130
+ /* istanbul ignore else */
1131
+ if (fieldName && tableName) {
1132
+ const geomName = templateDictionary.isPortal ? `${tableName}.shape` : `${tableName}.Shape`;
1133
+ (0, generalHelpers_1.setProp)(adminLayerInfo, "geometryField.name", geomName);
1134
+ }
1135
+ else if (!fieldName && (0, generalHelpers_1.getProp)(adminLayerInfo, "geometryField")) {
1136
+ // null geom field will cause failure to deploy in portal
1137
+ // this is also checked and removed on deploy for older solutions
1138
+ (0, generalHelpers_1.deleteProp)(adminLayerInfo, "geometryField");
1139
+ }
1140
+ }
1141
+ exports._updateGeomFieldName = _updateGeomFieldName;
1142
+ /**
1143
+ * Add the fields to the templateDictionary when a service has views
1144
+ * these are used to compare with fields from the view when domains are involved
1145
+ * when a view field has a domain that differs from that of the source service
1146
+ * the definition needs to be modified in an update call rather than when it is first added.
1147
+ * This should only happen when the domain differs.
1148
+ *
1149
+ * @param itemTemplate
1150
+ * @param templateDictionary Hash mapping Solution source id to id of its clone (and name & URL for feature service)
1151
+ * @private
1152
+ */
1153
+ function _updateTemplateDictionaryFields(itemTemplate, templateDictionary, compareItemId = true) {
1154
+ const layers = itemTemplate.properties.layers;
1155
+ const tables = itemTemplate.properties.tables;
1156
+ const layersAndTables = layers.concat(tables);
1157
+ const fieldInfos = {};
1158
+ layersAndTables.forEach((layerOrTable) => {
1159
+ fieldInfos[layerOrTable.id] = layerOrTable.fields;
1160
+ });
1161
+ Object.keys(templateDictionary).some((k) => {
1162
+ if (compareItemId ? templateDictionary[k].itemId === itemTemplate.itemId : k === itemTemplate.itemId) {
1163
+ templateDictionary[k].fieldInfos = fieldInfos;
1164
+ return true;
1165
+ }
1166
+ else {
1167
+ return false;
1168
+ }
1169
+ });
1170
+ }
1171
+ exports._updateTemplateDictionaryFields = _updateTemplateDictionaryFields;
1172
+ /**
1173
+ * Set the defaultSpatialReference variable with the services spatial reference.
1174
+ * If this item is a Feature Service that has child views then we will use this value
1175
+ * if one or more of the child views spatial reference differs from that of its parent.
1176
+ *
1177
+ * @param templateDictionary Hash mapping Solution source id to id of its clone (and name & URL for feature service)
1178
+ * @param itemId The source id for the item
1179
+ * @param spatialReference \{ wkid: 102100 \} for example
1180
+ * @private
1181
+ */
1182
+ function setDefaultSpatialReference(templateDictionary, itemId, spatialReference) {
1183
+ /* istanbul ignore else */
1184
+ if (spatialReference) {
1185
+ (0, generalHelpers_1.setCreateProp)(templateDictionary, `${itemId}.defaultSpatialReference`, spatialReference);
1186
+ }
1187
+ }
1188
+ exports.setDefaultSpatialReference = setDefaultSpatialReference;
1189
+ /**
1190
+ * Compare the spatial reference of the current item against its dependencies.
1191
+ * The spatial reference of a view cannot differ from its source service.
1192
+ * If the view has a different spatial reference from its source use the source spatial reference.
1193
+ *
1194
+ * @param serviceInfo Basic service information
1195
+ * @param itemTemplate The current template to process
1196
+ * @param templateDictionary Hash mapping Solution source id to id of its clone (and name & URL for feature service)
1197
+ * @private
1198
+ */
1199
+ function validateSpatialReferenceAndExtent(serviceInfo, itemTemplate, templateDictionary) {
1200
+ /* istanbul ignore else */
1201
+ if ((0, generalHelpers_1.getProp)(serviceInfo, "service.isView")) {
1202
+ // first pass ensure we have a geometry type before getting the spatial reference or extent
1203
+ // issue: #1368
1204
+ const geomCheckResults = _getSourceSpatialReferenceAndExtent(serviceInfo, itemTemplate, templateDictionary, true);
1205
+ // if not found with first pass just check for the first service that has the key values defined
1206
+ // as we did before the above handeling
1207
+ const results = _getSourceSpatialReferenceAndExtent(serviceInfo, itemTemplate, templateDictionary, false);
1208
+ const sourceSR = geomCheckResults.spatialReference || results.spatialReference;
1209
+ const sourceExt = geomCheckResults.extent || results.extent;
1210
+ const sourceWkid = (0, generalHelpers_1.getProp)(sourceSR, "wkid");
1211
+ const viewWkid = (0, generalHelpers_1.getProp)(serviceInfo, "service.spatialReference.wkid");
1212
+ /* istanbul ignore else */
1213
+ if (sourceWkid && viewWkid && sourceWkid !== viewWkid) {
1214
+ (0, generalHelpers_1.setCreateProp)(serviceInfo, "service.spatialReference", sourceSR);
1215
+ }
1216
+ const viewExt = (0, generalHelpers_1.getProp)(serviceInfo, "service.fullExtent");
1217
+ /* istanbul ignore else */
1218
+ if (sourceExt && viewExt && JSON.stringify(sourceExt) !== JSON.stringify(viewExt)) {
1219
+ (0, generalHelpers_1.setCreateProp)(serviceInfo, "defaultExtent", sourceExt);
1220
+ }
1221
+ }
1222
+ }
1223
+ exports.validateSpatialReferenceAndExtent = validateSpatialReferenceAndExtent;
1224
+ /**
1225
+ * Get the spatial reference from a views source.
1226
+ * Optionally ensure that the source has a valid geometry type prior to using its values.
1227
+ *
1228
+ * @param serviceInfo Basic service information
1229
+ * @param itemTemplate The current template to process
1230
+ * @param templateDictionary Hash mapping Solution source id to id of its clone (and name & URL for feature service)
1231
+ * @param validateGeom When true the source must contain a geometryType for values to be returned
1232
+ *
1233
+ * @returns An object that contains the default spatial reference and extent value
1234
+ * @private
1235
+ */
1236
+ function _getSourceSpatialReferenceAndExtent(serviceInfo, itemTemplate, templateDictionary, validateGeom) {
1237
+ const layersAndTables = [...(serviceInfo.layers || []), ...(serviceInfo.tables || [])];
1238
+ let spatialReference;
1239
+ let extent;
1240
+ itemTemplate.dependencies.some((id) => {
1241
+ const source = templateDictionary[id];
1242
+ const hasGeom = validateGeom
1243
+ ? layersAndTables.some((layerOrTable) => {
1244
+ const name = (0, generalHelpers_1.getProp)(layerOrTable, "adminLayerInfo.viewLayerDefinition.table.sourceServiceName");
1245
+ return name && source.name && name === source.name && layerOrTable.geometryType;
1246
+ })
1247
+ : true;
1248
+ const sr = (0, generalHelpers_1.getProp)(source, "defaultSpatialReference");
1249
+ /* istanbul ignore else */
1250
+ if (!spatialReference && sr && hasGeom) {
1251
+ spatialReference = sr;
1252
+ }
1253
+ const ext = (0, generalHelpers_1.getProp)(source, "defaultExtent");
1254
+ /* istanbul ignore else */
1255
+ if (!extent && ext && hasGeom) {
1256
+ extent = ext;
1257
+ }
1258
+ return spatialReference && extent;
1259
+ });
1260
+ return {
1261
+ spatialReference,
1262
+ extent,
1263
+ };
1264
+ }
1265
+ exports._getSourceSpatialReferenceAndExtent = _getSourceSpatialReferenceAndExtent;
1266
+ /**
1267
+ * Updates a feature service with a list of layers and/or tables.
1268
+ *
1269
+ * @param itemTemplate
1270
+ * @param fieldInfos Hash map of properties that contain field references
1271
+ * @param popupInfos Hash map of a layers popupInfo
1272
+ * @param adminLayerInfos Hash map of a layers adminLayerInfo
1273
+ * @param templateDictionary Hash mapping Solution source id to id of its clone (and name & URL for feature service)
1274
+ * @param authentication Credentials for the request
1275
+ * @returns A promise that will resolve when the feature service has been updated
1276
+ * @private
1277
+ */
1278
+ function updateLayerFieldReferences(itemTemplate, fieldInfos, popupInfos, adminLayerInfos, templateDictionary) {
1279
+ return new Promise((resolveFn, rejectFn) => {
1280
+ // Will need to do some post processing for fields
1281
+ // to handle any potential field name changes when deploying to portal
1282
+ postProcessFields(itemTemplate, fieldInfos, popupInfos, adminLayerInfos, templateDictionary).then((layerInfos) => {
1283
+ // Update the items text with detemplatized popupInfo
1284
+ updatePopupInfo(itemTemplate, layerInfos.popupInfos);
1285
+ resolveFn({
1286
+ itemTemplate,
1287
+ layerInfos,
1288
+ });
1289
+ }, (e) => rejectFn((0, generalHelpers_1.fail)(e)));
1290
+ });
1291
+ }
1292
+ exports.updateLayerFieldReferences = updateLayerFieldReferences;
1293
+ /**
1294
+ * Update the names of fields for each layer or table after it has been
1295
+ * added to the definition
1296
+ *
1297
+ * @param itemTemplate Item to be created
1298
+ * @param layerInfos Hash map of properties that contain field references and various layer info
1299
+ * @param popupInfos Hash map of a layers popupInfo
1300
+ * @param adminLayerInfos Hash map of a layers adminLayerInfo
1301
+ * @param templateDictionary
1302
+ * @param authentication Credentials for the request
1303
+ * @returns An object with detemplatized field references
1304
+ * @private
1305
+ */
1306
+ function postProcessFields(itemTemplate, layerInfos, popupInfos, adminLayerInfos, templateDictionary) {
1307
+ return new Promise((resolveFn, rejectFn) => {
1308
+ if (!itemTemplate.item.url) {
1309
+ rejectFn((0, generalHelpers_1.fail)("Feature layer " + itemTemplate.itemId + " does not have a URL"));
1310
+ }
1311
+ else {
1312
+ const id = itemTemplate.itemId;
1313
+ const settingsKeys = Object.keys(templateDictionary);
1314
+ let templateInfo;
1315
+ settingsKeys.some((k) => {
1316
+ if (templateDictionary[k].itemId === id) {
1317
+ templateInfo = templateDictionary[k];
1318
+ return true;
1319
+ }
1320
+ else {
1321
+ return false;
1322
+ }
1323
+ });
1324
+ // concat any layers and tables to process
1325
+ const layers = itemTemplate.properties.layers;
1326
+ const tables = itemTemplate.properties.tables;
1327
+ const layersAndTables = layers.concat(tables);
1328
+ // Set the newFields property for the layerInfos...this will contain all fields
1329
+ // as they are after being added to the definition.
1330
+ // This allows us to handle any potential field name changes after deploy to portal
1331
+ layersAndTables.forEach((item) => {
1332
+ // when deploying to portal "isView" is only set for create service and will fail when
1333
+ // present on addToDef so this property is removed from item and we should check the templates service info
1334
+ const isView = item.isView || itemTemplate.properties.service.isView;
1335
+ /* istanbul ignore else */
1336
+ if (layerInfos && layerInfos.hasOwnProperty(item.id)) {
1337
+ const layerInfo = layerInfos[item.id];
1338
+ layerInfo["isView"] = item.isView;
1339
+ layerInfo["newFields"] = item.fields;
1340
+ layerInfo["sourceSchemaChangesAllowed"] = item.sourceSchemaChangesAllowed;
1341
+ /* istanbul ignore else */
1342
+ if (item.editFieldsInfo) {
1343
+ // more than case change when deployed to protal so keep track of the new names
1344
+ layerInfo["newEditFieldsInfo"] = JSON.parse(JSON.stringify(item.editFieldsInfo));
1345
+ }
1346
+ /* istanbul ignore else */
1347
+ if (isView && templateInfo && templateDictionary.isPortal) {
1348
+ // when the item is a view bring over the source service fields so we can compare the domains
1349
+ layerInfo["sourceServiceFields"] = templateInfo.sourceServiceFields;
1350
+ }
1351
+ }
1352
+ });
1353
+ // Add the layerInfos to the settings object to be used while detemplatizing
1354
+ settingsKeys.forEach((k) => {
1355
+ if (id === templateDictionary[k].itemId) {
1356
+ templateDictionary[k] = Object.assign(templateDictionary[k], getLayerSettings(layerInfos, templateDictionary[k].url, id));
1357
+ }
1358
+ });
1359
+ // update the layerInfos object with current field names
1360
+ resolveFn(deTemplatizeFieldInfos(layerInfos, popupInfos, adminLayerInfos, templateDictionary));
1361
+ }
1362
+ });
1363
+ }
1364
+ exports.postProcessFields = postProcessFields;
1365
+ /**
1366
+ * Set isViewOverride to false for single source view fields in portal when the field has
1367
+ * a domain and isViewOverride is not currently defined
1368
+ *
1369
+ * https://devtopia.esri.com/WebGIS/solution-deployment-apps/issues/414
1370
+ *
1371
+ * @param item that stores the view fields
1372
+ * @param isPortal When true we are deploying to portal
1373
+ * @param isMsView When true the view is a multi-source view
1374
+ *
1375
+ * This function will update the item that is provided
1376
+ * @private
1377
+ */
1378
+ function _validateViewDomainFields(item, isPortal, isMsView) {
1379
+ /* istanbul ignore else */
1380
+ if (isPortal && !isMsView) {
1381
+ const k = "domain";
1382
+ const k2 = "isViewOverride";
1383
+ item.fields.map((field) => {
1384
+ /* istanbul ignore else */
1385
+ if (field.hasOwnProperty(k) && (0, generalHelpers_1.getProp)(field, k) && !field.hasOwnProperty(k2)) {
1386
+ field.isViewOverride = false;
1387
+ }
1388
+ return field;
1389
+ });
1390
+ }
1391
+ }
1392
+ exports._validateViewDomainFields = _validateViewDomainFields;
1393
+ /**
1394
+ * Add popup info back to the layer item
1395
+ *
1396
+ * @param itemTemplate
1397
+ * @param popupInfos popup info to be added back to the layer
1398
+ * @private
1399
+ */
1400
+ function updatePopupInfo(itemTemplate, popupInfos) {
1401
+ ["layers", "tables"].forEach((type) => {
1402
+ const _items = (0, generalHelpers_1.getProp)(itemTemplate, "data." + type);
1403
+ /* istanbul ignore else */
1404
+ if (_items && Array.isArray(_items)) {
1405
+ _items.forEach((item) => {
1406
+ item.popupInfo = (0, generalHelpers_1.getProp)(popupInfos, type + "." + item.id) || {};
1407
+ });
1408
+ }
1409
+ });
1410
+ }
1411
+ exports.updatePopupInfo = updatePopupInfo;
1412
+ //#endregion
1413
+ //#region Private helper functions --------------------------------------------------//
1414
+ /**
1415
+ * Helper function to templatize value and make sure its converted to lowercase
1416
+ *
1417
+ * @param basePath path used to de-templatize while deploying
1418
+ * @param value to be converted to lower case for lookup while deploying
1419
+ * @private
1420
+ */
1421
+ function _templatize(basePath, value, suffix) {
1422
+ if (value.startsWith("{{")) {
1423
+ return value;
1424
+ }
1425
+ else {
1426
+ return String((0, templatization_1.templatizeTerm)(basePath, basePath, "." + String(value).toLowerCase() + (suffix ? "." + suffix : "")));
1427
+ }
1428
+ }
1429
+ exports._templatize = _templatize;
1430
+ /**
1431
+ * templatize an objects property
1432
+ *
1433
+ * @param object the object with the property to templatize
1434
+ * @param property the property of the object to templatize
1435
+ * @param basePath path used to de-templatize while deploying
1436
+ * @private
1437
+ */
1438
+ function _templatizeProperty(object, property, basePath, suffix) {
1439
+ if (object && object.hasOwnProperty(property) && object[property]) {
1440
+ object[property] = _templatize(basePath, object[property], suffix);
1441
+ }
1442
+ }
1443
+ exports._templatizeProperty = _templatizeProperty;
1444
+ /**
1445
+ * Templatize field references, serviceItemId, and adminLayerInfo for a layer
1446
+ *
1447
+ * @param dataItem from the items data property
1448
+ * @param adminItem from the services admin api
1449
+ * @param itemTemplate Template for feature service item
1450
+ * @param dependencies Array of IDependency for name mapping
1451
+ * @param templatizeFieldReferences Templatize all field references within a layer
1452
+ * @returns A promise that will resolve when template has been updated
1453
+ * @private
1454
+ */
1455
+ function _templatizeLayer(dataItem, adminItem, itemTemplate, dependencies, templatizeFieldReferences, templateDictionary) {
1456
+ // check for and repair common field issues
1457
+ _validateFields(adminItem);
1458
+ // Templatize all properties that contain field references
1459
+ /* istanbul ignore else */
1460
+ if (templatizeFieldReferences) {
1461
+ _templatizeLayerFieldReferences(dataItem, itemTemplate.itemId, adminItem, dependencies);
1462
+ }
1463
+ const updates = [adminItem];
1464
+ if (dataItem) {
1465
+ updates.push(dataItem);
1466
+ }
1467
+ updates.forEach((update) => {
1468
+ if (update.hasOwnProperty("name")) {
1469
+ // templatize the name but leave the current name as the optional default
1470
+ update.name = (0, templatization_1.templatizeTerm)(update["serviceItemId"] + ".layer" + update.id, update["serviceItemId"] + ".layer" + update.id, ".name||" + update.name);
1471
+ }
1472
+ if (update.hasOwnProperty("extent")) {
1473
+ update.extent = (0, templatization_1.templatizeTerm)(update["serviceItemId"], update["serviceItemId"], ".solutionExtent");
1474
+ }
1475
+ if (update.hasOwnProperty("serviceItemId")) {
1476
+ update["serviceItemId"] = (0, templatization_1.templatizeTerm)(update["serviceItemId"], update["serviceItemId"], ".itemId");
1477
+ }
1478
+ if (update.hasOwnProperty("adminLayerInfo")) {
1479
+ update.adminLayerInfo = _templatizeAdminLayerInfo(update, dependencies, templateDictionary);
1480
+ }
1481
+ });
1482
+ }
1483
+ exports._templatizeLayer = _templatizeLayer;
1484
+ /**
1485
+ * Repair common issues that can occur with feature service field references.
1486
+ * This function will mutate the input item if any of the common issues have occured.
1487
+ *
1488
+ * @param adminItem layer or table from the service
1489
+ */
1490
+ function _validateFields(adminItem) {
1491
+ const fieldNames = (adminItem.fields || []).map((f) => f.name);
1492
+ // Update primary display field if field isn't in the layer.
1493
+ _validateDisplayField(adminItem, fieldNames);
1494
+ // Remove indexes on fields that don't exist in the layer.
1495
+ // Remove duplicate indexes on the same field.
1496
+ _validateIndexes(adminItem, fieldNames);
1497
+ // Remove field references in templates when field doesn't exist in the layer.
1498
+ _validateTemplatesFields(adminItem, fieldNames);
1499
+ _validateTypesTemplates(adminItem, fieldNames);
1500
+ // Repair editFieldsInfo if field referenced doesn't exist in the layer
1501
+ _validateEditFieldsInfo(adminItem, fieldNames);
1502
+ }
1503
+ exports._validateFields = _validateFields;
1504
+ /**
1505
+ * Update primary display field if casing doesn't match.
1506
+ * Update primary display field to the first non OID or GlobalId if the field isn't in the layer.
1507
+ *
1508
+ * @param adminItem layer or table from the service
1509
+ * @param fieldNames string list of fields names
1510
+ * @private
1511
+ */
1512
+ function _validateDisplayField(adminItem, fieldNames) {
1513
+ const displayField = adminItem.displayField || "";
1514
+ let i = -1;
1515
+ if (fieldNames.some((name) => {
1516
+ i += 1;
1517
+ return name === displayField || name === displayField.toLowerCase();
1518
+ })) {
1519
+ adminItem.displayField = fieldNames[i];
1520
+ }
1521
+ else {
1522
+ // use the first non-OID non-globalId field we find
1523
+ const skipFields = [];
1524
+ const oidField = (0, generalHelpers_1.getProp)(adminItem, "uniqueIdField.name");
1525
+ /* istanbul ignore else */
1526
+ if (oidField) {
1527
+ skipFields.push(oidField);
1528
+ }
1529
+ const globalIdField = (0, generalHelpers_1.getProp)(adminItem, "globalIdField");
1530
+ /* istanbul ignore else */
1531
+ if (globalIdField) {
1532
+ skipFields.push(globalIdField);
1533
+ }
1534
+ fieldNames.some((name) => {
1535
+ if (skipFields.indexOf(name) === -1) {
1536
+ adminItem.displayField = name;
1537
+ return true;
1538
+ }
1539
+ else {
1540
+ return false;
1541
+ }
1542
+ });
1543
+ }
1544
+ }
1545
+ exports._validateDisplayField = _validateDisplayField;
1546
+ /**
1547
+ * Remove indexes on fields that don't exist in the layer.
1548
+ * Remove duplicate indexes on the same field.
1549
+ *
1550
+ * @param adminItem layer or table from the service
1551
+ * @param fieldNames string list of fields names
1552
+ * @private
1553
+ */
1554
+ function _validateIndexes(adminItem, fieldNames) {
1555
+ const indexes = adminItem.indexes;
1556
+ /* istanbul ignore else */
1557
+ if (indexes) {
1558
+ const indexedFields = [];
1559
+ adminItem.indexes = indexes.reduce((filtered, index) => {
1560
+ const indexFields = index.fields.split(",");
1561
+ const verifiedFields = [];
1562
+ indexFields.forEach((indexField) => {
1563
+ /* istanbul ignore else */
1564
+ if (indexedFields.indexOf(indexField) === -1) {
1565
+ indexedFields.push(indexField);
1566
+ // this is the first index with this field and it should be added if the field exists
1567
+ /* istanbul ignore else */
1568
+ if (fieldNames.indexOf(indexField) > -1) {
1569
+ verifiedFields.push(indexField);
1570
+ }
1571
+ }
1572
+ // else the field has more than one index associated and should not be returned
1573
+ });
1574
+ /* istanbul ignore else */
1575
+ if (verifiedFields.length > 0) {
1576
+ index.fields = verifiedFields.join(",");
1577
+ filtered.push(index);
1578
+ }
1579
+ return filtered;
1580
+ }, []);
1581
+ }
1582
+ }
1583
+ exports._validateIndexes = _validateIndexes;
1584
+ /**
1585
+ * Remove field references from templates that no longer exist.
1586
+ *
1587
+ * @param adminItem layer or table from the service
1588
+ * @param fieldNames string list of fields names
1589
+ * @private
1590
+ */
1591
+ function _validateTemplatesFields(adminItem, fieldNames) {
1592
+ const templates = adminItem.templates;
1593
+ /* istanbul ignore else */
1594
+ if (templates) {
1595
+ adminItem.templates = templates.map((template) => {
1596
+ const attributes = (0, generalHelpers_1.getProp)(template, "prototype.attributes");
1597
+ /* istanbul ignore else */
1598
+ if (attributes) {
1599
+ Object.keys(attributes).forEach((k) => {
1600
+ /* istanbul ignore else */
1601
+ if (fieldNames.indexOf(k) === -1) {
1602
+ delete attributes[k];
1603
+ }
1604
+ });
1605
+ (0, generalHelpers_1.setProp)(template, "prototype.attributes", attributes);
1606
+ }
1607
+ return template;
1608
+ });
1609
+ }
1610
+ }
1611
+ exports._validateTemplatesFields = _validateTemplatesFields;
1612
+ /**
1613
+ * Remove field references from templates that no longer exist.
1614
+ *
1615
+ * @param adminItem layer or table from the service
1616
+ * @param fieldNames string list of fields names
1617
+ * @private
1618
+ */
1619
+ function _validateTypesTemplates(adminItem, fieldNames) {
1620
+ const types = adminItem.types;
1621
+ /* istanbul ignore else */
1622
+ if (types) {
1623
+ adminItem.types = types.map((t) => {
1624
+ _validateTemplatesFields(t, fieldNames);
1625
+ return t;
1626
+ });
1627
+ }
1628
+ }
1629
+ exports._validateTypesTemplates = _validateTypesTemplates;
1630
+ /**
1631
+ * Check if edit feilds exist but with lower case
1632
+ *
1633
+ * @param adminItem layer or table from the service
1634
+ * @param fieldNames string list of fields names
1635
+ * @private
1636
+ */
1637
+ function _validateEditFieldsInfo(adminItem, fieldNames) {
1638
+ const editFieldsInfo = adminItem.editFieldsInfo;
1639
+ /* istanbul ignore else */
1640
+ if (editFieldsInfo) {
1641
+ const editFieldsInfoKeys = Object.keys(editFieldsInfo);
1642
+ editFieldsInfoKeys.forEach((k) => {
1643
+ const editFieldName = editFieldsInfo[k];
1644
+ /* istanbul ignore else */
1645
+ if (editFieldName) {
1646
+ fieldNames.some((name) => {
1647
+ if (name === editFieldName) {
1648
+ return true;
1649
+ }
1650
+ else if (name === editFieldName.toLowerCase()) {
1651
+ editFieldsInfo[k] = name;
1652
+ return true;
1653
+ }
1654
+ else {
1655
+ return false;
1656
+ }
1657
+ });
1658
+ }
1659
+ });
1660
+ }
1661
+ }
1662
+ exports._validateEditFieldsInfo = _validateEditFieldsInfo;
1663
+ /**
1664
+ *
1665
+ * Templatize all field references within a layer
1666
+ * This is necessary to support potential field name changes when deploying to portal
1667
+ * Portal will force all field names to be lower case
1668
+ *
1669
+ * @param dataItem The data layer instance with field name references within
1670
+ * @param itemID The id for the item that contains this layer.
1671
+ * @param layer JSON return from the layer being templatized.
1672
+ * @param dependencies
1673
+ * @returns An updated instance of the layer
1674
+ * @private
1675
+ */
1676
+ function _templatizeLayerFieldReferences(dataItem, itemID, layer, dependencies) {
1677
+ // This is the value that will be used as the template for adlib replacement
1678
+ const path = itemID + ".layer" + layer.id + ".fields";
1679
+ // Get the field names for various tests
1680
+ const fieldNames = layer.fields.map((f) => f.name);
1681
+ // Update the layer from the items data property
1682
+ if (dataItem) {
1683
+ _templatizeAdminLayerInfoFields(dataItem, dependencies);
1684
+ _templatizePopupInfo(dataItem, layer, path, itemID, fieldNames);
1685
+ }
1686
+ // Update the layer
1687
+ _templatizeAdminLayerInfoFields(layer, dependencies);
1688
+ _templatizeRelationshipFields(layer, itemID);
1689
+ _templatizeDefinitionEditor(layer, path, fieldNames);
1690
+ _templatizeDefinitionExpression(layer, path, fieldNames);
1691
+ _templatizeDrawingInfo(layer, path, fieldNames);
1692
+ _templatizeTemplates(layer, path);
1693
+ _templatizeTypeTemplates(layer, path);
1694
+ _templatizeTimeInfo(layer, path);
1695
+ _templatizeDefinitionQuery(layer, path, fieldNames);
1696
+ }
1697
+ exports._templatizeLayerFieldReferences = _templatizeLayerFieldReferences;
1698
+ /**
1699
+ * Templatize a layers adminLayerInfo by removing properties that will case issues with clone.
1700
+ * Also templatizes the source service name when we are dealing with a view.
1701
+ *
1702
+ * @param layer The layer to be modified
1703
+ * @param dependencies Array of service dependencies
1704
+ * @returns A new copy of the modified adminLayerInfo for the given layer
1705
+ * @private
1706
+ */
1707
+ function _templatizeAdminLayerInfo(layer, dependencies, templateDictionary) {
1708
+ // Create new instance of adminLayerInfo to update for clone
1709
+ const adminLayerInfo = Object.assign({}, layer.adminLayerInfo);
1710
+ _updateGeomFieldName(adminLayerInfo, templateDictionary);
1711
+ (0, generalHelpers_1.deleteProp)(adminLayerInfo, "xssTrustedFields");
1712
+ (0, generalHelpers_1.deleteProp)(adminLayerInfo, "tableName");
1713
+ // Remove unnecessary properties and templatize key properties from viewLayerDefinition
1714
+ /* istanbul ignore else */
1715
+ if (adminLayerInfo.viewLayerDefinition) {
1716
+ const viewDef = Object.assign({}, adminLayerInfo.viewLayerDefinition);
1717
+ _processAdminObject(viewDef, dependencies);
1718
+ // Remove unnecessary properties and templatize key properties from viewLayerDefinition.table
1719
+ /* istanbul ignore else */
1720
+ if (viewDef.table) {
1721
+ _processAdminObject(viewDef.table, dependencies);
1722
+ /* istanbul ignore else */
1723
+ if (viewDef.table.relatedTables) {
1724
+ viewDef.table.relatedTables.forEach((table) => {
1725
+ _processAdminObject(table, dependencies);
1726
+ });
1727
+ }
1728
+ }
1729
+ adminLayerInfo.viewLayerDefinition = viewDef;
1730
+ }
1731
+ return adminLayerInfo;
1732
+ }
1733
+ exports._templatizeAdminLayerInfo = _templatizeAdminLayerInfo;
1734
+ /**
1735
+ * Remove sourceId and templatize the sourceServiceName
1736
+ *
1737
+ * @param object The layer to be modified
1738
+ * @param dependencies Array of service dependencies
1739
+ * @private
1740
+ */
1741
+ function _processAdminObject(object, dependencies) {
1742
+ (0, generalHelpers_1.deleteProp)(object, "sourceId");
1743
+ if (object.hasOwnProperty("sourceServiceName")) {
1744
+ object.sourceServiceName = _templatizeSourceServiceName(object.sourceServiceName, dependencies);
1745
+ }
1746
+ }
1747
+ exports._processAdminObject = _processAdminObject;
1748
+ /**
1749
+ * Templatize the name based on the given dependencies
1750
+ *
1751
+ * @param lookupName The current name from the source service
1752
+ * @param dependencies Array of IDependency for name mapping
1753
+ * @returns The templatized name || undefined when no matching dependency is found
1754
+ * @private
1755
+ */
1756
+ function _templatizeSourceServiceName(lookupName, dependencies) {
1757
+ const deps = dependencies.filter((dependency) => dependency.name === lookupName);
1758
+ return deps.length === 1 ? _templatize(deps[0].id, "name") : undefined;
1759
+ }
1760
+ exports._templatizeSourceServiceName = _templatizeSourceServiceName;
1761
+ /**
1762
+ * templatize the fields referenced in adminLayerInfo
1763
+ *
1764
+ * @param layer the layer object with the adminLayerInfo property to templatize
1765
+ * @param basePath path used to de-templatize while deploying
1766
+ * @param itemID the id for the item that contains this layer
1767
+ * @private
1768
+ */
1769
+ function _templatizeAdminLayerInfoFields(layer, dependencies) {
1770
+ // templatize the source layer fields
1771
+ const table = (0, generalHelpers_1.getProp)(layer, "adminLayerInfo.viewLayerDefinition.table");
1772
+ if (table) {
1773
+ let id = _getDependantItemId(table.sourceServiceName, dependencies);
1774
+ const path = id + ".layer" + table.sourceLayerId + ".fields";
1775
+ _templatizeAdminSourceLayerFields(table.sourceLayerFields || [], path);
1776
+ // templatize the releated table fields
1777
+ const relatedTables = (0, generalHelpers_1.getProp)(layer, "adminLayerInfo.viewLayerDefinition.table.relatedTables") || [];
1778
+ if (relatedTables.length > 0) {
1779
+ relatedTables.forEach((t) => {
1780
+ id = _getDependantItemId(t.sourceServiceName, dependencies);
1781
+ const relatedPath = id + ".layer" + t.sourceLayerId + ".fields";
1782
+ _templatizeTopFilter(t.topFilter || {}, relatedPath);
1783
+ _templatizeAdminSourceLayerFields(t.sourceLayerFields || [], relatedPath);
1784
+ const parentKeyFields = t.parentKeyFields || [];
1785
+ t.parentKeyFields = parentKeyFields.map((f) => {
1786
+ return _templatize(path, f, "name");
1787
+ });
1788
+ const keyFields = t.keyFields || [];
1789
+ t.keyFields = keyFields.map((f) => {
1790
+ return _templatize(relatedPath, f, "name");
1791
+ });
1792
+ });
1793
+ }
1794
+ }
1795
+ }
1796
+ exports._templatizeAdminLayerInfoFields = _templatizeAdminLayerInfoFields;
1797
+ /**
1798
+ * find id based on dependency name
1799
+ *
1800
+ * @param lookupName name of dependency we want to find the id of
1801
+ * @param dependencies array of item dependencies
1802
+ * @private
1803
+ */
1804
+ function _getDependantItemId(lookupName, dependencies) {
1805
+ const deps = dependencies.filter((dependency) => dependency.name === lookupName);
1806
+ return deps.length === 1 ? deps[0].id : "";
1807
+ }
1808
+ exports._getDependantItemId = _getDependantItemId;
1809
+ /**
1810
+ * templatize the sourceLayerFields referenced in adminLayerInfo
1811
+ *
1812
+ * @param fields array of sourceLayerFields to templatize
1813
+ * @param basePath path used to de-templatize while deploying
1814
+ * @private
1815
+ */
1816
+ function _templatizeAdminSourceLayerFields(fields, basePath) {
1817
+ fields.forEach((f) => _templatizeProperty(f, "source", basePath, "name"));
1818
+ }
1819
+ exports._templatizeAdminSourceLayerFields = _templatizeAdminSourceLayerFields;
1820
+ /**
1821
+ * templatize the topFilter property from adminLayerInfo related tables
1822
+ *
1823
+ * @param topFilter the topFilter object to templatize
1824
+ * @param basePath path used to de-templatize while deploying
1825
+ * @private
1826
+ */
1827
+ function _templatizeTopFilter(topFilter, basePath) {
1828
+ /* istanbul ignore else */
1829
+ if (topFilter) {
1830
+ // templatize the orderByFields prop
1831
+ const orderByFields = topFilter["orderByFields"] || "";
1832
+ /* istanbul ignore else */
1833
+ if (orderByFields !== "") {
1834
+ const orderByField = orderByFields.split(" ")[0];
1835
+ topFilter.orderByFields = topFilter.orderByFields.replace(orderByField, _templatize(basePath, orderByField, "name"));
1836
+ }
1837
+ const groupByFields = topFilter["groupByFields"] || "";
1838
+ /* istanbul ignore else */
1839
+ if (groupByFields !== "") {
1840
+ const _groupByFields = groupByFields.split(",");
1841
+ /* istanbul ignore else */
1842
+ if (_groupByFields.length > 0) {
1843
+ const mappedFields = _groupByFields.map((f) => {
1844
+ return _templatize(basePath, f, "name");
1845
+ });
1846
+ topFilter.groupByFields = mappedFields.join(",");
1847
+ }
1848
+ }
1849
+ }
1850
+ }
1851
+ exports._templatizeTopFilter = _templatizeTopFilter;
1852
+ /**
1853
+ * templatize the relationships key fields using the related table id in the basePath
1854
+ *
1855
+ * @param layer the layer that has the relationships to templatize
1856
+ * @param itemID the id of the item that contains the related table
1857
+ * @private
1858
+ */
1859
+ function _templatizeRelationshipFields(layer, itemID) {
1860
+ if (layer && layer.relationships) {
1861
+ const relationships = layer.relationships;
1862
+ relationships.forEach((r) => {
1863
+ /* istanbul ignore else */
1864
+ if (r.keyField) {
1865
+ const basePath = itemID + ".layer" + layer.id + ".fields";
1866
+ _templatizeProperty(r, "keyField", basePath, "name");
1867
+ }
1868
+ });
1869
+ }
1870
+ }
1871
+ exports._templatizeRelationshipFields = _templatizeRelationshipFields;
1872
+ /**
1873
+ * templatize the popupInfo
1874
+ *
1875
+ * @param layerDefinition the layerDefinition that has the popupInfo to templatize
1876
+ * @param layer the JSON for the layer being templatized
1877
+ * @param basePath path used to de-templatize while deploying
1878
+ * @param itemID the id for the item that contains this layer
1879
+ * @param fieldNames array of fieldNames
1880
+ * @private
1881
+ */
1882
+ function _templatizePopupInfo(layerDefinition, layer, basePath, itemID, fieldNames) {
1883
+ // the data layer does not have the fields...will need to get those
1884
+ // from the associated layer json
1885
+ if (fieldNames && layerDefinition.popupInfo) {
1886
+ const popupInfo = layerDefinition.popupInfo;
1887
+ _templatizeName(popupInfo, "title", fieldNames, basePath);
1888
+ _templatizeName(popupInfo, "description", fieldNames, basePath);
1889
+ const fieldInfos = popupInfo.fieldInfos || [];
1890
+ _templatizePopupInfoFieldInfos(fieldInfos, layer, itemID, basePath);
1891
+ const expressionInfos = popupInfo.expressionInfos || [];
1892
+ _templatizeExpressionInfos(expressionInfos, fieldNames, basePath);
1893
+ const popupElements = popupInfo.popupElements || [];
1894
+ _templatizePopupElements(popupElements, basePath, layer, itemID, fieldNames);
1895
+ const mediaInfos = popupInfo.mediaInfos || [];
1896
+ _templatizeMediaInfos(mediaInfos, fieldNames, basePath, layer, itemID);
1897
+ }
1898
+ }
1899
+ exports._templatizePopupInfo = _templatizePopupInfo;
1900
+ /**
1901
+ * templatize field name when referenced like this: \{\{fieldName\}\}
1902
+ * checks each field name from the layer
1903
+ *
1904
+ * @param object with the property to test for a field name
1905
+ * @param property that could have a field name referenced
1906
+ * @param fieldNames array for field names for the layer
1907
+ * @param basePath path used to de-templatize while deploying
1908
+ * @private
1909
+ */
1910
+ function _templatizeName(object, property, fieldNames, basePath) {
1911
+ if (object.hasOwnProperty(property)) {
1912
+ fieldNames.forEach((name) => {
1913
+ // Only test and replace instance of the name so any enclosing characters
1914
+ // will be retained
1915
+ const regEx = new RegExp("(\\b" + name + "\\b(?![}]{2}))", "gm");
1916
+ if (regEx.test(object[property])) {
1917
+ object[property] = object[property].replace(regEx, _templatize(basePath, name, "name"));
1918
+ }
1919
+ });
1920
+ }
1921
+ }
1922
+ exports._templatizeName = _templatizeName;
1923
+ /**
1924
+ * templatize field name when referenced like this: \{\{fieldName\}\}
1925
+ * checks each field name from the layer
1926
+ *
1927
+ * @param fieldInfos object that contains the popups fieldInfos
1928
+ * @param layer json of layer being cloned
1929
+ * @param itemID id of the item that contains the current layer
1930
+ * @param basePath path used to de-templatize while deploying
1931
+ * @private
1932
+ */
1933
+ function _templatizePopupInfoFieldInfos(fieldInfos, layer, itemID, basePath) {
1934
+ fieldInfos.forEach((f) => {
1935
+ f.fieldName = _templatizeFieldName(f.fieldName, layer, itemID, basePath);
1936
+ });
1937
+ }
1938
+ exports._templatizePopupInfoFieldInfos = _templatizePopupInfoFieldInfos;
1939
+ /**
1940
+ * templatize field name when referenced like this: \{\{fieldName\}\}
1941
+ * checks each field name from the layer
1942
+ *
1943
+ * @param name the field name to templatize
1944
+ * @param layer json of layer being cloned
1945
+ * @param itemID id of the item that contains the current layer
1946
+ * @param basePath path used to de-templatize while deploying
1947
+ * @private
1948
+ */
1949
+ function _templatizeFieldName(name, layer, itemID, basePath) {
1950
+ if (name.indexOf("relationships/") > -1) {
1951
+ const rels = name.split("/");
1952
+ const relationshipId = rels[1];
1953
+ const adminRelatedTables = (0, generalHelpers_1.getProp)(layer, "adminLayerInfo.viewLayerDefinition.table.relatedTables");
1954
+ const relatedTables = layer.relationships || adminRelatedTables;
1955
+ /* istanbul ignore else */
1956
+ if (relatedTables && relatedTables.length > parseInt(relationshipId, 10)) {
1957
+ const relatedTable = relatedTables[relationshipId];
1958
+ // the layers relationships stores the property as relatedTableId
1959
+ // the layers adminLayerInfo relatedTables stores the property as sourceLayerId
1960
+ const prop = (0, generalHelpers_1.getProp)(relatedTable, "relatedTableId") ? "relatedTableId" : "sourceLayerId";
1961
+ const _basePath = itemID + ".layer" + relatedTable[prop] + ".fields";
1962
+ rels[2] = _templatize(_basePath, rels[2], "name");
1963
+ name = rels.join("/");
1964
+ }
1965
+ }
1966
+ else {
1967
+ // do not need to templatize expression references as the expression
1968
+ // itself will be templatized
1969
+ if (name.indexOf("expression/") === -1) {
1970
+ name = _templatize(basePath, name, "name");
1971
+ }
1972
+ }
1973
+ return name;
1974
+ }
1975
+ exports._templatizeFieldName = _templatizeFieldName;
1976
+ /**
1977
+ * templatize field name when referenced in expressionInfos
1978
+ *
1979
+ * @param expressionInfos the popups expressionInfos to check
1980
+ * @param fieldNames array of the layers field names
1981
+ * @param basePath path used to de-templatize while deploying
1982
+ * @private
1983
+ */
1984
+ function _templatizeExpressionInfos(expressionInfos, fieldNames, basePath) {
1985
+ return expressionInfos.map((i) => {
1986
+ fieldNames.forEach((name) => {
1987
+ i.expression = _templatizeArcadeExpressions(i.expression, name, basePath);
1988
+ });
1989
+ return i;
1990
+ });
1991
+ }
1992
+ exports._templatizeExpressionInfos = _templatizeExpressionInfos;
1993
+ /**
1994
+ * templatize field name when referenced in popupElelments
1995
+ *
1996
+ * @param popupElelments the popups popupElelments to check
1997
+ * @param basePath path used to de-templatize while deploying
1998
+ * @param layer json of layer being cloned
1999
+ * @param itemID id of the item that contains the current layer
2000
+ * @param fieldNames array of field names
2001
+ * @private
2002
+ */
2003
+ function _templatizePopupElements(popupElelments, basePath, layer, itemID, fieldNames) {
2004
+ popupElelments.forEach((pe) => {
2005
+ if (pe.hasOwnProperty("fieldInfos")) {
2006
+ _templatizePopupInfoFieldInfos(pe.fieldInfos, layer, itemID, basePath);
2007
+ }
2008
+ if (pe.hasOwnProperty("mediaInfos")) {
2009
+ _templatizeMediaInfos(pe.mediaInfos, fieldNames, basePath, layer, itemID);
2010
+ }
2011
+ });
2012
+ }
2013
+ exports._templatizePopupElements = _templatizePopupElements;
2014
+ /**
2015
+ * templatize field name when referenced in mediaInfos
2016
+ *
2017
+ * @param mediaInfos the popups mediaInfos to check
2018
+ * @param fieldNames array of the layers field names
2019
+ * @param basePath path used to de-templatize while deploying
2020
+ * @param layer json of layer being cloned
2021
+ * @param itemID id of the item that contains the current layer
2022
+ * @private
2023
+ */
2024
+ function _templatizeMediaInfos(mediaInfos, fieldNames, basePath, layer, itemId) {
2025
+ // templatize various properties of mediaInfos
2026
+ const props = ["title", "caption"];
2027
+ props.forEach((p) => _templatizeName(mediaInfos, p, fieldNames, basePath));
2028
+ mediaInfos.forEach((mi) => {
2029
+ /* istanbul ignore else */
2030
+ if (mi.hasOwnProperty("value")) {
2031
+ const v = mi.value;
2032
+ const vfields = v.fields || [];
2033
+ v.fields = vfields.map((f) => _templatizeFieldName(f, layer, itemId, basePath));
2034
+ if (v.hasOwnProperty("normalizeField")) {
2035
+ _templatizeProperty(v, "normalizeField", basePath, "name");
2036
+ }
2037
+ /* istanbul ignore else */
2038
+ if (v.hasOwnProperty("tooltipField")) {
2039
+ v.tooltipField = _templatizeFieldName(v.tooltipField, layer, itemId, basePath);
2040
+ }
2041
+ }
2042
+ });
2043
+ }
2044
+ exports._templatizeMediaInfos = _templatizeMediaInfos;
2045
+ /**
2046
+ * templatize field names when referenced in definitionEditor
2047
+ *
2048
+ * @param layer the layer with the definition editor
2049
+ * @param basePath path used to de-templatize while deploying
2050
+ * @param fieldNames json of layer being cloned
2051
+ * @private
2052
+ */
2053
+ function _templatizeDefinitionEditor(layer, basePath, fieldNames) {
2054
+ if (layer) {
2055
+ const defEditor = layer.definitionEditor || {};
2056
+ /* istanbul ignore else */
2057
+ if (defEditor) {
2058
+ const inputs = defEditor.inputs;
2059
+ if (inputs) {
2060
+ inputs.forEach((i) => {
2061
+ /* istanbul ignore else */
2062
+ if (i.parameters) {
2063
+ i.parameters.forEach((p) => {
2064
+ _templatizeProperty(p, "fieldName", basePath, "name");
2065
+ });
2066
+ }
2067
+ });
2068
+ }
2069
+ if (defEditor.hasOwnProperty("parameterizedExpression")) {
2070
+ defEditor.parameterizedExpression = _templatizeSimpleName(defEditor.parameterizedExpression || "", basePath, fieldNames, "name");
2071
+ }
2072
+ }
2073
+ }
2074
+ }
2075
+ exports._templatizeDefinitionEditor = _templatizeDefinitionEditor;
2076
+ /**
2077
+ * templatize field names when referenced in definitionExpression
2078
+ *
2079
+ * @param layer the layer with the definition editor
2080
+ * @param basePath path used to de-templatize while deploying
2081
+ * @param fieldNames array of field names
2082
+ * @private
2083
+ */
2084
+ function _templatizeDefinitionExpression(layer, basePath, fieldNames) {
2085
+ if (layer && layer.hasOwnProperty("definitionExpression")) {
2086
+ layer.definitionExpression = _templatizeSimpleName(layer.definitionExpression || "", basePath, fieldNames, "name");
2087
+ }
2088
+ }
2089
+ exports._templatizeDefinitionExpression = _templatizeDefinitionExpression;
2090
+ /**
2091
+ * Case sensitive test for field names that appear anywhere within a string
2092
+ *
2093
+ * @param expression the expression to test for field name references
2094
+ * @param basePath path used to de-templatize while deploying
2095
+ * @param fieldNames array of the layers field names
2096
+ * @private
2097
+ */
2098
+ function _templatizeSimpleName(expression, basePath, fieldNames, suffix) {
2099
+ fieldNames.forEach((name) => {
2100
+ // look for the name but not if its followed by }}
2101
+ const regEx = new RegExp("\\b" + name + "\\b(?![}]{2})", "gm");
2102
+ if (expression && regEx.test(expression)) {
2103
+ expression = expression.replace(regEx, _templatize(basePath, name, suffix));
2104
+ }
2105
+ });
2106
+ return expression;
2107
+ }
2108
+ exports._templatizeSimpleName = _templatizeSimpleName;
2109
+ /**
2110
+ * Templatize field references within a layers drawingInfo
2111
+ *
2112
+ * @param layer the data layer
2113
+ * @param basePath path used to de-templatize while deploying
2114
+ * @param fieldNames array of the layers field names
2115
+ * @private
2116
+ */
2117
+ function _templatizeDrawingInfo(layer, basePath, fieldNames) {
2118
+ if (layer) {
2119
+ const drawingInfo = layer.drawingInfo;
2120
+ if (drawingInfo) {
2121
+ // templatize the renderer fields
2122
+ const renderer = drawingInfo.renderer || {};
2123
+ _templatizeRenderer(renderer, basePath, fieldNames);
2124
+ // templatize the labelingInfo
2125
+ const labelingInfo = drawingInfo.labelingInfo || [];
2126
+ _templatizeLabelingInfo(labelingInfo, basePath, fieldNames);
2127
+ }
2128
+ }
2129
+ }
2130
+ exports._templatizeDrawingInfo = _templatizeDrawingInfo;
2131
+ /**
2132
+ * Templatize field references within a layers drawingInfo
2133
+ *
2134
+ * @param renderer the layers renderer
2135
+ * @param basePath path used to de-templatize while deploying
2136
+ * @param fieldNames array of the layers field names
2137
+ * @private
2138
+ */
2139
+ function _templatizeRenderer(renderer, basePath, fieldNames) {
2140
+ switch (renderer.type) {
2141
+ case "classBreaks":
2142
+ case "uniqueValue":
2143
+ case "predominance":
2144
+ case "simple":
2145
+ case "heatmap":
2146
+ _templatizeGenRenderer(renderer, basePath, fieldNames);
2147
+ break;
2148
+ case "temporal":
2149
+ _templatizeTemporalRenderer(renderer, basePath, fieldNames);
2150
+ break;
2151
+ default:
2152
+ break;
2153
+ }
2154
+ }
2155
+ exports._templatizeRenderer = _templatizeRenderer;
2156
+ /**
2157
+ * Templatize field references within a layers renderer
2158
+ *
2159
+ * @param renderer the renderer object to check for field references
2160
+ * @param basePath path used to de-templatize while deploying
2161
+ * @param fieldNames array of field names that will be used to search expressions
2162
+ * @private
2163
+ */
2164
+ function _templatizeGenRenderer(renderer, basePath, fieldNames) {
2165
+ /* istanbul ignore else */
2166
+ if (renderer) {
2167
+ // update authoringInfo
2168
+ const authoringInfo = renderer.authoringInfo;
2169
+ if (authoringInfo) {
2170
+ _templatizeAuthoringInfo(authoringInfo, basePath, fieldNames);
2171
+ }
2172
+ const props = ["field", "normalizationField"];
2173
+ props.forEach((p) => _templatizeProperty(renderer, p, basePath, "name"));
2174
+ const fieldNameProps = ["field1", "field2", "field3"];
2175
+ fieldNameProps.forEach((fnP) => _templatizeProperty(renderer, fnP, basePath, "name"));
2176
+ // When an attribute name is specified, it's enclosed in square brackets
2177
+ const rExp = renderer.rotationExpression;
2178
+ if (rExp) {
2179
+ fieldNames.forEach((name) => {
2180
+ const regEx = new RegExp("(\\[" + name + "\\])", "gm");
2181
+ if (regEx.test(rExp)) {
2182
+ renderer.rotationExpression = rExp.replace(regEx, "[" + _templatize(basePath, name, "name") + "]");
2183
+ }
2184
+ });
2185
+ }
2186
+ // update valueExpression
2187
+ if (renderer.valueExpression) {
2188
+ fieldNames.forEach((name) => {
2189
+ renderer.valueExpression = _templatizeArcadeExpressions(renderer.valueExpression, name, basePath);
2190
+ });
2191
+ }
2192
+ // update visualVariables
2193
+ const visualVariables = renderer.visualVariables;
2194
+ if (visualVariables) {
2195
+ visualVariables.forEach((v) => {
2196
+ props.forEach((p) => _templatizeProperty(v, p, basePath, "name"));
2197
+ if (v.valueExpression) {
2198
+ fieldNames.forEach((name) => {
2199
+ v.valueExpression = _templatizeArcadeExpressions(v.valueExpression, name, basePath);
2200
+ });
2201
+ }
2202
+ });
2203
+ }
2204
+ }
2205
+ }
2206
+ exports._templatizeGenRenderer = _templatizeGenRenderer;
2207
+ /**
2208
+ * Templatize field references within a layers renderer
2209
+ *
2210
+ * @param renderer the renderer object to check for field references
2211
+ * @param basePath path used to de-templatize while deploying
2212
+ * @param fieldNames array of field names that will be used to search expressions
2213
+ * @private
2214
+ */
2215
+ function _templatizeTemporalRenderer(renderer, basePath, fieldNames) {
2216
+ const renderers = [renderer.latestObservationRenderer, renderer.observationRenderer, renderer.trackRenderer];
2217
+ renderers.forEach((r) => {
2218
+ _templatizeRenderer(r, basePath, fieldNames);
2219
+ });
2220
+ }
2221
+ exports._templatizeTemporalRenderer = _templatizeTemporalRenderer;
2222
+ /**
2223
+ * Templatize renderers authoringInfo
2224
+ *
2225
+ * @param authoringInfo object containing metadata about the authoring process
2226
+ * @param basePath path used to de-templatize while deploying
2227
+ * @param fieldNames the name of fields from the layer
2228
+ * @private
2229
+ */
2230
+ function _templatizeAuthoringInfo(authoringInfo, basePath, fieldNames) {
2231
+ /* istanbul ignore else */
2232
+ if (authoringInfo) {
2233
+ const props = ["field", "normalizationField"];
2234
+ const field1 = authoringInfo.field1;
2235
+ props.forEach((p) => _templatizeProperty(field1, p, basePath, "name"));
2236
+ const field2 = authoringInfo.field2;
2237
+ props.forEach((p) => _templatizeProperty(field2, p, basePath, "name"));
2238
+ const fields = authoringInfo.fields;
2239
+ if (fields) {
2240
+ authoringInfo.fields = fields.map((f) => _templatize(basePath, f, "name"));
2241
+ }
2242
+ const vProps = ["endTime", "field", "startTime"];
2243
+ const vVars = authoringInfo.visualVariables;
2244
+ if (vVars) {
2245
+ vProps.forEach((p) => {
2246
+ // endTime and startTime may or may not be a field name
2247
+ if (fieldNames.indexOf(vVars[p]) > -1) {
2248
+ _templatizeProperty(vVars, p, basePath, "name");
2249
+ }
2250
+ });
2251
+ }
2252
+ }
2253
+ }
2254
+ exports._templatizeAuthoringInfo = _templatizeAuthoringInfo;
2255
+ /**
2256
+ * Templatize field references within an arcade expression
2257
+ *
2258
+ * @param text the text that contains the expression
2259
+ * @param fieldName name of the field to test for
2260
+ * @param basePath path used to de-templatize while deploying
2261
+ * @private
2262
+ */
2263
+ function _templatizeArcadeExpressions(text, fieldName, basePath) {
2264
+ const t = _templatize(basePath, fieldName, "name");
2265
+ if (text) {
2266
+ // test for $feature. notation
2267
+ // captures VOTED_DEM_2012 from $feature.VOTED_DEM_2012
2268
+ let exp = "(?:\\$feature\\.)(" + fieldName + ")\\b";
2269
+ let regEx = new RegExp(exp, "gm");
2270
+ text = regEx.test(text) ? text.replace(regEx, "$feature." + t) : text;
2271
+ // test for $feature[] notation
2272
+ // captures VOTED_DEM_2012 from $feature["VOTED_DEM_2012"]
2273
+ // captures VOTED_DEM_2012 from $feature['VOTED_DEM_2012']
2274
+ // captures VOTED_DEM_2012 from $feature[VOTED_DEM_2012]
2275
+ exp = "(?:[$]feature)(\\[\\\"?\\'?)" + fieldName + "(\\\"?\\'?\\])";
2276
+ regEx = new RegExp(exp, "gm");
2277
+ let result = regEx.exec(text);
2278
+ if (result) {
2279
+ text = text.replace(regEx, "$feature" + result[1] + t + result[2]);
2280
+ }
2281
+ // test for $feature[] with join case
2282
+ // captures VOTED_DEM_2016 from $feature["COUNTY_ID.VOTED_DEM_2016"]
2283
+ exp = "(?:[$]feature)(\\[\\\"?\\'?)(\\w+)[.]" + fieldName + "(\\\"?\\'?\\])";
2284
+ regEx = new RegExp(exp, "gm");
2285
+ result = regEx.exec(text);
2286
+ if (result && result.length > 3) {
2287
+ // TODO result[2] is the table name...this needs to be templatized as well
2288
+ text = text.replace(regEx, "$feature" + result[1] + result[2] + "." + t + result[3]);
2289
+ }
2290
+ // test for "fieldName"
2291
+ // captures fieldName from "var names = ["fieldName", "fieldName2"]..."
2292
+ // captures fieldName from "var names = ['fieldName', 'fieldName2']..."
2293
+ exp = "(\\\"|\\')+" + fieldName + "(\\\"|\\')+";
2294
+ regEx = new RegExp(exp, "gm");
2295
+ result = regEx.exec(text);
2296
+ if (result) {
2297
+ text = text.replace(regEx, result[1] + t + result[2]);
2298
+ }
2299
+ }
2300
+ return text;
2301
+ }
2302
+ exports._templatizeArcadeExpressions = _templatizeArcadeExpressions;
2303
+ /**
2304
+ * templatize field names when referenced in the layers labelingInfo
2305
+ *
2306
+ * @param labelingInfo the object that contains the labelingInfo
2307
+ * @param basePath path used to de-templatize while deploying
2308
+ * @param fieldNames array of the layers field names
2309
+ * @private
2310
+ */
2311
+ function _templatizeLabelingInfo(labelingInfo, basePath, fieldNames) {
2312
+ labelingInfo.forEach((li) => {
2313
+ /* istanbul ignore else */
2314
+ if (li.hasOwnProperty("fieldInfos")) {
2315
+ const fieldInfos = li.fieldInfos || [];
2316
+ fieldInfos.forEach((fi) => _templatizeProperty(fi, "fieldName", basePath, "name"));
2317
+ }
2318
+ const labelExp = li.labelExpression || "";
2319
+ const labelExpInfo = li.labelExpressionInfo || {};
2320
+ fieldNames.forEach((n) => {
2321
+ const t = _templatize(basePath, n, "name");
2322
+ // check for [fieldName] or ["fieldName"]
2323
+ const regExBracket = new RegExp('(\\[\\"*)+(' + n + ')(\\"*\\])+', "gm");
2324
+ let result = regExBracket.exec(labelExp);
2325
+ if (result) {
2326
+ li.labelExpression = labelExp.replace(regExBracket, result[1] + t + result[3]);
2327
+ }
2328
+ /* istanbul ignore else */
2329
+ if (labelExpInfo.value) {
2330
+ let v = labelExpInfo.value;
2331
+ // check for {fieldName}
2332
+ const regExCurly = new RegExp("(\\{" + n + "\\})", "gm");
2333
+ v = regExCurly.test(v) ? v.replace(regExCurly, "{" + t + "}") : v;
2334
+ // check for [fieldName] or ["fieldName"]
2335
+ result = regExBracket.exec(v);
2336
+ v = result ? v.replace(regExBracket, result[1] + t + result[3]) : v;
2337
+ li.labelExpressionInfo.value = v;
2338
+ }
2339
+ /* istanbul ignore else */
2340
+ if (labelExpInfo.expression) {
2341
+ li.labelExpressionInfo.expression = _templatizeArcadeExpressions(labelExpInfo.expression, n, basePath);
2342
+ }
2343
+ });
2344
+ });
2345
+ }
2346
+ exports._templatizeLabelingInfo = _templatizeLabelingInfo;
2347
+ /**
2348
+ * templatize the layers editing templates
2349
+ *
2350
+ * @param layer the data layer being cloned
2351
+ * @param basePath path used to de-templatize while deploying
2352
+ * @private
2353
+ */
2354
+ function _templatizeTemplates(layer, basePath) {
2355
+ const templates = layer.templates || [];
2356
+ templates.forEach((t) => {
2357
+ const attributes = (0, generalHelpers_1.getProp)(t, "prototype.attributes");
2358
+ const _attributes = _templatizeKeys(attributes, basePath, "name");
2359
+ /* istanbul ignore else */
2360
+ if (_attributes) {
2361
+ t.prototype.attributes = _attributes;
2362
+ }
2363
+ });
2364
+ }
2365
+ exports._templatizeTemplates = _templatizeTemplates;
2366
+ /**
2367
+ * templatize the layer types and templates
2368
+ *
2369
+ * @param layer the data layer being cloned
2370
+ * @param basePath path used to de-templatize while deploying
2371
+ * @private
2372
+ */
2373
+ function _templatizeTypeTemplates(layer, basePath) {
2374
+ const types = layer.types;
2375
+ if (types && Array.isArray(types) && types.length > 0) {
2376
+ types.forEach((type) => {
2377
+ const domains = _templatizeKeys(type.domains, basePath, "name");
2378
+ /* istanbul ignore else */
2379
+ if (domains) {
2380
+ type.domains = domains;
2381
+ }
2382
+ const templates = type.templates;
2383
+ /* istanbul ignore else */
2384
+ if (templates && templates.length > 0) {
2385
+ templates.forEach((t) => {
2386
+ const attributes = (0, generalHelpers_1.getProp)(t, "prototype.attributes");
2387
+ const _attributes = _templatizeKeys(attributes, basePath, "name");
2388
+ /* istanbul ignore else */
2389
+ if (_attributes) {
2390
+ t.prototype.attributes = _attributes;
2391
+ }
2392
+ });
2393
+ }
2394
+ });
2395
+ }
2396
+ }
2397
+ exports._templatizeTypeTemplates = _templatizeTypeTemplates;
2398
+ /**
2399
+ * templatize object keys
2400
+ *
2401
+ * @param obj the object to templatize
2402
+ * @param basePath path used to de-templatize while deploying
2403
+ * @param suffix expected suffix for template variable
2404
+ * @private
2405
+ */
2406
+ function _templatizeKeys(obj, basePath, suffix) {
2407
+ let _obj;
2408
+ /* istanbul ignore else */
2409
+ if (obj) {
2410
+ _obj = {};
2411
+ const objKeys = Object.keys(obj);
2412
+ /* istanbul ignore else */
2413
+ if (objKeys && objKeys.length > 0) {
2414
+ objKeys.forEach((k) => {
2415
+ _obj[_templatize(basePath, k, suffix)] = obj[k];
2416
+ });
2417
+ }
2418
+ }
2419
+ return _obj;
2420
+ }
2421
+ exports._templatizeKeys = _templatizeKeys;
2422
+ /**
2423
+ * templatize fields referenced in the layers time info
2424
+ *
2425
+ * @param layer the data layer being cloned
2426
+ * @param basePath path used to de-templatize while deploying
2427
+ * @private
2428
+ */
2429
+ function _templatizeTimeInfo(layer, basePath) {
2430
+ if (layer.timeInfo) {
2431
+ const timeInfo = layer.timeInfo;
2432
+ const timeProps = ["endTimeField", "startTimeField", "trackIdField"];
2433
+ timeProps.forEach((t) => {
2434
+ if (timeInfo[t] !== "") {
2435
+ _templatizeProperty(timeInfo, t, basePath, "name");
2436
+ }
2437
+ else {
2438
+ timeInfo[t] = null;
2439
+ }
2440
+ });
2441
+ }
2442
+ }
2443
+ exports._templatizeTimeInfo = _templatizeTimeInfo;
2444
+ /**
2445
+ * templatize the layers definition query
2446
+ *
2447
+ * @param layer the data layer being cloned
2448
+ * @param basePath path used to de-templatize while deploying
2449
+ * @param fieldNames array of the layers field names
2450
+ * @private
2451
+ */
2452
+ function _templatizeDefinitionQuery(layer, basePath, fieldNames) {
2453
+ // templatize view definition query
2454
+ if (layer && layer.hasOwnProperty("viewDefinitionQuery")) {
2455
+ layer.viewDefinitionQuery = _templatizeSimpleName(layer.viewDefinitionQuery || "", basePath, fieldNames, "name");
2456
+ }
2457
+ if (layer && layer.hasOwnProperty("definitionQuery")) {
2458
+ layer.definitionQuery = _templatizeSimpleName(layer.definitionQuery || "", basePath, fieldNames, "name");
2459
+ }
2460
+ }
2461
+ exports._templatizeDefinitionQuery = _templatizeDefinitionQuery;
2462
+ /**
2463
+ * Helper function to create the name mapping used to
2464
+ * de-templatize the field reference
2465
+ *
2466
+ * @param fieldInfos the object that stores the cached information
2467
+ * @param id the id for the current layer being processed
2468
+ * @private
2469
+ */
2470
+ function _getNameMapping(fieldInfos, id) {
2471
+ // create name mapping
2472
+ const fInfo = fieldInfos[id];
2473
+ const nameMapping = {};
2474
+ const newFields = fInfo.newFields;
2475
+ const newFieldNames = newFields ? newFields.map((f) => f.name) : [];
2476
+ const sourceFields = fInfo.sourceFields || [];
2477
+ sourceFields.forEach((field) => {
2478
+ const lName = String(field.name).toLowerCase();
2479
+ newFields.forEach((f) => {
2480
+ // Names can change more than case
2481
+ if (newFieldNames.indexOf(field.name) === -1 && newFieldNames.indexOf(lName) === -1) {
2482
+ // If both new (f) and source (field) aliases are defined and are equal, map the source name to the new name
2483
+ if (f.alias && f.alias === field.alias) {
2484
+ nameMapping[lName] = {
2485
+ name: f.name,
2486
+ alias: f.alias,
2487
+ type: f.type ? f.type : "",
2488
+ };
2489
+ }
2490
+ }
2491
+ if (String(f.name).toLowerCase() === lName) {
2492
+ nameMapping[lName] = {
2493
+ name: f.name,
2494
+ alias: f.alias ? f.alias : "",
2495
+ type: f.type ? f.type : "",
2496
+ };
2497
+ }
2498
+ });
2499
+ });
2500
+ // update for editFieldsInfo
2501
+ if (fInfo.editFieldsInfo && fInfo.newEditFieldsInfo) {
2502
+ const efi = JSON.parse(JSON.stringify(fInfo.editFieldsInfo));
2503
+ const newEfi = JSON.parse(JSON.stringify(fInfo.newEditFieldsInfo));
2504
+ const nameMappingKeys = Object.keys(nameMapping);
2505
+ Object.keys(efi).forEach((k) => {
2506
+ const lowerEfi = String(efi[k]).toLowerCase();
2507
+ if ((nameMappingKeys.indexOf(lowerEfi) === -1 || nameMapping[lowerEfi].name !== newEfi[k]) &&
2508
+ newFieldNames.indexOf(lowerEfi) > -1) {
2509
+ // Only add delete fields if source schema changes allowed
2510
+ /* istanbul ignore else */
2511
+ if (fInfo.sourceSchemaChangesAllowed && !fInfo.isView) {
2512
+ /* istanbul ignore else */
2513
+ if (!fInfo.hasOwnProperty("deleteFields")) {
2514
+ fInfo.deleteFields = [];
2515
+ }
2516
+ // This issue only occurs on portal so we
2517
+ // need to delete the lcase version of the field
2518
+ fInfo.deleteFields.push(lowerEfi);
2519
+ }
2520
+ // editFieldsInfo only has the name and not the alias and type
2521
+ let sourceEfiField;
2522
+ fInfo.sourceFields.some((sf) => {
2523
+ if (sf.name === efi[k]) {
2524
+ sourceEfiField = sf;
2525
+ }
2526
+ return sf.name === efi[k];
2527
+ });
2528
+ nameMapping[lowerEfi] = {
2529
+ name: newEfi[k],
2530
+ alias: sourceEfiField && sourceEfiField.alias ? sourceEfiField.alias : "",
2531
+ type: sourceEfiField && sourceEfiField.type ? sourceEfiField.type : "",
2532
+ };
2533
+ }
2534
+ });
2535
+ (0, generalHelpers_1.deleteProp)(fInfo, "sourceSchemaChangesAllowed");
2536
+ (0, generalHelpers_1.deleteProp)(fInfo, "editFieldsInfo");
2537
+ (0, generalHelpers_1.deleteProp)(fInfo, "newEditFieldsInfo");
2538
+ (0, generalHelpers_1.deleteProp)(fInfo, "isView");
2539
+ }
2540
+ return nameMapping;
2541
+ }
2542
+ exports._getNameMapping = _getNameMapping;
2543
+ /**
2544
+ * Helper function to ensure same chunk size value is used in multiple locations
2545
+ *
2546
+ * @returns a number that represents how many layers should be included per addToDef call
2547
+ * @private
2548
+ */
2549
+ function _getLayerChunkSize() {
2550
+ return 20;
2551
+ }
2552
+ exports._getLayerChunkSize = _getLayerChunkSize;
2553
+ //# sourceMappingURL=featureServiceHelpers.js.map