Skip to content

Commit ccd0d75

Browse files
committed
add lint to services
1 parent 4824d05 commit ccd0d75

26 files changed

+1077
-1022
lines changed

plugins/arcgis/service/eslint.config.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,19 @@ export default [
99
files: ["**/*.{js,mjs,cjs,ts}"],
1010
languageOptions: { globals: globals.browser },
1111
plugins: { jsdoc },
12-
rules: { "jsdoc/require-description": "warn" },
12+
rules: {
13+
"jsdoc/require-description": "warn",
14+
"semi": ["error", "always"]
15+
},
16+
"overrides": [
17+
{
18+
// enable the rule specifically for TypeScript files
19+
"files": ["*.ts", "*.tsx"],
20+
"rules": {
21+
"@typescript-eslint/no-explicit-any": "off"
22+
}
23+
}
24+
]
1325
},
1426
pluginJs.configs.recommended,
1527
...tseslint.configs.recommended,

plugins/arcgis/service/src/AddLayersRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ export interface Field {
2424
nullable: boolean
2525
editable: boolean
2626
domain?: string
27-
defaultValue?: any
27+
defaultValue?: unknown
2828
}

plugins/arcgis/service/src/ArcGISConfig.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MageEventId } from "@ngageoint/mage.service/lib/entities/events/entities.events"
1+
import { MageEventId } from "@ngageoint/mage.service/lib/entities/events/entities.events";
22

33
/**
44
* Contains an arc feature service url and layers.
@@ -11,8 +11,8 @@ export interface FeatureServiceConfig {
1111
url: string
1212

1313
/**
14-
* Serialized ArcGISIdentityManager
15-
*/
14+
* Serialized ArcGISIdentityManager
15+
*/
1616
identityManager: string
1717

1818
/**
@@ -56,7 +56,7 @@ export interface AttributeConfig {
5656
/**
5757
* Value mappings
5858
*/
59-
mappings?: { [value: string]: any }
59+
mappings?: { [value: string]: unknown }
6060

6161
/**
6262
* Default values
@@ -100,7 +100,7 @@ export interface AttributeDefaultConfig {
100100
/**
101101
* Default value.
102102
*/
103-
value: any
103+
value: unknown
104104

105105
/**
106106
* Conditional attribute equality values when the default applies.
@@ -122,6 +122,6 @@ export interface AttributeValueConfig {
122122
/**
123123
* Attribute values.
124124
*/
125-
values: any[]
125+
values: unknown[]
126126

127127
}

plugins/arcgis/service/src/ArcGISPluginConfig.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FeatureServiceConfig, AttributeConfig } from "./ArcGISConfig"
1+
import { FeatureServiceConfig, AttributeConfig } from "./ArcGISConfig";
22

33
/**
44
* Contains various configuration values used by the plugin.
@@ -71,13 +71,13 @@ export interface ArcGISPluginConfig {
7171
idSeparator: string
7272

7373
/**
74-
* The event id field attribute name.
75-
*/
74+
* The event id field attribute name.
75+
*/
7676
eventIdField?: string
7777

7878
/**
79-
* The last edited date field attribute name on the ArcGIS server.
80-
*/
79+
* The last edited date field attribute name on the ArcGIS server.
80+
*/
8181
lastEditedDateField?: string
8282

8383
/**
@@ -123,7 +123,7 @@ export interface ArcGISPluginConfig {
123123
/**
124124
* Override mappings between event form fields and ArcGIS attributes as: { event: { form: { field: attribute } } }
125125
*/
126-
fieldAttributes?: any
126+
fieldAttributes?: unknown
127127

