Skip to content

Commit

Permalink
feat(hub-common): add minimal definitions of ArcGIS types and drop ar…
Browse files Browse the repository at this point in the history
…cgis-js-api (#1797)
  • Loading branch information
tomwayson authored Feb 7, 2025
1 parent 16878c6 commit 27c08b8
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 89 deletions.
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
77 changes: 18 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions packages/common/src/content/_internal/internalContentUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
38 changes: 38 additions & 0 deletions packages/common/src/core/types/IGeometryInstance.ts
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 4 additions & 8 deletions packages/common/src/core/types/IHubLocation.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<Partial<__esri.Geometry>>;
// 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<Partial<IGeometryInstance>>;

/** The name of the location */
name?: string;
Expand Down
13 changes: 13 additions & 0 deletions packages/common/src/core/types/ISpatialReferenceInstance.ts
Original file line number Diff line number Diff line change
@@ -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;
}
4 changes: 2 additions & 2 deletions packages/common/src/core/types/Metrics.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -173,7 +173,7 @@ export interface IMetricAttributes extends IEntityInfo {
*/
export interface IMetricFeature {
attributes: IMetricAttributes;
geometry?: __esri.Geometry;
geometry?: IGeometryInstance;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/core/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down
Loading

0 comments on commit 27c08b8

Please sign in to comment.