@arcgis/coding-components 4.31.0-next.2 → 4.31.0-next.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/README.md +22 -3
  2. package/dist/arcgis-coding-components/arcgis-coding-components.esm.js +2 -2
  3. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.ar.json +1 -1
  4. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.bg.json +1 -1
  5. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.bs.json +1 -1
  6. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.ca.json +6 -6
  7. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.cs.json +1 -1
  8. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.da.json +1 -1
  9. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.de.json +1 -1
  10. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.el.json +1 -1
  11. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.es.json +1 -1
  12. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.et.json +1 -1
  13. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.fi.json +1 -1
  14. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.fr.json +1 -1
  15. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.he.json +1 -1
  16. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.hr.json +1 -1
  17. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.id.json +1 -1
  18. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.it.json +1 -1
  19. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.ko.json +1 -1
  20. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.nb.json +1 -1
  21. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.nl.json +1 -1
  22. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.pl.json +1 -1
  23. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.pt-BR.json +1 -1
  24. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.pt-PT.json +1 -1
  25. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.ru.json +1 -1
  26. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.sk.json +1 -1
  27. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.sl.json +1 -1
  28. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.sr.json +1 -1
  29. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.sv.json +1 -1
  30. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.th.json +1 -1
  31. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.tr.json +1 -1
  32. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.uk.json +5 -5
  33. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.vi.json +1 -1
  34. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.zh-CN.json +1 -1
  35. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.zh-HK.json +1 -1
  36. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.zh-TW.json +1 -1
  37. package/dist/arcgis-coding-components/assets/arcade-results/t9n/arcade-results.t9n.ca.json +2 -2
  38. package/dist/arcgis-coding-components/assets/arcade-results/t9n/arcade-results.t9n.de.json +1 -1
  39. package/dist/arcgis-coding-components/assets/arcade-results/t9n/arcade-results.t9n.he.json +1 -1
  40. package/dist/arcgis-coding-components/assets/arcade-variables/t9n/arcade-variables.t9n.ca.json +1 -1
  41. package/dist/arcgis-coding-components/assets/arcade-variables/t9n/arcade-variables.t9n.it.json +1 -1
  42. package/dist/arcgis-coding-components/assets/code-editor/css.worker.js +1 -1
  43. package/dist/arcgis-coding-components/assets/code-editor/html.worker.js +1 -1
  44. package/dist/arcgis-coding-components/assets/code-editor/json.worker.js +1 -1
  45. package/dist/arcgis-coding-components/assets/code-editor/sql-expr.worker.js +33 -0
  46. package/dist/arcgis-coding-components/assets/code-editor/ts.worker.js +1 -1
  47. package/dist/arcgis-coding-components/assets/language-api-panel/t9n/language-api-panel.t9n.ca.json +1 -1
  48. package/dist/arcgis-coding-components/assets/sql-expression-editor/api/sql-expression-api.t9n.en.json +735 -0
  49. package/dist/arcgis-coding-components/index.esm.js +2 -2
  50. package/dist/arcgis-coding-components/{p-7984ea8e.js → p-1b799777.js} +2 -2
  51. package/dist/arcgis-coding-components/p-4d5cf512.entry.js +6 -0
  52. package/dist/arcgis-coding-components/{p-60c2a820.js → p-56266a64.js} +2 -2
  53. package/dist/arcgis-coding-components/{p-e8211ffe.js → p-57b8bcd7.js} +1 -1
  54. package/dist/arcgis-coding-components/{p-9eced6fc.js → p-5b67b62b.js} +2 -2
  55. package/dist/arcgis-coding-components/{p-93a97573.js → p-64137fec.js} +3 -3
  56. package/dist/arcgis-coding-components/{p-e7ee4d64.js → p-6621a80f.js} +3 -3
  57. package/dist/arcgis-coding-components/p-77dd5521.js +6 -0
  58. package/dist/arcgis-coding-components/p-8eb7e694.js +6 -0
  59. package/dist/arcgis-coding-components/p-a2341e0c.js +6 -0
  60. package/dist/arcgis-coding-components/{p-bb7e832e.js → p-b715834b.js} +3 -3
  61. package/dist/arcgis-coding-components/p-cbee273f.js +6 -0
  62. package/dist/arcgis-coding-components/{p-5ef7cce5.js → p-cdc52d2f.js} +1 -1
  63. package/dist/arcgis-coding-components/{p-36fedc23.js → p-d7d1f130.js} +12 -12
  64. package/dist/arcgis-coding-components/p-e1f9b463.entry.js +6 -0
  65. package/dist/arcgis-coding-components/{p-62ee6251.js → p-e5a924a1.js} +1 -1
  66. package/dist/arcgis-coding-components/p-f2d64a9d.js +6 -0
  67. package/dist/arcgis-coding-components/{p-03ea6cd7.js → p-ff62d134.js} +3 -3
  68. package/dist/arcgis-coding-components/p-ffce0588.entry.js +6 -0
  69. package/dist/cjs/{app-globals-aee5f4b5.js → app-globals-a9ef3ca8.js} +1 -1
  70. package/dist/cjs/arcade-defaults-f5241680.js +349 -0
  71. package/dist/cjs/arcade-language-features-0b9f3947.js +274 -0
  72. package/dist/cjs/arcade-mode-cc08d9cd.js +335 -0
  73. package/dist/cjs/arcgis-arcade-editor_6.cjs.entry.js +181 -1501
  74. package/dist/cjs/arcgis-coding-components.cjs.js +4 -4
  75. package/dist/cjs/arcgis-sql-expression-editor.cjs.entry.js +81 -0
  76. package/dist/cjs/arcgis-sql-expression-fields.cjs.entry.js +80 -0
  77. package/dist/cjs/{css-7cc05f76.js → css-bb6a49ec.js} +1 -1
  78. package/dist/cjs/{cssMode-2b0daeae.js → cssMode-e7fac7d7.js} +3 -4
  79. package/dist/cjs/{html-f56911e1.js → html-7ff4071d.js} +3 -4
  80. package/dist/cjs/{htmlMode-43eed674.js → htmlMode-c89193ec.js} +3 -4
  81. package/dist/cjs/{index-b34238a6.js → index-4b7880ab.js} +9 -1
  82. package/dist/cjs/index.cjs.js +4 -3
  83. package/dist/cjs/{javascript-5115cb76.js → javascript-864c0220.js} +3 -4
  84. package/dist/cjs/{jsonMode-550dda36.js → jsonMode-ac4a7be7.js} +3 -4
  85. package/dist/cjs/{arcade-defaults-a8d8f8e2.js → language-defaults-base-57b37f9f.js} +842 -1183
  86. package/dist/cjs/loader.cjs.js +4 -4
  87. package/dist/cjs/sql-expr-defaults-245b036d.js +1347 -0
  88. package/dist/cjs/sql-expr-mode-304f5ce2.js +20844 -0
  89. package/dist/cjs/{tsMode-336306a9.js → tsMode-d30d4ab1.js} +4 -5
  90. package/dist/cjs/{typescript-b395242f.js → typescript-6c87ddb3.js} +3 -4
  91. package/dist/components/arcade-defaults.js +54 -1369
  92. package/dist/components/arcade-language-features.js +271 -0
  93. package/dist/components/arcade-mode.js +4 -264
  94. package/dist/components/arcade-results.js +7 -5
  95. package/dist/components/arcade-suggestions.js +7 -5
  96. package/dist/components/arcade-variables.js +8 -6
  97. package/dist/components/arcgis-arcade-editor.js +37 -35
  98. package/dist/components/arcgis-arcade-results.js +1 -1
  99. package/dist/components/arcgis-arcade-suggestions.js +1 -1
  100. package/dist/components/arcgis-arcade-variables.js +1 -1
  101. package/dist/components/arcgis-assets.d.ts +1 -1
  102. package/dist/components/arcgis-assets.js +1 -1
  103. package/dist/components/arcgis-code-editor.js +1 -1
  104. package/dist/components/arcgis-language-api-panel.js +1 -1
  105. package/dist/components/arcgis-sql-expression-editor.d.ts +11 -0
  106. package/dist/components/arcgis-sql-expression-editor.js +120 -0
  107. package/dist/components/arcgis-sql-expression-fields.d.ts +11 -0
  108. package/dist/components/arcgis-sql-expression-fields.js +11 -0
  109. package/dist/components/chunk-2JTWBRMN.js +1154 -0
  110. package/dist/components/code-editor.js +40 -13
  111. package/dist/components/fields.js +5 -5
  112. package/dist/components/index.js +1 -1
  113. package/dist/components/index2.js +30 -22
  114. package/dist/components/language-api-panel.js +13 -40
  115. package/dist/components/language-defaults-base.js +1309 -0
  116. package/dist/components/markdown.js +1 -1
  117. package/dist/components/sql-expr-defaults.js +196 -0
  118. package/dist/components/sql-expr-mode.js +20842 -0
  119. package/dist/components/sql-expression-fields.js +102 -0
  120. package/dist/components/useT9n.js +45 -8
  121. package/dist/components/utilities.js +1 -1
  122. package/dist/esm/{app-globals-59faaf33.js → app-globals-6d0ca11d.js} +1 -1
  123. package/dist/esm/arcade-defaults-066445c4.js +344 -0
  124. package/dist/esm/arcade-language-features-0e00c199.js +269 -0
  125. package/dist/esm/{arcade-mode-5d46035e.js → arcade-mode-abf1e1cf.js} +3 -263
  126. package/dist/esm/arcgis-arcade-editor_6.entry.js +127 -1447
  127. package/dist/esm/arcgis-coding-components.js +5 -5
  128. package/dist/esm/arcgis-sql-expression-editor.entry.js +77 -0
  129. package/dist/esm/arcgis-sql-expression-fields.entry.js +76 -0
  130. package/dist/esm/{css-e257dc49.js → css-c6dae12d.js} +1 -1
  131. package/dist/esm/{cssMode-c11f7f40.js → cssMode-052bb603.js} +2 -3
  132. package/dist/esm/{html-a6c37a99.js → html-572696a1.js} +2 -3
  133. package/dist/esm/{htmlMode-1270bc7d.js → htmlMode-fc184f2d.js} +2 -3
  134. package/dist/esm/{index-a970952c.js → index-0edd9846.js} +9 -1
  135. package/dist/esm/index.js +4 -3
  136. package/dist/esm/{javascript-ee179624.js → javascript-8bfc0096.js} +3 -4
  137. package/dist/esm/{jsonMode-07502ccb.js → jsonMode-7adf94ff.js} +2 -3
  138. package/dist/esm/{arcade-defaults-9eb28407.js → language-defaults-base-85a7f476.js} +833 -1179
  139. package/dist/esm/loader.js +5 -5
  140. package/dist/esm/sql-expr-defaults-be84ec7f.js +1339 -0
  141. package/dist/esm/sql-expr-mode-a4413e5c.js +20840 -0
  142. package/dist/esm/{tsMode-96749a12.js → tsMode-d10773c8.js} +2 -3
  143. package/dist/esm/{typescript-a3cf9881.js → typescript-9491f23e.js} +2 -3
  144. package/dist/loader/cdn.js +1 -1
  145. package/dist/loader/index.cjs.js +1 -1
  146. package/dist/loader/index.es2017.js +1 -1
  147. package/dist/loader/index.js +1 -1
  148. package/dist/types/components/arcade-editor/arcade-editor.d.ts +45 -10
  149. package/dist/types/components/arcade-results/arcade-results.d.ts +43 -1
  150. package/dist/types/components/arcade-suggestions/arcade-suggestions.d.ts +22 -1
  151. package/dist/types/components/arcade-variables/arcade-variables.d.ts +28 -1
  152. package/dist/types/components/code-editor/code-editor.d.ts +16 -5
  153. package/dist/types/components/language-api-panel/language-api-panel.d.ts +34 -8
  154. package/dist/types/components/sql-expression-editor/sql-expression-editor.d.ts +24 -0
  155. package/dist/types/components/sql-expression-fields/sql-expression-fields.d.ts +32 -0
  156. package/dist/types/components.d.ts +98 -24
  157. package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stories/internal/arcade-editor/arcade-editor.stories.d.ts +8 -1
  158. package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stories/internal/arcade-editor/editorContext.d.ts +5 -1
  159. package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stories/internal/sql-expression-editor/sql-expression-editor.stories.d.ts +13 -0
  160. package/dist/types/dependencies.d.ts +6 -10
  161. package/dist/types/utils/arcade-monaco/arcade-language-features.d.ts +1 -0
  162. package/dist/types/utils/arcade-monaco/arcade-profile-strategy.d.ts +9 -0
  163. package/dist/types/utils/fields.d.ts +2 -2
  164. package/dist/types/utils/language-defaults-base.d.ts +2 -9
  165. package/dist/types/utils/profile/editor-profile.d.ts +7 -6
  166. package/dist/types/utils/profile/types.d.ts +53 -65
  167. package/dist/types/utils/profile/utils.d.ts +9 -8
  168. package/dist/types/utils/sql-expr-monaco/DependentFiles/DateOnly.d.ts +41 -0
  169. package/dist/types/utils/sql-expr-monaco/DependentFiles/SqlInterval.d.ts +16 -0
  170. package/dist/types/utils/sql-expr-monaco/DependentFiles/SqlTimestampOffset.d.ts +26 -0
  171. package/dist/types/utils/sql-expr-monaco/DependentFiles/TimeOnly.d.ts +37 -0
  172. package/dist/types/utils/sql-expr-monaco/DependentFiles/UnknownTimeZone.d.ts +11 -0
  173. package/dist/types/utils/sql-expr-monaco/DependentFiles/WhereGrammar.d.ts +122 -0
  174. package/dist/types/utils/sql-expr-monaco/DependentFiles/sqlCompareUtils.d.ts +5 -0
  175. package/dist/types/utils/sql-expr-monaco/DependentFiles/sqlDateParsingUtils.d.ts +18 -0
  176. package/dist/types/utils/sql-expr-monaco/DependentFiles/sqlUtils.d.ts +6 -0
  177. package/dist/types/utils/sql-expr-monaco/DependentFiles/standardizedFunctions.d.ts +156 -0
  178. package/dist/types/utils/sql-expr-monaco/DependentFiles/support.d.ts +150 -0
  179. package/dist/types/utils/sql-expr-monaco/PeggyGrammar/sql92grammar.d.ts +1397 -0
  180. package/dist/types/utils/sql-expr-monaco/sql-expr-completion.d.ts +6 -0
  181. package/dist/types/utils/sql-expr-monaco/sql-expr-constants.d.ts +45 -0
  182. package/dist/types/utils/sql-expr-monaco/sql-expr-contribution.d.ts +1 -0
  183. package/dist/types/utils/sql-expr-monaco/sql-expr-defaults.d.ts +21 -0
  184. package/dist/types/utils/sql-expr-monaco/sql-expr-language-features.d.ts +39 -0
  185. package/dist/types/utils/sql-expr-monaco/sql-expr-language-syntax.d.ts +8 -0
  186. package/dist/types/utils/sql-expr-monaco/sql-expr-mode.d.ts +43 -0
  187. package/dist/types/utils/sql-expr-monaco/sql-expr-service-accessors.d.ts +19 -0
  188. package/dist/types/utils/sql-expr-monaco/sql-expr-validation-diagnostic-adapter.d.ts +34 -0
  189. package/dist/types/utils/sql-expr-monaco/sql-expr-validation-utils.d.ts +100 -0
  190. package/dist/types/utils/sql-expr-monaco/sql-expr-validation.d.ts +41 -0
  191. package/dist/types/utils/sql-expr-monaco/sql-expr-worker-manager.d.ts +17 -0
  192. package/dist/types/utils/sql-expr-monaco/sql-expr.worker.d.ts +24 -0
  193. package/dist/types/utils/sql-expr-monaco/sql-expression-profile-strategy.d.ts +13 -0
  194. package/dist/types/utils/sql-expr-monaco/types.d.ts +89 -0
  195. package/package.json +27 -21
  196. package/dist/arcgis-coding-components/p-0c6de9b3.js +0 -6
  197. package/dist/arcgis-coding-components/p-81c37dab.entry.js +0 -6
  198. package/dist/cjs/arcade-mode-b85ae7d4.js +0 -595
  199. package/dist/components/chunk-IHYYRFLQ.js +0 -1363
  200. package/dist/types/components/arcade-editor/t9n-types.d.ts +0 -8
  201. package/dist/types/components/arcade-results/t9n-types.d.ts +0 -13
  202. package/dist/types/components/arcade-suggestions/t9n-types.d.ts +0 -6
  203. package/dist/types/components/arcade-variables/t9n-types.d.ts +0 -8
  204. package/dist/types/components/language-api-panel/t9n-types.d.ts +0 -8
  205. package/dist/types/utils/profile/predefined-profile.d.ts +0 -2
