diff --git a/karma.conf.js b/karma.conf.js index 41a2a71a908..e0f10963019 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -57,7 +57,7 @@ module.exports = function (config) { tsconfig: "./tsconfig.json", bundlerOptions: { transforms: [require("karma-typescript-es6-transform")()], - exclude: ["@esri/arcgis-rest-types"], + exclude: [ "@esri/arcgis-rest-types" ], resolve: { // karmas resolver cant figure out the symlinked deps from lerna // so we need to manually alias each package here. diff --git a/package-lock.json b/package-lock.json index 51c1f13b044..5c544b07953 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10242,15 +10242,6 @@ "integrity": "sha512-7vRDaOFejVMdjzKagD45fK+mFs8pb0h9zmvsGrYsaQY9z+X3xUqf71uNMv8+OiVa8u/w1A7DS29LSUFzOnstRw==", "dev": true }, - "node_modules/@types/arcgis-js-api": { - "version": "4.28.0", - "resolved": "https://registry.npmjs.org/@types/arcgis-js-api/-/arcgis-js-api-4.28.0.tgz", - "integrity": "sha512-BYNaT12l3T2GQ+Bj7jbMUhe1K6CaCSMj/uaAOmZYwV/FaR8wJ8UBYwdEaX6oFus7oHgLX0NcbfTrj4TgUcGSpg==", - "deprecated": "This is a stub types definition. arcgis-js-api provides its own type definitions, so you do not need this installed.", - "dependencies": { - "arcgis-js-api": "*" - } - }, "node_modules/@types/arcgis-rest-api": { "version": "10.4.8", "resolved": "https://registry.npmjs.org/@types/arcgis-rest-api/-/arcgis-rest-api-10.4.8.tgz", @@ -11826,11 +11817,6 @@ "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", "dev": true }, - "node_modules/arcgis-js-api": { - "version": "4.30.9", - "resolved": "https://registry.npmjs.org/arcgis-js-api/-/arcgis-js-api-4.30.9.tgz", - "integrity": "sha512-FFHAX6Yh5m/pldBpA58+vg9oSUASOtokMuE2PKV9As6TKF9VbT3C6FlExv/3ln/T2Bc2dlAmcGMdrrvNbQqepA==" - }, "node_modules/are-we-there-yet": { "version": "1.1.7", "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.7.tgz", @@ -22695,10 +22681,9 @@ }, "node_modules/cz-lerna-changelog/node_modules/npm/node_modules/lodash._baseindexof": { "version": "3.1.0", - "dev": true, + "extraneous": true, "inBundle": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/cz-lerna-changelog/node_modules/npm/node_modules/lodash._baseuniq": { "version": "4.6.0", @@ -22713,24 +22698,21 @@ }, "node_modules/cz-lerna-changelog/node_modules/npm/node_modules/lodash._bindcallback": { "version": "3.0.1", - "dev": true, + "extraneous": true, "inBundle": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/cz-lerna-changelog/node_modules/npm/node_modules/lodash._cacheindexof": { "version": "3.0.2", - "dev": true, + "extraneous": true, "inBundle": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/cz-lerna-changelog/node_modules/npm/node_modules/lodash._createcache": { "version": "3.1.2", - "dev": true, + "extraneous": true, "inBundle": true, "license": "MIT", - "peer": true, "dependencies": { "lodash._getnative": "^3.0.0" } @@ -22744,10 +22726,9 @@ }, "node_modules/cz-lerna-changelog/node_modules/npm/node_modules/lodash._getnative": { "version": "3.9.1", - "dev": true, + "extraneous": true, "inBundle": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/cz-lerna-changelog/node_modules/npm/node_modules/lodash._root": { "version": "3.0.1", @@ -22765,10 +22746,9 @@ }, "node_modules/cz-lerna-changelog/node_modules/npm/node_modules/lodash.restparam": { "version": "3.6.1", - "dev": true, + "extraneous": true, "inBundle": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/cz-lerna-changelog/node_modules/npm/node_modules/lodash.union": { "version": "4.6.0", @@ -65023,11 +65003,10 @@ }, "packages/common": { "name": "@esri/hub-common", - "version": "15.27.0", + "version": "15.29.0", "license": "Apache-2.0", "dependencies": { "@terraformer/arcgis": "^2.1.2", - "@types/arcgis-js-api": "~4.28.0", "abab": "^2.0.5", "adlib": "^3.0.8", "ajv": "^6.12.6", @@ -68769,7 +68748,6 @@ "requires": { "@terraformer/arcgis": "^2.1.2", "@types/adlib": "^3.0.1", - "@types/arcgis-js-api": "~4.28.0", "@types/geojson": "^7946.0.13", "@types/terraformer__arcgis": "^2.0.5", "abab": "^2.0.5", @@ -73152,14 +73130,6 @@ "integrity": "sha512-7vRDaOFejVMdjzKagD45fK+mFs8pb0h9zmvsGrYsaQY9z+X3xUqf71uNMv8+OiVa8u/w1A7DS29LSUFzOnstRw==", "dev": true }, - "@types/arcgis-js-api": { - "version": "4.28.0", - "resolved": "https://registry.npmjs.org/@types/arcgis-js-api/-/arcgis-js-api-4.28.0.tgz", - "integrity": "sha512-BYNaT12l3T2GQ+Bj7jbMUhe1K6CaCSMj/uaAOmZYwV/FaR8wJ8UBYwdEaX6oFus7oHgLX0NcbfTrj4TgUcGSpg==", - "requires": { - "arcgis-js-api": "*" - } - }, "@types/arcgis-rest-api": { "version": "10.4.8", "resolved": "https://registry.npmjs.org/@types/arcgis-rest-api/-/arcgis-rest-api-10.4.8.tgz", @@ -74505,11 +74475,6 @@ "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", "dev": true }, - "arcgis-js-api": { - "version": "4.30.9", - "resolved": "https://registry.npmjs.org/arcgis-js-api/-/arcgis-js-api-4.30.9.tgz", - "integrity": "sha512-FFHAX6Yh5m/pldBpA58+vg9oSUASOtokMuE2PKV9As6TKF9VbT3C6FlExv/3ln/T2Bc2dlAmcGMdrrvNbQqepA==" - }, "are-we-there-yet": { "version": "1.1.7", "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.7.tgz", @@ -83487,8 +83452,7 @@ "lodash._baseindexof": { "version": "3.1.0", "bundled": true, - "dev": true, - "peer": true + "extraneous": true }, "lodash._baseuniq": { "version": "4.6.0", @@ -83503,20 +83467,17 @@ "lodash._bindcallback": { "version": "3.0.1", "bundled": true, - "dev": true, - "peer": true + "extraneous": true }, "lodash._cacheindexof": { "version": "3.0.2", "bundled": true, - "dev": true, - "peer": true + "extraneous": true }, "lodash._createcache": { "version": "3.1.2", "bundled": true, - "dev": true, - "peer": true, + "extraneous": true, "requires": { "lodash._getnative": "^3.0.0" } @@ -83530,8 +83491,7 @@ "lodash._getnative": { "version": "3.9.1", "bundled": true, - "dev": true, - "peer": true + "extraneous": true }, "lodash._root": { "version": "3.0.1", @@ -83548,8 +83508,7 @@ "lodash.restparam": { "version": "3.6.1", "bundled": true, - "dev": true, - "peer": true + "extraneous": true }, "lodash.union": { "version": "4.6.0", diff --git a/packages/common/package.json b/packages/common/package.json index f67a82f7a82..e0205084acc 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -13,7 +13,6 @@ ], "dependencies": { "@terraformer/arcgis": "^2.1.2", - "@types/arcgis-js-api": "~4.28.0", "abab": "^2.0.5", "adlib": "^3.0.8", "ajv": "^6.12.6", diff --git a/packages/common/src/content/_internal/internalContentUtils.ts b/packages/common/src/content/_internal/internalContentUtils.ts index 88188acebf4..7c68165553c 100644 --- a/packages/common/src/content/_internal/internalContentUtils.ts +++ b/packages/common/src/content/_internal/internalContentUtils.ts @@ -17,11 +17,11 @@ import { IUser, } from "@esri/arcgis-rest-types"; import { + IGeometryInstance, IHubContent, IHubLocation, PublisherSource, - getTypeFromEntity, -} from "../../core"; +} from "../../core/types"; import { IHubGeography, GeographyProvenance, @@ -163,13 +163,13 @@ export const deriveLocationFromItem = (item: IItem): IHubLocation => { // determine the spatial reference of the extent. const bbox = GeoJSONPolygonToBBox(extent as any as Polygon); const defaultSpatialReference = { wkid: 4326 }; - const _geometry: Partial<__esri.Geometry> = { + const _geometry = { type: "polygon", ...geojsonToArcGIS(extent as any as Polygon), spatialReference: allCoordinatesPossiblyWGS84(bbox) ? defaultSpatialReference : (getItemSpatialReference(item) as any) || defaultSpatialReference, - }; + } as IGeometryInstance; return { type: "custom", extent: bbox, diff --git a/packages/common/src/core/types/IGeometryInstance.ts b/packages/common/src/core/types/IGeometryInstance.ts new file mode 100644 index 00000000000..e1e55253483 --- /dev/null +++ b/packages/common/src/core/types/IGeometryInstance.ts @@ -0,0 +1,38 @@ +import { ISpatialReferenceInstance } from "./ISpatialReferenceInstance.js"; + +// NOTE: we define our own interface for geometry b/c +// adding @arcgis/core just to get the Geometry type causes problems, for example: +// as of the 4.32 RC we see (non-fatal) TS errors when running karma tests +/** + * An instance of the [Geometry](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Geometry.html) class + * + * NOTE: this interface only defines the properties needed by this package + */ +export interface IGeometryInstance { + /** + * The spatial reference of the geometry. + * + * @default SpatialReference.WGS84 // wkid: 4326 + * + * [Read more...](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Geometry.html#spatialReference) + */ + spatialReference: ISpatialReferenceInstance; + /** + * The geometry type. + * + * [Read more...](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Geometry.html#type) + */ + readonly type: + | "point" + | "multipoint" + | "polyline" + | "polygon" + | "extent" + | "mesh"; + /** + * Converts an instance of this class to its [ArcGIS portal JSON](https://developers.arcgis.com/documentation/common-data-types/geometry-objects.htm) representation. + * + * [Read more...](https://developers.arcgis.com/javascript/latest/api-reference/esri-core-JSONSupport.html#toJSON) + */ + toJSON(): any; +} diff --git a/packages/common/src/core/types/IHubLocation.ts b/packages/common/src/core/types/IHubLocation.ts index 75e64e63741..d5c95def05e 100644 --- a/packages/common/src/core/types/IHubLocation.ts +++ b/packages/common/src/core/types/IHubLocation.ts @@ -1,6 +1,7 @@ import { ISpatialReference } from "@esri/arcgis-rest-types"; import { IHubLocationType } from "./types"; import { HubEntityType } from "./HubEntityType"; +import { IGeometryInstance } from "../.."; /** * A location associated with an item and stored as a json resource. @@ -17,14 +18,9 @@ export interface IHubLocation { // the extent of the location extent?: number[][]; - // array of geometries representing the location - // NOTE: we use partial here b/c __esri.Geometry - // is the type for instances and includes methods, etc - // but we want to be able to pass around POJOs as well as instances - // instead, we might want to use __esri.GeometryProperties or - // a discriminated union of the point, line, polygon, and extent _property_ types - // but for now it is a non-breaking change to relax __esri.Geometry w/ a partial - geometries?: Array>; + // NOTE: at next major release or breaking change we can probably remove the Partial here + /** array of[geometries](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Geometry.html) representing the location */ + geometries?: Array>; /** The name of the location */ name?: string; diff --git a/packages/common/src/core/types/ISpatialReferenceInstance.ts b/packages/common/src/core/types/ISpatialReferenceInstance.ts new file mode 100644 index 00000000000..6abaceff21f --- /dev/null +++ b/packages/common/src/core/types/ISpatialReferenceInstance.ts @@ -0,0 +1,13 @@ +/** + * The properties of a spatial reference instance used by hub.js + * + * [Read more...](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-SpatialReference.html) + */ +export interface ISpatialReferenceInstance { + /** + * The well-known ID of a spatial reference. + * + * [Read more...](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-SpatialReference.html#wkid) + */ + wkid: number; +} diff --git a/packages/common/src/core/types/Metrics.ts b/packages/common/src/core/types/Metrics.ts index 025c8015abe..19330d5768b 100644 --- a/packages/common/src/core/types/Metrics.ts +++ b/packages/common/src/core/types/Metrics.ts @@ -1,7 +1,7 @@ import { IQuery } from "../../search/types/IHubCatalog"; import { FieldType, IField } from "@esri/arcgis-rest-types"; import { IReference } from "./IReference"; -import { ServiceAggregation } from "../../core/types/DynamicValues"; +import { IGeometryInstance, ServiceAggregation } from "../../core/types"; /** * Defines the information required from a Metric @@ -173,7 +173,7 @@ export interface IMetricAttributes extends IEntityInfo { */ export interface IMetricFeature { attributes: IMetricAttributes; - geometry?: __esri.Geometry; + geometry?: IGeometryInstance; } /** diff --git a/packages/common/src/core/types/index.ts b/packages/common/src/core/types/index.ts index c1dbc42e836..807406f75ca 100644 --- a/packages/common/src/core/types/index.ts +++ b/packages/common/src/core/types/index.ts @@ -3,6 +3,7 @@ export * from "./DynamicValues"; export * from "./HubEntity"; export * from "./HubEntityEditor"; export * from "./HubEntityType"; +export * from "./IGeometryInstance"; export * from "./IHubContent"; export * from "./IHubContentEnrichments"; export * from "./IHubDiscussion"; @@ -28,6 +29,7 @@ export * from "./IHubSchedule"; export * from "./IItemEnrichments"; export * from "./IReference"; export * from "./IServerEnrichments"; +export * from "./ISpatialReferenceInstance"; export * from "./ISystemStatus"; export * from "./MaybeTranslate"; export * from "./IHubCardViewModel"; diff --git a/packages/common/src/downloads/_internal/file-url-fetchers/fetchExportImageDownloadFile.ts b/packages/common/src/downloads/_internal/file-url-fetchers/fetchExportImageDownloadFile.ts index 5f5ec9c50ed..2f5da2627b0 100644 --- a/packages/common/src/downloads/_internal/file-url-fetchers/fetchExportImageDownloadFile.ts +++ b/packages/common/src/downloads/_internal/file-url-fetchers/fetchExportImageDownloadFile.ts @@ -1,3 +1,4 @@ +import { IExtent } from "@esri/arcgis-rest-types"; import { request } from "@esri/arcgis-rest-request"; import { DownloadOperationStatus, @@ -7,9 +8,19 @@ import { } from "../../types"; import HubError from "../../../HubError"; import { getProp } from "../../../objects/get-prop"; -import { IHubEditableContent } from "../../../core/types/IHubEditableContent"; +import { + IHubEditableContent, + ISpatialReferenceInstance, +} from "../../../core/types"; import { ExportImageFormat } from "../_types"; +/** + * Extent object with a spatial reference instance defined + */ +interface IExtentWithSpatialReference extends IExtent { + spatialReference: ISpatialReferenceInstance; +} + /** * @private * @@ -71,16 +82,18 @@ function validateOptions(options: IFetchDownloadFileOptions) { } } -function getExportImageExtent( - options: IFetchDownloadFileOptions -): __esri.Extent { +function getExportImageExtent(options: IFetchDownloadFileOptions) { const { entity, geometry } = options; - const serverExtent = getProp(entity, "extendedProps.server.extent"); + const serverExtent = getProp( + entity, + "extendedProps.server.extent" + ) as IExtentWithSpatialReference; // TODO: Factor in entity.extent if it exists AND is a valid 4326 bbox - let result: __esri.Extent = null; + let result: IExtentWithSpatialReference = null; if (geometry) { - result = geometry as __esri.Extent; + // NOTE: we already confirmed that geometry is an extent in validateOptions + result = geometry as unknown as IExtentWithSpatialReference; } else if (serverExtent) { result = serverExtent; } diff --git a/packages/common/src/downloads/types.ts b/packages/common/src/downloads/types.ts index d7a68f81cc9..3b981c6c283 100644 --- a/packages/common/src/downloads/types.ts +++ b/packages/common/src/downloads/types.ts @@ -1,5 +1,5 @@ import { IArcGISContext } from "../ArcGISContext"; -import { IHubEditableContent } from "../core/types/IHubEditableContent"; +import { IHubEditableContent, IGeometryInstance } from "../core/types"; /** * This hash map was defined to support the previous implementation of the export item flow. @@ -129,7 +129,11 @@ export interface IFetchDownloadFileOptions { format: ServiceDownloadFormat; context: IArcGISContext; layers?: number[]; // layers to download; when not specified, all layers will be downloaded - geometry?: __esri.Geometry; // geometry to filter results by + /** + * [Geometry](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Geometry.html) to filter results by + * NOTE: image downloads only support [Extent](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Extent.html) or an extent-like object + */ + geometry?: IGeometryInstance; where?: string; // where clause to filter results by progressCallback?: downloadProgressCallback; pollInterval?: number; // interval in milliseconds to poll for job completion diff --git a/packages/common/test/downloads/_internal/file-url-fetchers/fetchHubApiDownloadFile.test.ts b/packages/common/test/downloads/_internal/file-url-fetchers/fetchHubApiDownloadFile.test.ts index 8803fcb22ec..8424326ef4b 100644 --- a/packages/common/test/downloads/_internal/file-url-fetchers/fetchHubApiDownloadFile.test.ts +++ b/packages/common/test/downloads/_internal/file-url-fetchers/fetchHubApiDownloadFile.test.ts @@ -240,7 +240,7 @@ describe("fetchHubApiDownloadFile", () => { geometry: { type: "point", toJSON: () => ({ type: "point", coordinates: [1, 2] }), - } as unknown as __esri.Point, + } as any, where: "1=1", }); diff --git a/packages/common/test/initiatives/fixtures.ts b/packages/common/test/initiatives/fixtures.ts index e5b7055aea3..b1bb444d121 100644 --- a/packages/common/test/initiatives/fixtures.ts +++ b/packages/common/test/initiatives/fixtures.ts @@ -34,7 +34,7 @@ export const INITIATIVE_LOCATION: IHubLocation = { [-76.8191059305754, 39.08220981728297], ], ], - } as unknown as __esri.Geometry, + } as any, ], }; diff --git a/packages/common/test/projects/fixtures.ts b/packages/common/test/projects/fixtures.ts index a559f54cd07..40632358869 100644 --- a/packages/common/test/projects/fixtures.ts +++ b/packages/common/test/projects/fixtures.ts @@ -34,7 +34,7 @@ export const PROJECT_LOCATION: IHubLocation = { [-76.8191059305754, 39.08220981728297], ], ], - } as unknown as __esri.Geometry, + } as any, ], }; diff --git a/tsconfig.json b/tsconfig.json index c012cbaed02..55eb8be49dd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -53,8 +53,7 @@ ], /* List of folders to include type definitions from. */ "types": [ "node", - "jasmine", - "arcgis-js-api" + "jasmine" ], /* Type declaration files to be included in compilation. */ "allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */