@esri/solution-common 6.0.4-alpha.0 → 6.1.0-alpha.0

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