@arcgis/languages-api-utils 4.31.0-next.15

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.
package/LICENSE.md ADDED
@@ -0,0 +1,13 @@
1
+ # Licensing
2
+
3
+ COPYRIGHT © 2024 Esri
4
+
5
+ All rights reserved under the copyright laws of the United States and applicable international laws, treaties, and conventions.
6
+
7
+ This material is licensed for use under the Esri Master License Agreement (MLA), and is bound by the terms of that agreement. You may redistribute and use this code without modification, provided you adhere to the terms of the MLA and include this copyright notice.
8
+
9
+ See use restrictions at http://www.esri.com/legal/pdfs/mla_e204_e300/english
10
+
11
+ For additional information, contact: Environmental Systems Research Institute, Inc. Attn: Contracts and Legal Services Department 380 New York Street Redlands, California, USA 92373 USA
12
+
13
+ email: contracts@esri.com
package/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # ArcGIS Maps SDK for JavaScript - Languages API Utils
2
+
3
+ This package is part of the [ArcGIS Maps SDK for JavaScript](https://developers.arcgis.com/javascript/latest/).
4
+
5
+ The package provides a set of classes and utilities to work with custom programming languages inside
6
+ monaco-editor.
7
+
8
+ It is not intended to be used directly, but rather used as a dependency by other packages in the SDK.
9
+
10
+ ## License
11
+
12
+ COPYRIGHT © 2024 Esri
13
+
14
+ All rights reserved under the copyright laws of the United States and applicable international laws, treaties, and conventions.
15
+
16
+ This material is licensed for use under the Esri Master License Agreement (MLA), and is bound by the terms of that agreement. You may redistribute and use this code without modification, provided you adhere to the terms of the MLA and include this copyright notice.
17
+
18
+ See use restrictions at <http://www.esri.com/legal/pdfs/mla_e204_e300/english>
19
+
20
+ For additional information, contact: Environmental Systems Research Institute, Inc. Attn: Contracts and Legal Services Department 380 New York Street Redlands, California, USA 92373 USA
21
+
22
+ email: contracts@esri.com
@@ -0,0 +1,3 @@
1
+ "use strict";var f=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var S=(e,t)=>{for(var i in t)f(e,i,{get:t[i],enumerable:!0})},k=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of C(t))!x.call(e,r)&&r!==i&&f(e,r,{get:()=>t[r],enumerable:!(n=b(t,r))||n.enumerable});return e};var V=e=>k(f({},"__esModule",{value:!0}),e);var F={};S(F,{ApiService:()=>g,isDictionaryVariable:()=>I,isValueVariable:()=>P});module.exports=V(F);var s=require("vscode-languageserver-types");function D(e){return Array.isArray(e.testSdkCategories)}async function h(e,t){try{let i=await e,n=new Map,r=new Map,a=[],o=T(t);return i.forEach(c=>{let l=[];c.items.forEach(p=>v(l,r,n,o,p)),l.length&&a.push({...c,items:l})}),{categories:a,functionDefinitions:n,constantDefinitions:r}}catch{return{categories:[],functionDefinitions:new Map,constantDefinitions:new Map}}}var g=class{constructor(t){this._settings=t;this.sdkCategoriesCache=new Map}async getApiDatabase(t){let{locale:i="en"}=t,n=this.sdkCategoriesCache.get(i);if(!n){let{assetsPath:r}=this._settings;if(!r)return{categories:[],functionDefinitions:new Map,constantDefinitions:new Map};n=this.loadSdkApiLibrary(i,r),this.sdkCategoriesCache.set(i,n)}return await h(n,t)}async getApiLibrary(t){let{categories:i}=await this.getApiDatabase(t);return i}async loadSdkApiLibrary(t="en",i=""){if(D(this._settings))return this._settings.testSdkCategories;if(i=i.replace(/\/$/u,""),!i)return[];try{let n=this._settings.apiPathTemplate.replace("${assetsPath}",i).replace("${locale}",t),r=await fetch(n);return r.ok?await r.json():t==="en"?[]:await this.loadSdkApiLibrary("en",i)}catch{return[]}}};function T(e){let{profile:{apiVersion:t,bundles:i,hiddenApiItems:n=[]}={}}=e,r=y(t),a=Array.isArray(i)&&i.length>0?new Set(["core",...i]):void 0;return o=>M(r,o.sinceVersion)&&(!a||a.has(o.bundle))&&!n.includes(o.name)}function v(e,t,i,n,r){if(Array.isArray(r)){r.forEach(a=>A(e,i,n,a));return}r.type==="constant"?w(e,t,n,r):A(e,i,n,r)}function A(e,t,i,n){if(!i(n))return;n.disableDocumentation||e.push(n);let{completion:{label:r}}=n,a=r.toLowerCase(),o=t.get(a);o||(o={type:"functionDefinition",key:a,overloads:[]},t.set(a,o)),o.overloads.push(n)}function w(e,t,i,n){if(!i(n))return;e.push(n);let{completion:{label:r}}=n,a=r.toLowerCase();t.set(a,n);let[o,c]=n.completion.label.split(".");if(!c)return;let l=o.toLowerCase(),p=t.get(l);p||(p={type:"namespace",key:l,members:[],completion:{label:o,detail:o,insertText:o,insertTextMode:s.InsertTextMode.adjustIndentation,insertTextFormat:s.InsertTextFormat.PlainText,kind:s.CompletionItemKind.Enum}},t.set(l,p));let u=structuredClone(n);u.name=c,u.completion.label=c,u.completion.insertText=c,u.completion.kind=s.CompletionItemKind.Constant,p.members.push(u),p.completion.documentation=p.members.reduce((d,m)=>(d.value=`${d.value}${d.value?`
2
+
3
+ `:""}**${m.completion.label}**: ${m.description}`,d),{kind:s.MarkupKind.Markdown,value:""})}function y(e){if(!e||typeof e!="string")return null;let t=e.split(".").map(r=>Number.parseInt(r));if(t.some(Number.isNaN))return console.error("Invalid API version string",e),null;let[i,n]=t.slice(0,2);return{major:i,minor:n}}function M(e,t){if(!e)return!0;let i=y(t);return i?e.major>i.major?!1:e.minor===void 0||i.minor===void 0?!0:i.minor<=e.minor:!0}function P(e){return!!e&&e.type!=="dictionary"}function I(e){return e?.type==="dictionary"}0&&(module.exports={ApiService,isDictionaryVariable,isValueVariable});
@@ -0,0 +1,325 @@
1
+ import { CompletionItem } from 'vscode-languageserver-types';
2
+
3
+ /**
4
+ * Supported function bundles
5
+ */
6
+ type BundleType = "core" | "data-access" | "database" | "geometry" | "knowledge-graph" | "portal-access" | "track";
7
+
8
+ /**
9
+ * The list of supported profiles
10
+ */
11
+ type ProfileId = "minimalist" | "alias" | "attribute-rule-calculation" | "attribute-rule-constraint" | "attribute-rule-validation" | "dashboard-indicator-formatting" | "dashboard-list-formatting" | "dashboard-table-formatting" | "dashboard-data" | "dictionary-renderer" | "feature-z" | "field-calculation" | "field-mapping" | "form-calculation" | "form-constraint" | "geoanalytics" | "geotrigger-notification" | "labeling" | "layout" | "location-update-constraint" | "measure-visualization" | "popup" | "popup-element" | "popup-feature-reduction" | "popup-element-feature-reduction" | "quick-capture" | "tasks" | "velocity" | "visualization";
12
+ /**
13
+ * Describes a profile
14
+ */
15
+ interface SdkPredefinedProfile {
16
+ /**
17
+ * Profile name for UI
18
+ */
19
+ name: string;
20
+ /**
21
+ * Profile id for docs
22
+ */
23
+ id: ProfileId;
24
+ /**
25
+ * Function bundles enabled for this profile
26
+ */
27
+ bundles: BundleType[];
28
+ /**
29
+ * Variable describing name, type, and providing description
30
+ */
31
+ variables: SdkVariable[];
32
+ }
33
+ /**
34
+ * Supported profile variable types
35
+ */
36
+ type SdkVariableType = "number" | "text" | "date" | "dateOnly" | "time" | "boolean" | "dictionary" | "array" | "geometry" | "feature" | "featureSet" | "featureSetCollection" | "knowledgeGraph";
37
+ /**
38
+ * Describes variables
39
+ */
40
+ interface SdkVariableBase {
41
+ /**
42
+ * Name of the variable.
43
+ */
44
+ name: string;
45
+ /**
46
+ * Type of the variable.
47
+ */
48
+ type: SdkVariableType;
49
+ /**
50
+ * Description of the variable.
51
+ */
52
+ description?: string;
53
+ }
54
+ /**
55
+ * A variable that represents a simple type (boolean, number, feature, etc.)
56
+ */
57
+ interface SdkValueVariable extends SdkVariableBase {
58
+ type: Exclude<SdkVariableType, "dictionary">;
59
+ }
60
+ /**
61
+ * A dictionary variable
62
+ */
63
+ interface SdkDictionaryVariable extends SdkVariableBase {
64
+ type: "dictionary";
65
+ properties: SdkVariable[];
66
+ }
67
+ /**
68
+ * Profile variable
69
+ */
70
+ type SdkVariable = SdkValueVariable | SdkDictionaryVariable;
71
+
72
+ /**
73
+ * Represents an api category and its items
74
+ */
75
+ interface SdkCategory {
76
+ /**
77
+ * The unique ID for the category
78
+ */
79
+ id: string;
80
+ /**
81
+ * The title for the category
82
+ */
83
+ title: string;
84
+ /**
85
+ * The collection of api items for the category
86
+ */
87
+ items: SdkItem[];
88
+ }
89
+ interface SdkItemBase {
90
+ /**
91
+ * The name of the function or constant.
92
+ */
93
+ name: string;
94
+ /**
95
+ * The version string when the api item was introduced. If undefined then it was from the origin.
96
+ */
97
+ sinceVersion?: string;
98
+ /**
99
+ * The api bundle this item belongs to.
100
+ */
101
+ bundle: BundleType;
102
+ /**
103
+ * Markdown description of the item.
104
+ */
105
+ description: string;
106
+ /**
107
+ * Markdown containing examples.
108
+ */
109
+ examples: string;
110
+ /**
111
+ * Link for additional information about the item.
112
+ */
113
+ link: string;
114
+ /**
115
+ * Completion item directly leveraged by the editor.
116
+ */
117
+ completion: CompletionItem;
118
+ /**
119
+ * Indicates if the documentation for this item should be disabled.
120
+ */
121
+ disableDocumentation?: boolean;
122
+ }
123
+ /**
124
+ * Represents a constant in the arcade api.
125
+ */
126
+ interface SdkConstant extends SdkItemBase {
127
+ type: "constant";
128
+ }
129
+ /**
130
+ * Represents a function in the arcade api
131
+ */
132
+ interface SdkFunction extends SdkItemBase {
133
+ type: "function";
134
+ /**
135
+ * Information leveraged by the editor to validate function call.
136
+ * Indicates the minimum number of expected parameters and the maximum number of parameters expected.
137
+ */
138
+ parametersInfo: {
139
+ min: number;
140
+ max: number;
141
+ };
142
+ }
143
+ /**
144
+ * Represents an item in the arcade api.
145
+ */
146
+ type SdkItem = SdkConstant | SdkFunction | SdkFunction[];
147
+
148
+ /**
149
+ * The editor can be extended with custom snippets
150
+ */
151
+ interface ApiSnippet {
152
+ /**
153
+ * The label for the snippet. The editor will use it to offer the snippet based on the text typed in the editor.
154
+ * It's recommended to keep it short and as close as possible to what the user may be looking for.
155
+ * For example: 'polyline'
156
+ */
157
+ label: string;
158
+ /**
159
+ * A slightly longer description of what the snippet offers.
160
+ */
161
+ detail: string;
162
+ /**
163
+ * A string that should be inserted into the script when selecting
164
+ * this snippet.
165
+ *
166
+ * The `insertText` is subject to interpretation by the editor.
167
+ * Use this rules: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#snippet_syntax
168
+ */
169
+ insertText: string;
170
+ }
171
+ /**
172
+ * Language service api options
173
+ */
174
+ interface ApiContext {
175
+ /**
176
+ * The profile (variables, additional api items, bundles, etc.)
177
+ */
178
+ profile?: ApiProfile;
179
+ /**
180
+ * The locale for the Api
181
+ */
182
+ locale?: string;
183
+ /**
184
+ * Allows to augment the language snippets with a collection of snippets
185
+ */
186
+ snippets?: ApiSnippet[];
187
+ }
188
+ /**
189
+ * Language service profile
190
+ */
191
+ interface ApiProfile {
192
+ /**
193
+ * The wellknown profile id if applicable
194
+ */
195
+ id?: ProfileId;
196
+ /**
197
+ * The set of profile variables
198
+ */
199
+ variables: ApiVariable[];
200
+ /**
201
+ * The api version to use
202
+ */
203
+ apiVersion?: string;
204
+ /**
205
+ * The api bundles to use
206
+ */
207
+ bundles?: BundleType[];
208
+ /**
209
+ * A collection of api item names to hide.
210
+ */
211
+ hiddenApiItems?: string[];
212
+ }
213
+ /**
214
+ * The type for value variable.
215
+ */
216
+ type ApiValueVariableType = Exclude<SdkVariableType, "dictionary">;
217
+ interface ApiVariableBase {
218
+ /**
219
+ * Name of the variable
220
+ */
221
+ name: string;
222
+ /**
223
+ * Optional short description for the variable
224
+ */
225
+ description?: string;
226
+ /**
227
+ * Completion item for the variable, leveraged bu the editor
228
+ */
229
+ completion?: CompletionItem;
230
+ }
231
+ /**
232
+ * Describes a dictionary type (feature, dictionary)
233
+ */
234
+ interface ApiDictionaryVariable extends ApiVariableBase {
235
+ type: "dictionary";
236
+ /**
237
+ * Dictionary properties
238
+ */
239
+ properties?: ApiVariable[];
240
+ }
241
+ /**
242
+ * Describes a simple variable type (number, featureSet, etc.)
243
+ */
244
+ interface ApiValueVariable extends ApiVariableBase {
245
+ type: ApiValueVariableType;
246
+ }
247
+ /**
248
+ * The profile variable type
249
+ */
250
+ type ApiVariable = ApiDictionaryVariable | ApiValueVariable;
251
+ /**
252
+ * Helper function to test if a variable is a value variable
253
+ */
254
+ declare function isValueVariable(variable: ApiVariable | null | undefined): variable is ApiValueVariable;
255
+ /**
256
+ * Helper function to test if a variable is a dictionary variable
257
+ */
258
+ declare function isDictionaryVariable(variable: ApiVariable | null | undefined): variable is ApiDictionaryVariable;
259
+
260
+ /**
261
+ * Represent items stored in the library
262
+ */
263
+ type ApiItem = SdkConstant | SdkFunction;
264
+ /**
265
+ * Represent a category of api items in the api library
266
+ */
267
+ interface ApiCategory extends SdkCategory {
268
+ items: ApiItem[];
269
+ }
270
+
271
+ /**
272
+ * Language service settings
273
+ */
274
+ interface LanguageServiceSettings {
275
+ /**
276
+ * The path to the assets folder where the api files are stored
277
+ */
278
+ assetsPath?: string;
279
+ /**
280
+ * A template string for constructing the path to the api definition
281
+ * example: `${assetsPath}/api/arcade-api.t9n.${locale}.json`
282
+ */
283
+ apiPathTemplate: string;
284
+ /**
285
+ * The language id
286
+ */
287
+ languageId: string;
288
+ }
289
+
290
+ type ApiConstantNamespace = {
291
+ type: "namespace";
292
+ key: string;
293
+ members: SdkConstant[];
294
+ completion: CompletionItem;
295
+ };
296
+ type ApiConstantDefinition = SdkConstant | ApiConstantNamespace;
297
+ type ApiFunctionDefinition = {
298
+ type: "functionDefinition";
299
+ key: string;
300
+ overloads: SdkFunction[];
301
+ };
302
+ /**
303
+ * Describes the API properties
304
+ */
305
+ interface ApiDatabase {
306
+ categories: ApiCategory[];
307
+ functionDefinitions: Map<string, ApiFunctionDefinition>;
308
+ constantDefinitions: Map<string, ApiConstantDefinition>;
309
+ }
310
+ declare class ApiService<TApiContext extends ApiContext = ApiContext> {
311
+ private _settings;
312
+ private sdkCategoriesCache;
313
+ constructor(_settings: LanguageServiceSettings);
314
+ /**
315
+ * Returns the API defintions for the given settings: definitions, constant definitions, and function definitons
316
+ */
317
+ getApiDatabase(context: TApiContext): Promise<ApiDatabase>;
318
+ /**
319
+ * Returns the API definitions
320
+ */
321
+ getApiLibrary(context: TApiContext): Promise<ApiCategory[]>;
322
+ private loadSdkApiLibrary;
323
+ }
324
+
325
+ export { type ApiCategory, type SdkConstant as ApiConstant, type ApiConstantDefinition, type ApiConstantNamespace, type ApiContext, type ApiDatabase, type ApiDictionaryVariable, type SdkFunction as ApiFunction, type ApiFunctionDefinition, type ApiItem, type ApiProfile, ApiService, type ApiSnippet, type ApiValueVariable, type ApiValueVariableType, type ApiVariable, type SdkVariableType as ApiVariableType, type BundleType, type LanguageServiceSettings, type ProfileId, type SdkPredefinedProfile, isDictionaryVariable, isValueVariable };
@@ -0,0 +1,325 @@
1
+ import { CompletionItem } from 'vscode-languageserver-types';
2
+
3
+ /**
4
+ * Supported function bundles
5
+ */
6
+ type BundleType = "core" | "data-access" | "database" | "geometry" | "knowledge-graph" | "portal-access" | "track";
7
+
8
+ /**
9
+ * The list of supported profiles
10
+ */
11
+ type ProfileId = "minimalist" | "alias" | "attribute-rule-calculation" | "attribute-rule-constraint" | "attribute-rule-validation" | "dashboard-indicator-formatting" | "dashboard-list-formatting" | "dashboard-table-formatting" | "dashboard-data" | "dictionary-renderer" | "feature-z" | "field-calculation" | "field-mapping" | "form-calculation" | "form-constraint" | "geoanalytics" | "geotrigger-notification" | "labeling" | "layout" | "location-update-constraint" | "measure-visualization" | "popup" | "popup-element" | "popup-feature-reduction" | "popup-element-feature-reduction" | "quick-capture" | "tasks" | "velocity" | "visualization";
12
+ /**
13
+ * Describes a profile
14
+ */
15
+ interface SdkPredefinedProfile {
16
+ /**
17
+ * Profile name for UI
18
+ */
19
+ name: string;
20
+ /**
21
+ * Profile id for docs
22
+ */
23
+ id: ProfileId;
24
+ /**
25
+ * Function bundles enabled for this profile
26
+ */
27
+ bundles: BundleType[];
28
+ /**
29
+ * Variable describing name, type, and providing description
30
+ */
31
+ variables: SdkVariable[];
32
+ }
33
+ /**
34
+ * Supported profile variable types
35
+ */
36
+ type SdkVariableType = "number" | "text" | "date" | "dateOnly" | "time" | "boolean" | "dictionary" | "array" | "geometry" | "feature" | "featureSet" | "featureSetCollection" | "knowledgeGraph";
37
+ /**
38
+ * Describes variables
39
+ */
40
+ interface SdkVariableBase {
41
+ /**
42
+ * Name of the variable.
43
+ */
44
+ name: string;
45
+ /**
46
+ * Type of the variable.
47
+ */
48
+ type: SdkVariableType;
49
+ /**
50
+ * Description of the variable.
51
+ */
52
+ description?: string;
53
+ }
54
+ /**
55
+ * A variable that represents a simple type (boolean, number, feature, etc.)
56
+ */
57
+ interface SdkValueVariable extends SdkVariableBase {
58
+ type: Exclude<SdkVariableType, "dictionary">;
59
+ }
60
+ /**
61
+ * A dictionary variable
62
+ */
63
+ interface SdkDictionaryVariable extends SdkVariableBase {
64
+ type: "dictionary";
65
+ properties: SdkVariable[];
66
+ }
67
+ /**
68
+ * Profile variable
69
+ */
70
+ type SdkVariable = SdkValueVariable | SdkDictionaryVariable;
71
+
72
+ /**
73
+ * Represents an api category and its items
74
+ */
75
+ interface SdkCategory {
76
+ /**
77
+ * The unique ID for the category
78
+ */
79
+ id: string;
80
+ /**
81
+ * The title for the category
82
+ */
83
+ title: string;
84
+ /**
85
+ * The collection of api items for the category
86
+ */
87
+ items: SdkItem[];
88
+ }
89
+ interface SdkItemBase {
90
+ /**
91
+ * The name of the function or constant.
92
+ */
93
+ name: string;
94
+ /**
95
+ * The version string when the api item was introduced. If undefined then it was from the origin.
96
+ */
97
+ sinceVersion?: string;
98
+ /**
99
+ * The api bundle this item belongs to.
100
+ */
101
+ bundle: BundleType;
102
+ /**
103
+ * Markdown description of the item.
104
+ */
105
+ description: string;
106
+ /**
107
+ * Markdown containing examples.
108
+ */
109
+ examples: string;
110
+ /**
111
+ * Link for additional information about the item.
112
+ */
113
+ link: string;
114
+ /**
115
+ * Completion item directly leveraged by the editor.
116
+ */
117
+ completion: CompletionItem;
118
+ /**
119
+ * Indicates if the documentation for this item should be disabled.
120
+ */
121
+ disableDocumentation?: boolean;
122
+ }
123
+ /**
124
+ * Represents a constant in the arcade api.
125
+ */
126
+ interface SdkConstant extends SdkItemBase {
127
+ type: "constant";
128
+ }
129
+ /**
130
+ * Represents a function in the arcade api
131
+ */
132
+ interface SdkFunction extends SdkItemBase {
133
+ type: "function";
134
+ /**
135
+ * Information leveraged by the editor to validate function call.
136
+ * Indicates the minimum number of expected parameters and the maximum number of parameters expected.
137
+ */
138
+ parametersInfo: {
139
+ min: number;
140
+ max: number;
141
+ };
142
+ }
143
+ /**
144
+ * Represents an item in the arcade api.
145
+ */
146
+ type SdkItem = SdkConstant | SdkFunction | SdkFunction[];
147
+
148
+ /**
149
+ * The editor can be extended with custom snippets
150
+ */
151
+ interface ApiSnippet {
152
+ /**
153
+ * The label for the snippet. The editor will use it to offer the snippet based on the text typed in the editor.
154
+ * It's recommended to keep it short and as close as possible to what the user may be looking for.
155
+ * For example: 'polyline'
156
+ */
157
+ label: string;
158
+ /**
159
+ * A slightly longer description of what the snippet offers.
160
+ */
161
+ detail: string;
162
+ /**
163
+ * A string that should be inserted into the script when selecting
164
+ * this snippet.
165
+ *
166
+ * The `insertText` is subject to interpretation by the editor.
167
+ * Use this rules: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#snippet_syntax
168
+ */
169
+ insertText: string;
170
+ }
171
+ /**
172
+ * Language service api options
173
+ */
174
+ interface ApiContext {
175
+ /**
176
+ * The profile (variables, additional api items, bundles, etc.)
177
+ */
178
+ profile?: ApiProfile;
179
+ /**
180
+ * The locale for the Api
181
+ */
182
+ locale?: string;
183
+ /**
184
+ * Allows to augment the language snippets with a collection of snippets
185
+ */
186
+ snippets?: ApiSnippet[];
187
+ }
188
+ /**
189
+ * Language service profile
190
+ */
191
+ interface ApiProfile {
192
+ /**
193
+ * The wellknown profile id if applicable
194
+ */
195
+ id?: ProfileId;
196
+ /**
197
+ * The set of profile variables
198
+ */
199
+ variables: ApiVariable[];
200
+ /**
201
+ * The api version to use
202
+ */
203
+ apiVersion?: string;
204
+ /**
205
+ * The api bundles to use
206
+ */
207
+ bundles?: BundleType[];
208
+ /**
209
+ * A collection of api item names to hide.
210
+ */
211
+ hiddenApiItems?: string[];
212
+ }
213
+ /**
214
+ * The type for value variable.
215
+ */
216
+ type ApiValueVariableType = Exclude<SdkVariableType, "dictionary">;
217
+ interface ApiVariableBase {
218
+ /**
219
+ * Name of the variable
220
+ */
221
+ name: string;
222
+ /**
223
+ * Optional short description for the variable
224
+ */
225
+ description?: string;
226
+ /**
227
+ * Completion item for the variable, leveraged bu the editor
228
+ */
229
+ completion?: CompletionItem;
230
+ }
231
+ /**
232
+ * Describes a dictionary type (feature, dictionary)
233
+ */
234
+ interface ApiDictionaryVariable extends ApiVariableBase {
235
+ type: "dictionary";
236
+ /**
237
+ * Dictionary properties
238
+ */
239
+ properties?: ApiVariable[];
240
+ }
241
+ /**
242
+ * Describes a simple variable type (number, featureSet, etc.)
243
+ */
244
+ interface ApiValueVariable extends ApiVariableBase {
245
+ type: ApiValueVariableType;
246
+ }
247
+ /**
248
+ * The profile variable type
249
+ */
250
+ type ApiVariable = ApiDictionaryVariable | ApiValueVariable;
251
+ /**
252
+ * Helper function to test if a variable is a value variable
253
+ */
254
+ declare function isValueVariable(variable: ApiVariable | null | undefined): variable is ApiValueVariable;
255
+ /**
256
+ * Helper function to test if a variable is a dictionary variable
257
+ */
258
+ declare function isDictionaryVariable(variable: ApiVariable | null | undefined): variable is ApiDictionaryVariable;
259
+
260
+ /**
261
+ * Represent items stored in the library
262
+ */
263
+ type ApiItem = SdkConstant | SdkFunction;
264
+ /**
265
+ * Represent a category of api items in the api library
266
+ */
267
+ interface ApiCategory extends SdkCategory {
268
+ items: ApiItem[];
269
+ }
270
+
271
+ /**
272
+ * Language service settings
273
+ */
274
+ interface LanguageServiceSettings {
275
+ /**
276
+ * The path to the assets folder where the api files are stored
277
+ */
278
+ assetsPath?: string;
279
+ /**
280
+ * A template string for constructing the path to the api definition
281
+ * example: `${assetsPath}/api/arcade-api.t9n.${locale}.json`
282
+ */
283
+ apiPathTemplate: string;
284
+ /**
285
+ * The language id
286
+ */
287
+ languageId: string;
288
+ }
289
+
290
+ type ApiConstantNamespace = {
291
+ type: "namespace";
292
+ key: string;
293
+ members: SdkConstant[];
294
+ completion: CompletionItem;
295
+ };
296
+ type ApiConstantDefinition = SdkConstant | ApiConstantNamespace;
297
+ type ApiFunctionDefinition = {
298
+ type: "functionDefinition";
299
+ key: string;
300
+ overloads: SdkFunction[];
301
+ };
302
+ /**
303
+ * Describes the API properties
304
+ */
305
+ interface ApiDatabase {
306
+ categories: ApiCategory[];
307
+ functionDefinitions: Map<string, ApiFunctionDefinition>;
308
+ constantDefinitions: Map<string, ApiConstantDefinition>;
309
+ }
310
+ declare class ApiService<TApiContext extends ApiContext = ApiContext> {
311
+ private _settings;
312
+ private sdkCategoriesCache;
313
+ constructor(_settings: LanguageServiceSettings);
314
+ /**
315
+ * Returns the API defintions for the given settings: definitions, constant definitions, and function definitons
316
+ */
317
+ getApiDatabase(context: TApiContext): Promise<ApiDatabase>;
318
+ /**
319
+ * Returns the API definitions
320
+ */
321
+ getApiLibrary(context: TApiContext): Promise<ApiCategory[]>;
322
+ private loadSdkApiLibrary;
323
+ }
324
+
325
+ export { type ApiCategory, type SdkConstant as ApiConstant, type ApiConstantDefinition, type ApiConstantNamespace, type ApiContext, type ApiDatabase, type ApiDictionaryVariable, type SdkFunction as ApiFunction, type ApiFunctionDefinition, type ApiItem, type ApiProfile, ApiService, type ApiSnippet, type ApiValueVariable, type ApiValueVariableType, type ApiVariable, type SdkVariableType as ApiVariableType, type BundleType, type LanguageServiceSettings, type ProfileId, type SdkPredefinedProfile, isDictionaryVariable, isValueVariable };
@@ -0,0 +1,3 @@
1
+ import{CompletionItemKind as f,InsertTextFormat as y,InsertTextMode as b,MarkupKind as C}from"vscode-languageserver-types";function x(i){return Array.isArray(i.testSdkCategories)}async function S(i,n){try{let e=await i,t=new Map,r=new Map,a=[],o=k(n);return e.forEach(p=>{let c=[];p.items.forEach(s=>V(c,r,t,o,s)),c.length&&a.push({...p,items:c})}),{categories:a,functionDefinitions:t,constantDefinitions:r}}catch{return{categories:[],functionDefinitions:new Map,constantDefinitions:new Map}}}var g=class{constructor(n){this._settings=n;this.sdkCategoriesCache=new Map}async getApiDatabase(n){let{locale:e="en"}=n,t=this.sdkCategoriesCache.get(e);if(!t){let{assetsPath:r}=this._settings;if(!r)return{categories:[],functionDefinitions:new Map,constantDefinitions:new Map};t=this.loadSdkApiLibrary(e,r),this.sdkCategoriesCache.set(e,t)}return await S(t,n)}async getApiLibrary(n){let{categories:e}=await this.getApiDatabase(n);return e}async loadSdkApiLibrary(n="en",e=""){if(x(this._settings))return this._settings.testSdkCategories;if(e=e.replace(/\/$/u,""),!e)return[];try{let t=this._settings.apiPathTemplate.replace("${assetsPath}",e).replace("${locale}",n),r=await fetch(t);return r.ok?await r.json():n==="en"?[]:await this.loadSdkApiLibrary("en",e)}catch{return[]}}};function k(i){let{profile:{apiVersion:n,bundles:e,hiddenApiItems:t=[]}={}}=i,r=A(n),a=Array.isArray(e)&&e.length>0?new Set(["core",...e]):void 0;return o=>h(r,o.sinceVersion)&&(!a||a.has(o.bundle))&&!t.includes(o.name)}function V(i,n,e,t,r){if(Array.isArray(r)){r.forEach(a=>m(i,e,t,a));return}r.type==="constant"?D(i,n,t,r):m(i,e,t,r)}function m(i,n,e,t){if(!e(t))return;t.disableDocumentation||i.push(t);let{completion:{label:r}}=t,a=r.toLowerCase(),o=n.get(a);o||(o={type:"functionDefinition",key:a,overloads:[]},n.set(a,o)),o.overloads.push(t)}function D(i,n,e,t){if(!e(t))return;i.push(t);let{completion:{label:r}}=t,a=r.toLowerCase();n.set(a,t);let[o,p]=t.completion.label.split(".");if(!p)return;let c=o.toLowerCase(),s=n.get(c);s||(s={type:"namespace",key:c,members:[],completion:{label:o,detail:o,insertText:o,insertTextMode:b.adjustIndentation,insertTextFormat:y.PlainText,kind:f.Enum}},n.set(c,s));let l=structuredClone(t);l.name=p,l.completion.label=p,l.completion.insertText=p,l.completion.kind=f.Constant,s.members.push(l),s.completion.documentation=s.members.reduce((u,d)=>(u.value=`${u.value}${u.value?`
2
+
3
+ `:""}**${d.completion.label}**: ${d.description}`,u),{kind:C.Markdown,value:""})}function A(i){if(!i||typeof i!="string")return null;let n=i.split(".").map(r=>Number.parseInt(r));if(n.some(Number.isNaN))return console.error("Invalid API version string",i),null;let[e,t]=n.slice(0,2);return{major:e,minor:t}}function h(i,n){if(!i)return!0;let e=A(n);return e?i.major>e.major?!1:i.minor===void 0||e.minor===void 0?!0:e.minor<=i.minor:!0}function w(i){return!!i&&i.type!=="dictionary"}function M(i){return i?.type==="dictionary"}export{g as ApiService,M as isDictionaryVariable,w as isValueVariable};
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@arcgis/languages-api-utils",
3
+ "version": "4.31.0-next.15",
4
+ "description": "ArcGIS Languages API Utilities",
5
+ "homepage": "https://developers.arcgis.com/javascript/latest/",
6
+ "type": "module",
7
+ "main": "dist/esm/index.js",
8
+ "module": "dist/esm/index.js",
9
+ "types": "dist/esm/index.d.ts",
10
+ "files": [
11
+ "dist/"
12
+ ],
13
+ "publishConfig": {
14
+ "registry": "https://registry.npmjs.org/",
15
+ "access": "public"
16
+ },
17
+ "license": "SEE LICENSE IN LICENSE.md",
18
+ "scripts": {
19
+ "build:dev": "yarn build:esm --sourcemap",
20
+ "build:cjs": "tsup --format cjs --outDir dist/cjs --silent --minify",
21
+ "build:esm": "tsup --format esm --outDir dist/esm --silent --minify",
22
+ "build": "npm run build:cjs && npm run build:esm",
23
+ "clean": "rimraf ./node_modules ./turbo ./dist",
24
+ "test": "jest"
25
+ },
26
+ "dependencies": {
27
+ "vscode-languageserver-textdocument": "^1.0.11",
28
+ "vscode-languageserver-types": "^3.17.5"
29
+ },
30
+ "devDependencies": {
31
+ "@arcgis/arcade-sdk": "~1.26.5",
32
+ "@arcgis/typescript-config": "4.31.0-next.15",
33
+ "@swc/core": "^1.5.6",
34
+ "@swc/jest": "^0.2.36",
35
+ "@types/jest": "^29.5.0",
36
+ "@types/node": "^20.2.5",
37
+ "eslint": "^8.55.0",
38
+ "jest": "^29.5.0",
39
+ "rimraf": "^5.0.0",
40
+ "tsup": "^8.1.0",
41
+ "typescript": "~5.4.0"
42
+ },
43
+ "gitHead": "679024353d5112dbab349c81b3d2c89358492044"
44
+ }