128128
/**
129129
* The attribute configurations.
@@ -162,16 +162,16 @@ export const defaultArcGISPluginConfig = Object.freeze<ArcGISPluginConfig>({
162162
{
163163
value: 3,
164164
condition: [
165-
{ attribute:'geometry_type', values: ['esriGeometryPolyline'] }
165+
{ attribute: 'geometry_type', values: ['esriGeometryPolyline'] }
166166
]
167167
},
168168
{
169169
value: 1,
170170
condition: [
171-
{ attribute:'geometry_type', values: ['esriGeometryPolygon'] }
171+
{ attribute: 'geometry_type', values: ['esriGeometryPolygon'] }
172172
]
173173
}
174174
]
175175
}
176176
}
177-
})
177+
});
Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,92 @@
1-
import { ArcGISIdentityManager } from '@esri/arcgis-rest-request'
2-
import { FeatureServiceConfig } from './ArcGISConfig'
3-
import { PluginStateRepository } from '@ngageoint/mage.service/lib/plugins.api'
1+
import { ArcGISIdentityManager } from '@esri/arcgis-rest-request';
2+
import { FeatureServiceConfig } from './ArcGISConfig';
3+
import { PluginStateRepository } from '@ngageoint/mage.service/lib/plugins.api';
4+
import { ArcGISPluginConfig } from './ArcGISPluginConfig';
45

6+
/**
7+
* Interface for managing ArcGIS identity and authentication.
8+
*/
59
export interface ArcGISIdentityService {
10+
/**
11+
* Sign in to ArcGIS with the feature service credentials.
12+
* @param {FeatureServiceConfig} featureService The feature service configuration.
13+
* @returns {Promise<ArcGISIdentityManager>} The ArcGIS identity manager.
14+
*/
615
signin(featureService: FeatureServiceConfig): Promise<ArcGISIdentityManager>
16+
17+
/**
18+
* Update the identity managers with latest tokens.
19+
* @returns {Promise<void>}
20+
*/
721
updateIndentityManagers(): Promise<void>
822
}
923

24+
/**
25+
* Creates a new ArcGIS identity service.
26+
* @param {PluginStateRepository<ArcGISPluginConfig>} stateRepo The plugin state repository.
27+
* @returns {ArcGISIdentityService} The ArcGIS identity service.
28+
*/
1029
export function createArcGISIdentityService(
11-
stateRepo: PluginStateRepository<any>
30+
stateRepo: PluginStateRepository<ArcGISPluginConfig>
1231
): ArcGISIdentityService {
13-
const identityManagerCache: Map<string, Promise<ArcGISIdentityManager>> = new Map()
32+
const identityManagerCache: Map<string, Promise<ArcGISIdentityManager>> = new Map();
1433

1534
return {
1635
async signin(featureService: FeatureServiceConfig): Promise<ArcGISIdentityManager> {
17-
let cached = await identityManagerCache.get(featureService.url)
36+
const cached = await identityManagerCache.get(featureService.url);
1837
if (!cached) {
19-
const identityManager = ArcGISIdentityManager.deserialize(featureService.identityManager)
20-
const promise = identityManager.getUser().then(() => identityManager)
21-
identityManagerCache.set(featureService.url, promise)
22-
return promise
38+
const identityManager = ArcGISIdentityManager.deserialize(featureService.identityManager);
39+
const promise = identityManager.getUser().then(() => identityManager);
40+
identityManagerCache.set(featureService.url, promise);
41+
return promise;
2342
} else {
24-
return cached
43+
return cached;
2544
}
2645
},
46+
2747
async updateIndentityManagers() {
28-
const config = await stateRepo.get()
29-
for (let [url, persistedIdentityManagerPromise] of identityManagerCache) {
30-
const persistedIdentityManager = await persistedIdentityManagerPromise
31-
const featureService: FeatureServiceConfig | undefined = config.featureServices.find((service: FeatureServiceConfig) => service.url === url)
32-
if (featureService) {
33-
const identityManager = ArcGISIdentityManager.deserialize(featureService.identityManager)
48+
const config = await stateRepo.get() as ArcGISPluginConfig | null;
49+
for (const [url, persistedIdentityManagerPromise] of identityManagerCache) {
50+
const persistedIdentityManager = await persistedIdentityManagerPromise;
51+
const featureService: FeatureServiceConfig | undefined = config?.featureServices.find((service: FeatureServiceConfig) => service.url === url);
52+
if (featureService && config) {
53+
const identityManager = ArcGISIdentityManager.deserialize(featureService.identityManager);
3454
if (identityManager.token !== persistedIdentityManager.token || identityManager.refreshToken !== persistedIdentityManager.refreshToken) {
35-
featureService.identityManager = persistedIdentityManager.serialize()
36-
await stateRepo.put(config)
55+
featureService.identityManager = persistedIdentityManager.serialize();
56+
await stateRepo.patch(config as never);
3757
}
3858
}
3959
}
4060
}
41-
}
61+
};
4262
}
4363

64+
/**
65+
* Gets the portal URL for an ArcGIS feature service.
66+
* @param {FeatureServiceConfig | string} featureService The feature service config or URL.
67+
* @returns {string} The portal URL.
68+
*/
4469
export function getPortalUrl(featureService: FeatureServiceConfig | string): string {
45-
const url = getFeatureServiceUrl(featureService)
46-
return `https://${url.hostname}/arcgis/sharing/rest`
70+
const url = getFeatureServiceUrl(featureService);
71+
return `https://${url.hostname}/arcgis/sharing/rest`;
4772
}
4873

74+
/**
75+
* Gets the server URL for an ArcGIS feature service.
76+
* @param {FeatureServiceConfig | string} featureService The feature service config or URL.
77+
* @returns {string} The server URL.
78+
*/
4979
export function getServerUrl(featureService: FeatureServiceConfig | string): string {
50-
const url = getFeatureServiceUrl(featureService)
51-
return `https://${url.hostname}/arcgis`
80+
const url = getFeatureServiceUrl(featureService);
81+
return `https://${url.hostname}/arcgis`;
5282
}
5383

84+
/**
85+
* Gets the URL object for an ArcGIS feature service.
86+
* @param {FeatureServiceConfig | string} featureService The feature service config or URL string.
87+
* @returns {URL} The feature service URL.
88+
*/
5489
export function getFeatureServiceUrl(featureService: FeatureServiceConfig | string): URL {
55-
const url = typeof featureService === 'string' ? featureService : featureService.url
56-
return new URL(url)
90+
const url = typeof featureService === 'string' ? featureService : featureService.url;
91+
return new URL(url);
5792
}

plugins/arcgis/service/src/ArcObject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
export interface ArcObject {
66
geometry: ArcGeometry,
77
attributes: {
8-
[key: string]: any
8+
[key: string]: unknown
99
}
1010
}
1111

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ArcObject } from './ArcObject'
2-
import { ArcObservation } from './ArcObservation'
1+
import { ArcObject } from './ArcObject';
2+
import { ArcObservation } from './ArcObservation';
33

44
/**
55
* Observation Features Objects to send, update, or delete in ArcGIS.
@@ -9,17 +9,17 @@ export class ArcObjects {
99
/**
1010
* The features to send to the arc server.
1111
*/
12-
objects: ArcObject[]
12+
objects: ArcObject[];
1313

1414
/**
1515
* The observations to send to the arc server.
1616
*/
17-
observations: ArcObservation[]
17+
observations: ArcObservation[];
1818

1919
/**
2020
* The observations to delete from the arc server.
2121
*/
22-
deletions: ArcObservation[]
22+
deletions: ArcObservation[];
2323

2424
/**
2525
* Indicates if these arc objects have been created from observations in the database and this
@@ -32,43 +32,43 @@ export class ArcObjects {
3232
* Constructor.
3333
*/
3434
constructor() {
35-
this.objects = []
36-
this.observations = []
37-
this.deletions = []
35+
this.objects = [];
36+
this.observations = [];
37+
this.deletions = [];
3838
this.firstRun = false;
3939
}
4040

4141
/**
4242
* Add an observation.
43-
* @param observation The observation to add.
43+
* @param {ArcObservation} observation The observation to add.
4444
*/
4545
add(observation: ArcObservation) {
46-
this.observations.push(observation)
47-
this.objects.push(observation.object)
46+
this.observations.push(observation);
47+
this.objects.push(observation.object);
4848
}
4949

5050
/**
5151
* Count of observations.
52-
* @return observation count.
52+
* @returns {number} observation count.
5353
*/
5454
count(): number {
55-
return this.objects.length
55+
return this.objects.length;
5656
}
5757

5858
/**
5959
* Is observations empty.
60-
* @return true if empty.
60+
* @returns {boolean} true if empty.
6161
*/
6262
isEmpty(): boolean {
63-
return this.count() == 0
63+
return this.count() == 0;
6464
}
6565

6666
/**
6767
* Clear the observations.
6868
*/
6969
clear() {
70-
this.objects = []
71-
this.observations = []
70+
this.objects = [];
71+
this.observations = [];
7272
}
7373

7474
}

plugins/arcgis/service/src/ArcObservation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ArcObject } from './ArcObject'
2-
import { ObservationId } from '@ngageoint/mage.service/lib/entities/observations/entities.observations'
1+
import { ArcObject } from './ArcObject';
2+
import { ObservationId } from '@ngageoint/mage.service/lib/entities/observations/entities.observations';
33

44
/**
55
* The ArcGIS Observation wraps the raw ArcObject and combines Arc & MAGE metadata.

0 commit comments

Comments
 (0)