@@ -0,0 +1,1309 @@
1
+ /*!
2
+ * All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
+ * See https://js.arcgis.com/4.31/esri/copyright.txt for details.
4
+ * v4.31.0-next.21
5
+ */
6
+ import { n as newLayersFeatureLayer, i as importRequest, s as supportedFields, a as newPortalPortalItem, b as newWebScene, c as newWebMap, f as fieldAlias, d as fieldTypeToIconName, e as fieldTypeToApiValueVarType } from './fields.js';
7
+ import { p as portalItemPageUrl } from './utilities.js';
8
+ import { i as isNotNull, a as isNotUndefined, b as addLTRMark, c as setValuesInString } from './index2.js';
9
+ import { InsertTextMode, InsertTextFormat, CompletionItemKind } from 'vscode-languageserver-types';
10
+ import { Emitter, Uri } from 'monaco-editor';
11
+
12
+ //#region Type Guards
13
+ function isFeatureLayerLikeInstance(item) {
14
+ return (!!item &&
15
+ typeof item === "object" &&
16
+ "declaredClass" in item &&
17
+ typeof item.declaredClass === "string" &&
18
+ item.declaredClass.startsWith("esri.layers.") &&
19
+ isFieldsDefinition(item) &&
20
+ "queryFeatures" in item &&
21
+ typeof item.queryFeatures === "function");
22
+ }
23
+ function isGroupLayerCapable(item) {
24
+ return (!!item &&
25
+ typeof item === "object" &&
26
+ "allLayers" in item &&
27
+ "allTables" in item &&
28
+ typeof item.allLayers === "object" &&
29
+ typeof item.allTables === "object");
30
+ }
31
+ function isMapInstance(item) {
32
+ return (!!item &&
33
+ typeof item === "object" &&
34
+ "declaredClass" in item &&
35
+ typeof item.declaredClass === "string" &&
36
+ (item.declaredClass === "esri.Map" ||
37
+ item.declaredClass === "esri.WebMap" ||
38
+ item.declaredClass === "esri.WebScene"));
39
+ }
40
+ function isLoadAllCapable(item) {
41
+ return !!item && typeof item === "object" && "loadAll" in item && typeof item.loadAll === "function";
42
+ }
43
+ function isPortalItemDefinition(item) {
44
+ return !!item && typeof item === "object" && "portalItem" in item && item.portalItem != null;
45
+ }
46
+ function isFeatureLayerItemDefinition(item) {
47
+ return !!item && typeof item === "object" && "portalItem" in item && item.portalItem != null;
48
+ }
49
+ function isFieldsDefinition(item) {
50
+ return !!item && typeof item === "object" && "fields" in item && Array.isArray(item.fields);
51
+ }
52
+ function isUrlDefinition(item) {
53
+ return !!item && typeof item === "object" && "url" in item && typeof item.url === "string";
54
+ }
55
+ function isSupportedServiceUrlDefinition(item) {
56
+ return isUrlDefinition(item) && /\/(?:featureserver|mapserver)(?:\/|$)/iu.test(item.url);
57
+ }
58
+ function isFeatureDefinition(item) {
59
+ return isUrlDefinition(item) || isFieldsDefinition(item) || isFeatureLayerItemDefinition(item);
60
+ }
61
+ function isFeatureSetDefinition(item) {
62
+ return isUrlDefinition(item) || isFieldsDefinition(item) || isFeatureLayerItemDefinition(item);
63
+ }
64
+ function isFeatureSetCollectionDefinition(item) {
65
+ return isPortalItemDefinition(item) || isMapInstance(item) || isSupportedServiceUrlDefinition(item);
66
+ }
67
+ function isSubtypeInstance(item) {
68
+ return (!!item &&
69
+ typeof item === "object" &&
70
+ "declaredClass" in item &&
71
+ item.declaredClass === "esri.layers.support.Subtype");
72
+ }
73
+ function isCodedValueDomainInstance(item) {
74
+ return (!!item &&
75
+ typeof item === "object" &&
76
+ "declaredClass" in item &&
77
+ item.declaredClass === "esri.layers.support.CodedValueDomain");
78
+ }
79
+ function isInheritedDomainInstance(item) {
80
+ return (!!item &&
81
+ typeof item === "object" &&
82
+ "declaredClass" in item &&
83
+ item.declaredClass === "esri.layers.support.InheritedDomain");
84
+ }
85
+ function isPredefinedProfile(item) {
86
+ return (!!item &&
87
+ typeof item === "object" &&
88
+ "id" in item &&
89
+ typeof item.id === "string" &&
90
+ "definitions" in item &&
91
+ typeof item.definitions === "object" &&
92
+ !Array.isArray(item.definitions));
93
+ }
94
+ function isTitleCapableSource(item) {
95
+ return !!item && typeof item === "object" && "title" in item && typeof item.title === "string";
96
+ }
97
+ function isUrlCapableSource(item) {
98
+ return !!item && typeof item === "object" && "url" in item && typeof item.url === "string";
99
+ }
100
+ function isLayerIdCapableSource(item) {
101
+ return !!item && typeof item === "object" && "layerId" in item && typeof item.layerId === "number";
102
+ }
103
+ function isFeatureTypesCapableLayer(item) {
104
+ return !!item && typeof item === "object" && "typeIdField" in item && "types" in item;
105
+ }
106
+ function isDomainsCapableLayer(item) {
107
+ return !!item && typeof item === "object" && "getFieldDomain" in item && typeof item.getFieldDomain === "function";
108
+ }
109
+ function isSubtypeFieldCapableLayer(item) {
110
+ return !!item && typeof item === "object" && "subtypeField" in item;
111
+ }
112
+ function isSubtypesCapableLayer(item) {
113
+ return isSubtypeFieldCapableLayer(item) && "subtypes" in item;
114
+ }
115
+ function isPortalItemCapable(item) {
116
+ return !!item && typeof item === "object" && "portalItem" in item;
117
+ }
118
+ function isRelationshipsCapableLayer(item) {
119
+ return (isLayerIdCapableSource(item) &&
120
+ "relationships" in item &&
121
+ "url" in item &&
122
+ Array.isArray(item.relationships) &&
123
+ typeof item.url === "string");
124
+ }
125
+ function isTableCapableLayer(item) {
126
+ return !!item && typeof item === "object" && "isTable" in item && typeof item.isTable === "boolean";
127
+ }
128
+ function isLoadableSource(item) {
129
+ return !!item && typeof item === "object" && "load" in item && typeof item.load === "function";
130
+ }
131
+ //#endregion
132
+ //#region Service Metadata
133
+ async function supportedSourceFromDefinition(definition) {
134
+ if (!definition) {
135
+ return null;
136
+ }
137
+ let source = null;
138
+ if (isFieldsDefinition(definition)) {
139
+ source = definition;
140
+ }
141
+ else {
142
+ source = await newLayersFeatureLayer(definition);
143
+ }
144
+ if (isLoadableSource(source)) {
145
+ await source.load();
146
+ }
147
+ return source;
148
+ }
149
+ async function serviceMetaData(url) {
150
+ url += "/layers";
151
+ const request = await importRequest();
152
+ const response = await request(url, { responseType: "json", query: { f: "json" } });
153
+ const queryCapability = url.endsWith("MapServer/layers") ? "data" : "query";
154
+ const layers = getSupportedLayerInfos(response.data?.layers, queryCapability);
155
+ const tables = getSupportedLayerInfos(response.data?.tables, queryCapability);
156
+ return { layers, tables };
157
+ }
158
+ function getSupportedLayerInfos(layers, queryCapability) {
159
+ if (!layers) {
160
+ return [];
161
+ }
162
+ return layers.filter((layer) => {
163
+ switch (layer.type) {
164
+ case "Feature Layer":
165
+ case "Oriented Imagery Layer":
166
+ case "Catalog Layer":
167
+ case "Table": {
168
+ const capabilities = layer.capabilities
169
+ ? layer.capabilities
170
+ .toLowerCase()
171
+ .split(",")
172
+ .map((value) => value.trim())
173
+ : [];
174
+ return capabilities.includes(queryCapability);
175
+ }
176
+ default:
177
+ return false;
178
+ }
179
+ });
180
+ }
181
+ //#endregion
182
+
183
+ //#endregion
184
+ //#region Support functions
185
+ async function getRelatedFeatureLayer(layer, relationship) {
186
+ const relatedFeatureLayer = await newLayersFeatureLayer({ url: `${layer.url}/${relationship.relatedTableId}` });
187
+ await relatedFeatureLayer.load();
188
+ return relatedFeatureLayer;
189
+ }
190
+ function sortFields(layer) {
191
+ return (firstField, secondField) => {
192
+ if (firstField.type === "oid") {
193
+ return -1;
194
+ }
195
+ if (secondField.type === "oid") {
196
+ return 1;
197
+ }
198
+ if (isSubtypeFieldCapableLayer(layer)) {
199
+ if (firstField.name === layer.subtypeField) {
200
+ return -1;
201
+ }
202
+ if (secondField.name === layer.subtypeField) {
203
+ return 1;
204
+ }
205
+ }
206
+ if (isFeatureTypesCapableLayer(layer)) {
207
+ if (firstField.name === layer.typeIdField) {
208
+ return -1;
209
+ }
210
+ if (secondField.name === layer.typeIdField) {
211
+ return 1;
212
+ }
213
+ }
214
+ return firstField.name.localeCompare(secondField.name, "en", { sensitivity: "base" });
215
+ };
216
+ }
217
+ function areAllDomainsInherited(types, field) {
218
+ return types?.every((type) => type.domains?.[field.name]?.type === "inherited") ?? false;
219
+ }
220
+ // const validIdentifierExpr = new RegExp(/^[a-z_$][\w$]*$/gi);
221
+ const validIdentifierExpr = /^[a-z_$][a-z0-9_$]*$/giu;
222
+ function getMemberExpressionProperty(prop, includeDot = true) {
223
+ if (prop.match(validIdentifierExpr)) {
224
+ return `${includeDot ? "." : ""}${prop}`;
225
+ }
226
+ return `["${prop}"]`;
227
+ }
228
+ function assembleMemberExpression(obj, prop) {
229
+ if (!obj) {
230
+ return prop;
231
+ }
232
+ return `${obj}${getMemberExpressionProperty(prop)}`;
233
+ }
234
+ function getMapPortalItem(map) {
235
+ if (isPortalItemCapable(map)) {
236
+ return map.portalItem;
237
+ }
238
+ return null;
239
+ }
240
+ /**
241
+ * converts fields to profile values and calculates the feature completion description all in one iteration
242
+ */
243
+ function fieldsToProfileValues(fields, initialFeatureCompletionDescription, includeAliases = false) {
244
+ let featureCompletionDescription = initialFeatureCompletionDescription;
245
+ const fieldProfileValues = [];
246
+ const aliasProfileValues = [];
247
+ supportedFields(fields).forEach((field) => {
248
+ if (featureCompletionDescription) {
249
+ featureCompletionDescription += " \n \n";
250
+ }
251
+ featureCompletionDescription += `**${field.name}** (${field.alias}) \n${field.type}`;
252
+ if (field.description) {
253
+ featureCompletionDescription += ` \n'${field.description}`;
254
+ }
255
+ // The property for the field
256
+ const type = fieldTypeToApiValueVarType(field);
257
+ const insertText = getMemberExpressionProperty(field.name, false);
258
+ const description = fieldAlias(field);
259
+ fieldProfileValues.push({
260
+ name: field.name,
261
+ description,
262
+ type,
263
+ completion: {
264
+ label: field.name,
265
+ detail: description,
266
+ insertText,
267
+ insertTextMode: InsertTextMode.asIs,
268
+ insertTextFormat: InsertTextFormat.PlainText,
269
+ kind: CompletionItemKind.Field,
270
+ },
271
+ });
272
+ if (includeAliases) {
273
+ if (!field.alias || field.alias.toLowerCase() === field.name.toLowerCase()) {
274
+ return;
275
+ }
276
+ // The property for the alias if different than the field name
277
+ let aliasCompletionDescription = `**${field.alias}** \n${field.type}`;
278
+ if (field.description) {
279
+ aliasCompletionDescription += ` \n'${field.description}`;
280
+ }
281
+ aliasProfileValues.push({
282
+ name: field.alias,
283
+ description: field.name,
284
+ type,
285
+ completion: {
286
+ label: field.alias,
287
+ detail: field.name,
288
+ insertText,
289
+ insertTextMode: InsertTextMode.asIs,
290
+ insertTextFormat: InsertTextFormat.PlainText,
291
+ kind: CompletionItemKind.Field,
292
+ documentation: { kind: "markdown", value: aliasCompletionDescription },
293
+ },
294
+ });
295
+ }
296
+ });
297
+ const properties = [...fieldProfileValues, ...aliasProfileValues];
298
+ return [properties, featureCompletionDescription];
299
+ }
300
+ /**
301
+ * Represents a item in the EditorProfile. The profile is converted into an optimized way for
302
+ * rendering in the editor. In addition to the representation of profile variables, other
303
+ * structures are created such as groups.
304
+ */
305
+ class ProfileItemBase {
306
+ constructor(_profile, _label, description) {
307
+ this._profile = _profile;
308
+ this._label = _label;
309
+ this.description = description;
310
+ this.filterDescription = false;
311
+ }
312
+ /**
313
+ * Returns the label string.
314
+ */
315
+ getLabel() {
316
+ if (this._label == null) {
317
+ return "";
318
+ }
319
+ if (typeof this._label === "string") {
320
+ // Some of our variables can start with a $ sign.
321
+ // If the component is under RTL, the string is messed up.
322
+ // It is converted from $feature to feature$, This is not acceptable since the label
323
+ // represents a variable name. We are adding in front of the $ sign a right to left mark.
324
+ return addLTRMark(this._label);
325
+ }
326
+ return setValuesInString(this._profile?.intlStrings[this._label.code], this._label.formatValues);
327
+ }
328
+ /**
329
+ * Returns the description string.
330
+ */
331
+ getDescription() {
332
+ if (this.description == null) {
333
+ return "";
334
+ }
335
+ if (typeof this.description === "string") {
336
+ return this.description;
337
+ }
338
+ return setValuesInString(this._profile?.intlStrings[this.description.code], this.description.formatValues);
339
+ }
340
+ /**
341
+ * Returns true if the item pass the filter test
342
+ */
343
+ passFilter(filterExpression) {
344
+ if (!filterExpression) {
345
+ return true;
346
+ }
347
+ if (filterExpression.test(this.getLabel())) {
348
+ return true;
349
+ }
350
+ return this.filterDescription && filterExpression.test(this.getDescription());
351
+ }
352
+ }
353
+ /**
354
+ * The base class for profile variables representation in the EditorProfile.
355
+ */
356
+ class VariableBase extends ProfileItemBase {
357
+ constructor(props) {
358
+ super(props.profile, props.label, props.description ?? props.declaration?.description);
359
+ this.declaration = props.declaration ?? {};
360
+ this.name = props.declaration?.name ?? "";
361
+ this.snippet = props.snippet ?? "";
362
+ this.nonInteractive = props.nonInteractive ?? false;
363
+ this.filterDescription = props.filterDescription ?? false;
364
+ this.icon = props.icon;
365
+ }
366
+ }
367
+ /**
368
+ * Represents the IProfileValue.
369
+ */
370
+ class ValueVariable extends VariableBase {
371
+ constructor(props) {
372
+ super(props);
373
+ this.type = "text";
374
+ this.isCollection = false;
375
+ this.type = props.declaration?.type ?? "text";
376
+ }
377
+ getDescription() {
378
+ if (this.description == null) {
379
+ return this._profile?.intlStrings[this.type.toLowerCase()] ?? "";
380
+ }
381
+ return super.getDescription();
382
+ }
383
+ toProfileVariableDefinition() {
384
+ return { type: this.type, name: "", ...this.declaration };
385
+ }
386
+ }
387
+ /**
388
+ * Represents the IProfileArray. The main difference is that the IProfileValue type
389
+ * is used as valueType.
390
+ */
391
+ class ArrayVariable extends VariableBase {
392
+ constructor(props) {
393
+ super(props);
394
+ this.type = "array";
395
+ this.isCollection = false;
396
+ this.elementType = props.declaration?.elementType ?? { type: "number", name: "number" };
397
+ }
398
+ getDescription() {
399
+ if (this.description == null) {
400
+ return this._profile?.intlStrings[this.type.toLowerCase()] ?? "";
401
+ }
402
+ return super.getDescription();
403
+ }
404
+ toProfileVariableDefinition() {
405
+ return { type: this.type, elementType: this.elementType, name: "", ...this.declaration };
406
+ }
407
+ }
408
+ /**
409
+ * Represents a collection of items. The collection of items can be synchronous or
410
+ * asynchronous. If the collection is asynchronous then the collection should be
411
+ * loaded by using the function 'load'. The property 'loaded' indicates if the
412
+ * collection is ready or not.
413
+ */
414
+ class CollectionBasedVariable extends VariableBase {
415
+ constructor(owner, props) {
416
+ super(props);
417
+ this.owner = owner;
418
+ this.isCollection = true;
419
+ this._loaded = true;
420
+ /**
421
+ * The collection of items used to display the profile.
422
+ * If the collection is asynchronous, the 'load' function should
423
+ * be called first before using the items.
424
+ */
425
+ this.variables = [];
426
+ }
427
+ get breadcrumb() {
428
+ // If there's an owner, prepend its breadcrumb and append the current name
429
+ if (this.owner) {
430
+ const ownerBreadcrumb = this.owner.breadcrumb;
431
+ return ownerBreadcrumb ? `${ownerBreadcrumb} / ${this.name}` : this.name;
432
+ }
433
+ // If there's no owner, this is the root element, so just return its name
434
+ return this.name;
435
+ }
436
+ /**
437
+ * Returns true if the collection has been loaded
438
+ */
439
+ get loaded() {
440
+ return this._loaded;
441
+ }
442
+ /**
443
+ * Returns an url to the associated information
444
+ */
445
+ get informationUrl() {
446
+ return null;
447
+ }
448
+ get informationType() {
449
+ return "";
450
+ }
451
+ }
452
+ class GroupOfVariables extends ProfileItemBase {
453
+ constructor(profile, label, variables = []) {
454
+ super(profile, label);
455
+ this.variables = variables;
456
+ this.type = "group";
457
+ this.isCollection = true;
458
+ }
459
+ passFilter() {
460
+ return true;
461
+ }
462
+ }
463
+ class DictionaryVariable extends CollectionBasedVariable {
464
+ constructor(owner, props) {
465
+ super(owner, props);
466
+ this.type = "dictionary";
467
+ /**
468
+ * The variables that the dictionary holds. It is different than the variables.
469
+ * The variables may contain grouping.
470
+ */
471
+ this.dictionaryVariables = [];
472
+ this.loadPropertyDeclarations(props.declaration?.properties);
473
+ // If we have a snippet then wrap the properties in a group and use the snippet as the heading
474
+ // This is not applicable for root Dictionary such as Profile
475
+ if (this.snippet && this.dictionaryVariables.length) {
476
+ this.variables = [new GroupOfVariables(this._profile, this.snippet, this.dictionaryVariables)];
477
+ }
478
+ }
479
+ async loadSource() {
480
+ // No-op
481
+ }
482
+ loadPropertyDeclarations(declarations) {
483
+ this.dictionaryVariables = this.createVariableInstances(declarations);
484
+ this.variables = this.dictionaryVariables;
485
+ }
486
+ createVariableInstances(declarations) {
487
+ if (!Array.isArray(declarations)) {
488
+ return [];
489
+ }
490
+ const properties = [];
491
+ declarations.forEach((declaration) => {
492
+ const variable = this.createVariableInstance(declaration);
493
+ if (variable) {
494
+ properties.push(variable);
495
+ }
496
+ });
497
+ return properties;
498
+ }
499
+ createVariableInstance(declaration) {
500
+ const snippet = assembleMemberExpression(this.snippet, declaration.name);
501
+ switch (declaration.type) {
502
+ case "number":
503
+ case "text":
504
+ case "boolean":
505
+ case "date":
506
+ case "dateOnly":
507
+ case "time":
508
+ case "geometry":
509
+ case "knowledgeGraph":
510
+ return new ValueVariable({ profile: this._profile, declaration, label: snippet, snippet });
511
+ case "feature":
512
+ return new FeatureVariable(this, { profile: this._profile, declaration, label: snippet, snippet });
513
+ case "featureSet":
514
+ return new FeatureSetVariable(this, { profile: this._profile, declaration, label: snippet, snippet }, [
515
+ new ValueVariable({ profile: this._profile, label: snippet, description: "", snippet }),
516
+ ]);
517
+ case "featureSetCollection":
518
+ return new FeatureSetCollectionVariable(this, {
519
+ profile: this._profile,
520
+ declaration,
521
+ label: snippet,
522
+ snippet,
523
+ });
524
+ case "dictionary":
525
+ return new DictionaryVariable(this, {
526
+ profile: this._profile,
527
+ declaration,
528
+ label: snippet,
529
+ snippet,
530
+ });
531
+ case "array":
532
+ return new ArrayVariable({
533
+ profile: this._profile,
534
+ declaration,
535
+ label: snippet,
536
+ snippet,
537
+ });
538
+ default:
539
+ console.error("Editor profile: Invalid profile variable", declaration);
540
+ return null;
541
+ }
542
+ }
543
+ toProfileVariableDefinition() {
544
+ return {
545
+ type: this.type,
546
+ name: "",
547
+ ...this.declaration,
548
+ properties: this.dictionaryVariables.map((variable) => variable.toProfileVariableDefinition()),
549
+ };
550
+ }
551
+ }
552
+ class SourceBasedVariable extends CollectionBasedVariable {
553
+ constructor(owner, props, relationshipsProperties) {
554
+ super(owner, props);
555
+ this.relationshipsProperties = relationshipsProperties;
556
+ this._source = null;
557
+ this._loaded = false;
558
+ this._definition = props.declaration?.definition;
559
+ }
560
+ get title() {
561
+ return isTitleCapableSource(this._source) ? this._source.title : "";
562
+ }
563
+ get url() {
564
+ return isUrlCapableSource(this._source) ? this._source.url : "";
565
+ }
566
+ get informationUrl() {
567
+ if (!this.loaded) {
568
+ return null;
569
+ }
570
+ if (!this.url) {
571
+ return null;
572
+ }
573
+ return isLayerIdCapableSource(this._source) ? `${this.url}/${this._source.layerId}` : this.url;
574
+ }
575
+ get informationType() {
576
+ return this._profile?.intlStrings.layer ?? "layer";
577
+ }
578
+ async loadSource() {
579
+ if (isNotNull(this._loadPromise) && isNotUndefined(this._loadPromise)) {
580
+ return await this._loadPromise;
581
+ }
582
+ this._loadPromise = this._loadSource();
583
+ return await this._loadPromise;
584
+ }
585
+ _getValueSnippet(field) {
586
+ // If the source is a feature, then we want to assemble the snippet ($feature) with the field name as a member expression
587
+ return this.type === "feature" ? assembleMemberExpression(this.snippet, field.name) : field.name;
588
+ }
589
+ _getSubtypeOrDomainNameSnippet(field) {
590
+ if (this.type !== "feature") {
591
+ return null;
592
+ }
593
+ if (isSubtypeFieldCapableLayer(this._source) && field.name === this._source.subtypeField) {
594
+ return `SubtypeName(${this.snippet})`;
595
+ }
596
+ return `DomainName(${this.snippet}, "${field.name}")`;
597
+ }
598
+ _getFieldProperty(field) {
599
+ // Check if the field is the type id field or of the field has a coded domain.
600
+ // If it has then the property will be an exanpdable property (dictionary).
601
+ // Otherwise just return a simple value property.
602
+ const subtypesOrDomainValuesDictionary = this._getDomainDictionary(field);
603
+ if (subtypesOrDomainValuesDictionary) {
604
+ return subtypesOrDomainValuesDictionary;
605
+ }
606
+ // Create the value property
607
+ const valueSnippet = this._getValueSnippet(field);
608
+ return new ValueVariable({
609
+ profile: this._profile,
610
+ label: valueSnippet,
611
+ description: fieldAlias(field),
612
+ snippet: valueSnippet,
613
+ icon: fieldTypeToIconName(field),
614
+ filterDescription: true,
615
+ });
616
+ }
617
+ _getDomainDictionary(field) {
618
+ if (!isDomainsCapableLayer(this._source)) {
619
+ return null;
620
+ }
621
+ // Note we have multiple scenarios:
622
+ // - Layers without subtypes or feature types: We will check if the field has a domain
623
+ // - Layers with only subtypes: We will parse the subtypes metadata and create a dictionary
624
+ // - Layers with only feature types: We will parse the feature types metadata
625
+ // - Layers with both subtypes and feature types: we will actually use the subtypes metadata
626
+ // Summary, we will always use the subtypes metadata if available.
627
+ if (isSubtypeFieldCapableLayer(this._source) && !!this._source.subtypeField) {
628
+ return this._getSubtypeDomainDictionary(field);
629
+ }
630
+ if (isFeatureTypesCapableLayer(this._source) && !!this._source.typeIdField) {
631
+ return this._getFeatureTypeDomainDictionary(field);
632
+ }
633
+ return this._getFieldDomainDictionary(field);
634
+ }
635
+ _getSubtypeDomainDictionary(field) {
636
+ // Should be tested before calling this function
637
+ if (!isSubtypeFieldCapableLayer(this._source)) {
638
+ return null;
639
+ }
640
+ // If the source has a subtype field but doesn't have subtypes, it is certainly a subtype sublayer
641
+ if (!isSubtypesCapableLayer(this._source)) {
642
+ // For the subtype field there is no domain
643
+ if (field.name === this._source.subtypeField) {
644
+ return null;
645
+ }
646
+ // For the other fields, we will use the getFieldDomain function
647
+ return this._getFieldDomainDictionary(field);
648
+ }
649
+ // The code here shoud be executed for layers that have subtypes
650
+ // Sepcial case for the subtype field
651
+ if (field.name === this._source.subtypeField) {
652
+ const domainDictionary = this._createDomainDictionary(field);
653
+ domainDictionary.icon = "subtype";
654
+ domainDictionary.variables.push(this._getTypeOrSubtypeDomainGroup(this._source.subtypes, field));
655
+ return domainDictionary;
656
+ }
657
+ // Check if all the domains for the field in the types are inherited.
658
+ // If it is we can simplify the structure by avoiding splitting in subtypes
659
+ if (areAllDomainsInherited(this._source.subtypes, field)) {
660
+ return this._getFieldDomainDictionary(field);
661
+ }
662
+ // We have domains per subtype
663
+ // We need to go thru each types and create a dictionary.
664
+ const domainValuesBySubtypeGroup = this._getDomainValuesGroup(this._source.subtypes, field);
665
+ if (!domainValuesBySubtypeGroup) {
666
+ return null;
667
+ }
668
+ const domainDictionary = this._createDomainDictionary(field);
669
+ domainDictionary.variables.push(domainValuesBySubtypeGroup);
670
+ return domainDictionary;
671
+ }
672
+ _getFeatureTypeDomainDictionary(field) {
673
+ // SHould be tested before calling this function
674
+ if (!isFeatureTypesCapableLayer(this._source)) {
675
+ return null;
676
+ }
677
+ // Special case for the type id field
678
+ if (field.name === this._source.typeIdField) {
679
+ const domainDictionary = this._createDomainDictionary(field);
680
+ domainDictionary.variables.push(this._getTypeOrSubtypeDomainGroup(this._source.types, field));
681
+ return domainDictionary;
682
+ }
683
+ // Check if all the domains for the field in the types are inherited.
684
+ // If it is we can simplify the structure by avoiding splitting in subtypes
685
+ if (areAllDomainsInherited(this._source.types, field)) {
686
+ return this._getFieldDomainDictionary(field);
687
+ }
688
+ // We have domains per feature type
689
+ // We need to go thru each types and create a dictionary.
690
+ const domainValuesByFeatureTypeGroup = this._getDomainValuesGroup(this._source.types, field);
691
+ if (!domainValuesByFeatureTypeGroup) {
692
+ return null;
693
+ }
694
+ const domainDictionary = this._createDomainDictionary(field);
695
+ domainDictionary.variables.push(domainValuesByFeatureTypeGroup);
696
+ return domainDictionary;
697
+ }
698
+ _getFieldDomainDictionary(field) {
699
+ // SHould be tested before calling this function
700
+ if (!isDomainsCapableLayer(this._source)) {
701
+ return null;
702
+ }
703
+ const fieldDomain = this._source.getFieldDomain(field.name);
704
+ if (!isCodedValueDomainInstance(fieldDomain)) {
705
+ return null;
706
+ }
707
+ const domainValuesGroup = this._getCodedValueDomainGroup(fieldDomain, {
708
+ code: "domainvalues",
709
+ });
710
+ const domainDictionary = this._createDomainDictionary(field);
711
+ domainDictionary.variables.push(domainValuesGroup);
712
+ return domainDictionary;
713
+ }
714
+ _getTypeOrSubtypeDomainGroup(types, field) {
715
+ // Try the coded domain first
716
+ if (isCodedValueDomainInstance(field.domain)) {
717
+ return this._getCodedValueDomainGroup(field.domain, { code: "subtypes" });
718
+ }
719
+ // No coded domain, we will manufacture it
720
+ const values = types?.map((t) => {
721
+ const label = isSubtypeInstance(t) ? t.code : t.id;
722
+ return new ValueVariable({
723
+ profile: this._profile,
724
+ label: `${label}`,
725
+ description: t.name,
726
+ snippet: `"${label}"`,
727
+ });
728
+ }) ?? [];
729
+ return new GroupOfVariables(this._profile, { code: "subtypes" }, values);
730
+ }
731
+ _getCodedValueDomainGroup(domain, label) {
732
+ const values = domain.codedValues.map((v) => new ValueVariable({
733
+ profile: this._profile,
734
+ label: `${v.code}`,
735
+ description: v.name,
736
+ snippet: `"${v.code}"`,
737
+ filterDescription: true,
738
+ }));
739
+ return new GroupOfVariables(this._profile, label, values);
740
+ }
741
+ _getDomainValuesGroup(types, field) {
742
+ const variables = [];
743
+ if (!types || types.length === 0) {
744
+ return null;
745
+ }
746
+ types.forEach((type) => {
747
+ let domain = type.domains?.[field.name];
748
+ if (!domain) {
749
+ return;
750
+ }
751
+ if (isInheritedDomainInstance(domain)) {
752
+ domain = field.domain;
753
+ return;
754
+ }
755
+ if (!isCodedValueDomainInstance(domain)) {
756
+ return;
757
+ }
758
+ const alias = fieldAlias(field);
759
+ const domainValuesGroup = this._getCodedValueDomainGroup(domain, {
760
+ code: "domainvaluesfortypeformat",
761
+ formatValues: {
762
+ fieldName: alias,
763
+ typeName: type.name,
764
+ },
765
+ });
766
+ const id = isSubtypeInstance(type) ? type.code : type.id;
767
+ const label = `${id}`;
768
+ const snippet = `"${id}""`;
769
+ const subtypeDictionary = new DictionaryVariable(this, {
770
+ profile: this._profile,
771
+ label,
772
+ snippet,
773
+ description: type.name,
774
+ declaration: { name: alias },
775
+ });
776
+ subtypeDictionary.variables = [domainValuesGroup];
777
+ variables.push(subtypeDictionary);
778
+ });
779
+ if (!variables.length) {
780
+ return null;
781
+ }
782
+ return new GroupOfVariables(this._profile, { code: "domainvaluesbysubtypes" }, variables);
783
+ }
784
+ _createDomainDictionary(field) {
785
+ // Create the domain dictionary.
786
+ // The dictionary will have a header group and a value group.
787
+ // At this point we are only creating the header group in the dictionary.
788
+ const valueSnippet = this._getValueSnippet(field);
789
+ const alias = fieldAlias(field);
790
+ const domainDictionary = new DictionaryVariable(this, {
791
+ profile: this._profile,
792
+ label: valueSnippet,
793
+ description: alias,
794
+ snippet: valueSnippet,
795
+ icon: "form-dropdown",
796
+ declaration: { name: field.name },
797
+ });
798
+ // Add the header group
799
+ const headerGroup = new GroupOfVariables(this._profile, alias, [
800
+ new ValueVariable({
801
+ profile: this._profile,
802
+ label: valueSnippet,
803
+ description: "",
804
+ snippet: valueSnippet,
805
+ }),
806
+ ]);
807
+ domainDictionary.variables = [headerGroup];
808
+ // Add the SubtypeName or DomainName snippet if available
809
+ const subtypeOrDomainNameSnippet = this._getSubtypeOrDomainNameSnippet(field);
810
+ if (subtypeOrDomainNameSnippet) {
811
+ headerGroup.variables.push(new ValueVariable({
812
+ profile: this._profile,
813
+ label: subtypeOrDomainNameSnippet,
814
+ description: "",
815
+ snippet: subtypeOrDomainNameSnippet,
816
+ }));
817
+ }
818
+ return domainDictionary;
819
+ }
820
+ async _getRelationshipsProperty() {
821
+ // We need the data store to find the relationship feature layers
822
+ if (!this.relationshipsProperties?.exposeRelationships || !this._profile?.supportFeatureSetFunctions) {
823
+ return null;
824
+ }
825
+ const source = this._source;
826
+ if (!isRelationshipsCapableLayer(source)) {
827
+ return null;
828
+ }
829
+ const relationshipsGroup = new GroupOfVariables(this._profile, { code: "relationships" });
830
+ const relationshipItems = await Promise.all(source.relationships.map(async (relationship) => {
831
+ const relatedLayer = await getRelatedFeatureLayer(source, relationship);
832
+ if (!isFeatureLayerLikeInstance(relatedLayer)) {
833
+ return null;
834
+ }
835
+ if (relationship.relatedTableId === this.relationshipsProperties?.sourceTableId) {
836
+ // We don't want to show the reverse relationship
837
+ return null;
838
+ }
839
+ const snippet = `FeatureSetByRelationshipName(${this.snippet}, "${relationship.name}")`;
840
+ return new FeatureSetVariable(this, {
841
+ profile: this._profile,
842
+ declaration: { definition: relatedLayer },
843
+ label: relatedLayer.title,
844
+ description: "",
845
+ nonInteractive: true,
846
+ }, [new ValueVariable({ profile: this._profile, label: snippet, description: "", snippet })], { exposeRelationships: true, sourceTableId: source.layerId });
847
+ }));
848
+ relationshipsGroup.variables = relationshipItems.filter(isNotNull);
849
+ if (!relationshipsGroup.variables.length) {
850
+ return null;
851
+ }
852
+ return relationshipsGroup;
853
+ }
854
+ }
855
+ class FeatureVariable extends SourceBasedVariable {
856
+ constructor(owner, props) {
857
+ super(owner, props, { exposeRelationships: true });
858
+ this.type = "feature";
859
+ }
860
+ get title() {
861
+ if (isTitleCapableSource(this._source)) {
862
+ return this._source.title ?? "";
863
+ }
864
+ return { code: "feature" };
865
+ }
866
+ async _loadSource() {
867
+ if (this.loaded) {
868
+ return this._source;
869
+ }
870
+ try {
871
+ this._source = await supportedSourceFromDefinition(this._definition);
872
+ if (!this._source) {
873
+ throw new Error("Invalid definition");
874
+ }
875
+ // The title group and snippet
876
+ const title = isTitleCapableSource(this._source) ? this._source.title ?? "" : "";
877
+ this.variables.push(new GroupOfVariables(this._profile, title, [
878
+ new ValueVariable({
879
+ profile: this._profile,
880
+ label: this.snippet,
881
+ description: "",
882
+ snippet: this.snippet,
883
+ }),
884
+ ]));
885
+ // The collection of feature attribute values
886
+ const valuesGroup = new GroupOfVariables(this._profile, { code: "values" });
887
+ this.variables.push(valuesGroup);
888
+ // Add the geometry if it's a feature layer and not a table
889
+ if (isTableCapableLayer(this._source) && !this._source.isTable) {
890
+ const snippet = `Geometry(${this.snippet})`;
891
+ const geometryProperty = new ValueVariable({
892
+ profile: this._profile,
893
+ declaration: { name: snippet },
894
+ label: snippet,
895
+ description: "Geometry",
896
+ snippet,
897
+ icon: "shapes",
898
+ filterDescription: true,
899
+ });
900
+ valuesGroup.variables.push(geometryProperty);
901
+ }
902
+ this._source.fields.sort(sortFields(this._source)).forEach((field) => {
903
+ valuesGroup.variables.push(this._getFieldProperty(field));
904
+ });
905
+ // The relatonships
906
+ const relationshipsGroup = await this._getRelationshipsProperty();
907
+ if (relationshipsGroup) {
908
+ this.variables.push(relationshipsGroup);
909
+ }
910
+ }
911
+ catch (error) {
912
+ console.error("Error with definition", error, this._definition);
913
+ this._source = null;
914
+ }
915
+ finally {
916
+ this._loaded = true;
917
+ }
918
+ return this._source;
919
+ }
920
+ toProfileVariableDefinition() {
921
+ return { type: this.type, name: "", ...this.declaration, definition: this._definition };
922
+ }
923
+ }
924
+ class FeatureSetVariable extends SourceBasedVariable {
925
+ constructor(owner, props, featureSetSnippets = [],
926
+ // Relationships for feature set if only supported if the feature set is actually
927
+ // representing a relationsip feature layer for a feature source.
928
+ relationshipProps) {
929
+ super(owner, props, relationshipProps);
930
+ this.featureSetSnippets = featureSetSnippets;
931
+ this.type = "featureSet";
932
+ }
933
+ get title() {
934
+ if (isTitleCapableSource(this._source)) {
935
+ return this._source.title ?? "";
936
+ }
937
+ return { code: "featureset" };
938
+ }
939
+ async _loadSource() {
940
+ if (this.loaded) {
941
+ return this._source;
942
+ }
943
+ try {
944
+ this._source = await supportedSourceFromDefinition(this._definition);
945
+ if (!this._source) {
946
+ throw new Error("Invalid definition");
947
+ }
948
+ // The title group and snippet
949
+ this.variables.push(new GroupOfVariables(this._profile, this.title, this.featureSetSnippets));
950
+ // Add the fields
951
+ const fieldsGroup = new GroupOfVariables(this._profile, { code: "fields" });
952
+ this.variables.push(fieldsGroup);
953
+ fieldsGroup.variables = this._source.fields
954
+ .sort(sortFields(this._source))
955
+ .map((field) => this._getFieldProperty(field));
956
+ // Add the relationships if enabled
957
+ const relationshipsGroup = await this._getRelationshipsProperty();
958
+ if (relationshipsGroup) {
959
+ this.variables.push(relationshipsGroup);
960
+ }
961
+ }
962
+ catch (error) {
963
+ console.error("Error with definition", error, this._definition);
964
+ this._source = null;
965
+ }
966
+ finally {
967
+ this._loaded = true;
968
+ }
969
+ return this._source;
970
+ }
971
+ toProfileVariableDefinition() {
972
+ return { type: this.type, name: "", ...this.declaration, definition: this._definition };
973
+ }
974
+ }
975
+ class FeatureSetCollectionVariable extends CollectionBasedVariable {
976
+ constructor(owner, props) {
977
+ super(owner, props);
978
+ this.type = "featureSetCollection";
979
+ this._featureSetCollections = null;
980
+ this._loaded = false;
981
+ this._definition = props.declaration?.definition;
982
+ }
983
+ get informationUrl() {
984
+ if (!this.loaded || !this._featureSetCollections) {
985
+ return null;
986
+ }
987
+ if (typeof this._featureSetCollections.source !== "string") {
988
+ return portalItemPageUrl(getMapPortalItem(this._featureSetCollections.source));
989
+ }
990
+ // const firstLayer = this._featureSetCollection.layers[0] ?? this._featureSetCollection.tables[0];
991
+ // if (!firstLayer) {
992
+ return null;
993
+ // }
994
+ // return `${firstLayer.url}`;
995
+ }
996
+ get informationType() {
997
+ if (!this.loaded || !this._featureSetCollections) {
998
+ return "";
999
+ }
1000
+ if (typeof this._featureSetCollections.source === "string") {
1001
+ return this._profile?.intlStrings.featureservice ?? "featureservice";
1002
+ }
1003
+ switch (this._featureSetCollections.source.declaredClass) {
1004
+ case "esri.WebMap":
1005
+ return this._profile?.intlStrings.webmap ?? "webmap";
1006
+ case "esri.WebScene":
1007
+ return this._profile?.intlStrings.webscene ?? "webscene";
1008
+ default:
1009
+ return this._profile?.intlStrings.map ?? "map";
1010
+ }
1011
+ }
1012
+ async loadSource() {
1013
+ if (isNotNull(this._loadPromise) && isNotUndefined(this._loadPromise)) {
1014
+ return await this._loadPromise;
1015
+ }
1016
+ this._loadPromise = this._loadSource();
1017
+ return await this._loadPromise;
1018
+ }
1019
+ async _loadSource() {
1020
+ if (this.loaded) {
1021
+ return this._featureSetCollections;
1022
+ }
1023
+ try {
1024
+ this._featureSetCollections = await this._featureSetCollectionsFromDefinition();
1025
+ if (!this._featureSetCollections) {
1026
+ throw new Error("Invalid definition");
1027
+ }
1028
+ // Create the group for the header
1029
+ const groupLabel = typeof this._featureSetCollections.source === "string"
1030
+ ? { code: this._featureSetCollections.source.endsWith("FeatureServer") ? "featureservice" : "mapservice" }
1031
+ : {
1032
+ code: "webmapformat",
1033
+ formatValues: {
1034
+ webMapTitle: getMapPortalItem(this._featureSetCollections.source)?.title || "Untitled map",
1035
+ },
1036
+ };
1037
+ const headerGroup = new GroupOfVariables(this._profile, groupLabel, [
1038
+ new ValueVariable({
1039
+ profile: this._profile,
1040
+ label: this.snippet,
1041
+ description: "",
1042
+ snippet: this.snippet,
1043
+ }),
1044
+ ]);
1045
+ // Creates the groups for the layer and tables
1046
+ const layersGroup = new GroupOfVariables(this._profile, { code: "layers" }, this._featureSetCollections.layers);
1047
+ const tablesGroup = new GroupOfVariables(this._profile, { code: "tables" }, this._featureSetCollections.tables);
1048
+ this.variables.push(headerGroup, layersGroup, tablesGroup);
1049
+ }
1050
+ catch (error) {
1051
+ console.error("Error with definition", error, this._definition);
1052
+ this._featureSetCollections = null;
1053
+ }
1054
+ finally {
1055
+ this._loaded = true;
1056
+ }
1057
+ return this._featureSetCollections;
1058
+ }
1059
+ async _featureSetCollectionsFromDefinition() {
1060
+ if (!this._definition) {
1061
+ return null;
1062
+ }
1063
+ if (isMapInstance(this._definition)) {
1064
+ return await this._featureSetCollectionFromMap(this._definition);
1065
+ }
1066
+ if (isUrlDefinition(this._definition)) {
1067
+ return await this._featureSetCollectionFromUrl(this._definition.url);
1068
+ }
1069
+ if (isPortalItemDefinition(this._definition)) {
1070
+ // Preload the portal item so we can discover if are dealing with a Web Map
1071
+ // or Feature Service
1072
+ return await this._featureSetCollectionFromPortalItem(this._definition.portalItem);
1073
+ }
1074
+ return null;
1075
+ }
1076
+ async _featureSetCollectionFromMap(map) {
1077
+ if (isLoadAllCapable(map)) {
1078
+ // Make sure the map is loaded
1079
+ await map.loadAll();
1080
+ }
1081
+ // Until jsapi fix a bug we have to load the table separately
1082
+ await Promise.all(map.tables.map(async (t) => (await t.load())));
1083
+ return {
1084
+ layers: this._convertWebMapLayersToVariables(map.layers),
1085
+ tables: this._convertWebMapLayersToVariables(map.tables, true),
1086
+ source: map,
1087
+ };
1088
+ }
1089
+ async _featureSetCollectionFromPortalItem(definition) {
1090
+ const portalItem = await newPortalPortalItem(definition);
1091
+ await portalItem.load();
1092
+ switch (portalItem.type) {
1093
+ case "Web Map": {
1094
+ const webMap = await newWebMap({ portalItem });
1095
+ return await this._featureSetCollectionFromMap(webMap);
1096
+ }
1097
+ case "Web Scene": {
1098
+ const webScene = await newWebScene({ portalItem });
1099
+ return await this._featureSetCollectionFromMap(webScene);
1100
+ }
1101
+ case "Feature Service":
1102
+ return await this._featureSetCollectionFromUrl(portalItem.url);
1103
+ default:
1104
+ console.error("Unsupported portal item", definition);
1105
+ return null;
1106
+ }
1107
+ }
1108
+ async _featureSetCollectionFromUrl(url) {
1109
+ let processedUrl = url.replace(/\/featureserver\/[0-9]*/iu, "/FeatureServer");
1110
+ processedUrl = processedUrl.replace(/\/mapserver\/[0-9]*/iu, "/MapServer");
1111
+ processedUrl = processedUrl.split("?")[0];
1112
+ if (!processedUrl) {
1113
+ return null;
1114
+ }
1115
+ const metadata = await serviceMetaData(processedUrl);
1116
+ const layersPromise = Promise.all(metadata.layers.map(async (layerInfo) => {
1117
+ const featureLayer = await newLayersFeatureLayer({ url: `${processedUrl}/${layerInfo.id}` });
1118
+ await featureLayer.load();
1119
+ return this._createFeatureSetVariable(featureLayer);
1120
+ }));
1121
+ const tablesPromise = Promise.all(metadata.tables.map(async (layerInfo) => {
1122
+ const table = await newLayersFeatureLayer({ url: `${processedUrl}/${layerInfo.id}` });
1123
+ await table.load();
1124
+ return this._createFeatureSetVariable(table);
1125
+ }));
1126
+ const [layers, tables] = await Promise.all([layersPromise, tablesPromise]);
1127
+ return { layers, tables, source: processedUrl };
1128
+ }
1129
+ _convertWebMapLayersToVariables(layers, filteringTables = false) {
1130
+ const layerVariables = [];
1131
+ layers
1132
+ .toArray()
1133
+ .reverse()
1134
+ .forEach((layer) => {
1135
+ if (isFeatureLayerLikeInstance(layer)) {
1136
+ layerVariables.push(this._createFeatureSetVariable(layer, true));
1137
+ return;
1138
+ }
1139
+ if (isGroupLayerCapable(layer)) {
1140
+ const groupLayerVariables = filteringTables
1141
+ ? this._convertWebMapLayersToVariables(layer.allTables, true)
1142
+ : this._convertWebMapLayersToVariables(layer.allLayers);
1143
+ layerVariables.push(...groupLayerVariables);
1144
+ }
1145
+ });
1146
+ return layerVariables;
1147
+ }
1148
+ _createFeatureSetVariable(featureLayerLike, isFromWebMap = false) {
1149
+ return new FeatureSetVariable(this, {
1150
+ profile: this._profile,
1151
+ declaration: { name: featureLayerLike.title, definition: featureLayerLike },
1152
+ label: isFromWebMap
1153
+ ? featureLayerLike.title
1154
+ : featureLayerLike.sourceJSON.name ?? featureLayerLike.title,
1155
+ description: "",
1156
+ nonInteractive: true,
1157
+ }, this._makeFeatureSetSnippets(featureLayerLike, isFromWebMap));
1158
+ }
1159
+ _makeFeatureSetSnippets(featureLayerLike, isFromWebMap = false) {
1160
+ if (!this._profile?.supportFeatureSetFunctions) {
1161
+ return [];
1162
+ }
1163
+ if (isFromWebMap) {
1164
+ const snippetById = `FeatureSetById(${this.snippet}, "${featureLayerLike.id}")`;
1165
+ const snippetByName = `FeatureSetByName(${this.snippet}, "${featureLayerLike.title}")`;
1166
+ return [
1167
+ new ValueVariable({ profile: this._profile, label: snippetById, description: "", snippet: snippetById }),
1168
+ new ValueVariable({ profile: this._profile, label: snippetByName, description: "", snippet: snippetByName }),
1169
+ ];
1170
+ }
1171
+ else {
1172
+ const snippetById = `FeatureSetById(${this.snippet}, "${featureLayerLike.layerId}")`;
1173
+ return [new ValueVariable({ profile: this._profile, label: snippetById, description: "", snippet: snippetById })];
1174
+ }
1175
+ }
1176
+ toProfileVariableDefinition() {
1177
+ return { type: this.type, name: "", ...this.declaration, definition: this._definition };
1178
+ }
1179
+ }
1180
+ /**
1181
+ * The EditorProfile is an object that represents an Arcade Profile.
1182
+ * It is used to display the profile in the editor.
1183
+ * It takes an IEditorProfile as a definition and a locale.
1184
+ * A EditorPofile instance
1185
+ * Some of the variables in the profile are based on layers, web maps, or feature services.
1186
+ * They need to be loaded asynchronously to get the metadata necessary for validation and completion.
1187
+ */
1188
+ class EditorProfile extends DictionaryVariable {
1189
+ constructor(definition, intlStrings, locale = "en") {
1190
+ // Delay the load of the variable declarations so we have a `this`
1191
+ super(undefined, {
1192
+ profile: null,
1193
+ declaration: { properties: [] },
1194
+ });
1195
+ this.definition = definition;
1196
+ this.intlStrings = intlStrings;
1197
+ this.locale = locale;
1198
+ this.variables = [];
1199
+ // We are the root
1200
+ this._profile = this;
1201
+ // Now that `this` is defined, we can load the variables
1202
+ this.loadPropertyDeclarations(definition?.variables);
1203
+ }
1204
+ /**
1205
+ * Returns true if the profile supports feature set functions for snippets.
1206
+ */
1207
+ get supportFeatureSetFunctions() {
1208
+ return this.definition?.bundles?.includes("data-access") ?? false;
1209
+ }
1210
+ /**
1211
+ * Returns the EditorProfile as a json. The EditorProfile may have been updated. This function allows to
1212
+ * get the new json representing mutations.
1213
+ */
1214
+ toEditorProfileDefinition() {
1215
+ return {
1216
+ ...this.definition,
1217
+ variables: this.dictionaryVariables.map((variable) => variable.toProfileVariableDefinition()),
1218
+ };
1219
+ }
1220
+ }
1221
+ //#endregion
1222
+
1223
+ // this file contains the building blocks for a language default provider
1224
+ const defaultContext = {
1225
+ locale: "en",
1226
+ };
1227
+ class LanguageDefaultsBase {
1228
+ constructor() {
1229
+ // #endregion
1230
+ // #region Protected properties
1231
+ this._onDidChange = new Emitter();
1232
+ this._profileMap = new Map();
1233
+ this._apiContextMap = new Map();
1234
+ this._onModelContextDidChange = new Emitter();
1235
+ this._onDidModelContextChangeTimeout = -1;
1236
+ // #endregion
1237
+ }
1238
+ // #endregion
1239
+ // #region Protected methods
1240
+ _fireModelContextDidChange(key) {
1241
+ if (this._onDidModelContextChangeTimeout !== -1) {
1242
+ return;
1243
+ }
1244
+ this._onDidModelContextChangeTimeout = window.setTimeout(() => {
1245
+ this._onDidModelContextChangeTimeout = -1;
1246
+ this._onModelContextDidChange.fire(key);
1247
+ }, 0);
1248
+ }
1249
+ _getApiKey(modelId) {
1250
+ if (!Uri.isUri(modelId)) {
1251
+ modelId = Uri.parse(modelId);
1252
+ }
1253
+ return modelId.toString();
1254
+ }
1255
+ // #endregion
1256
+ // #region Public methods
1257
+ get onDidChange() {
1258
+ return this._onDidChange.event;
1259
+ }
1260
+ get languageOptions() {
1261
+ return this._languageOptions;
1262
+ }
1263
+ /**
1264
+ * Dispose any cached resources for the model
1265
+ */
1266
+ disposeForModel(modelId) {
1267
+ const key = this._getApiKey(modelId);
1268
+ this._profileMap.delete(key);
1269
+ if (this._apiContextMap.delete(key)) {
1270
+ this._fireModelContextDidChange(key);
1271
+ }
1272
+ }
1273
+ /**
1274
+ * Returns the editor profile for the given model id.
1275
+ * @param modelId The model id for which to get the editor profile.
1276
+ * @returns The editor profile for the model.
1277
+ */
1278
+ getEditorProfileForModel(modelId) {
1279
+ return this._profileMap.get(this._getApiKey(modelId));
1280
+ }
1281
+ /**
1282
+ * Returns the API context for the given model id.
1283
+ * Returns the default context if the model has no context.
1284
+ * @param modelId The model id for which to get the API context.
1285
+ * @returns The API context for the model.
1286
+ */
1287
+ getApiContextForModel(contextId) {
1288
+ return this._apiContextMap.get(this._getApiKey(contextId)) ?? defaultContext;
1289
+ }
1290
+ /**
1291
+ * Set or update api context for the given model id.
1292
+ * @param modelId The model id for which to set the context.
1293
+ * @param apiContext The api context to set.
1294
+ */
1295
+ updateApiContextForModel(modelId, apiContext) {
1296
+ const key = this._getApiKey(modelId);
1297
+ const currentApiContext = this._apiContextMap.get(key) ?? {};
1298
+ this._apiContextMap.set(key, { ...currentApiContext, ...apiContext });
1299
+ this._fireModelContextDidChange(key);
1300
+ }
1301
+ get onModelContextDidChange() {
1302
+ return this._onModelContextDidChange.event;
1303
+ }
1304
+ get languageId() {
1305
+ return this._languageId;
1306
+ }
1307
+ }
1308
+
1309
+ export { EditorProfile as E, LanguageDefaultsBase as L, isFeatureSetCollectionDefinition as a, isFeatureSetDefinition as b, isFeatureDefinition as c, fieldsToProfileValues as f, isPredefinedProfile as i };