@esri/hub-common 20.16.2 → 20.16.4

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.
@@ -1,4 +1,5 @@
1
1
  import { getItemData } from "@esri/arcgis-rest-portal";
2
+ import { includes } from "../utils";
2
3
  /**
3
4
  * Given an Item, fetch the data json and return an IModel
4
5
  * @param item
@@ -6,10 +7,25 @@ import { getItemData } from "@esri/arcgis-rest-portal";
6
7
  * @returns
7
8
  */
8
9
  export async function fetchModelFromItem(item, requestOptions) {
9
- const data = await getItemData(item.id, requestOptions).catch(() => null);
10
+ const data = shouldFetchItemData(item)
11
+ ? (await getItemData(item.id, requestOptions).catch(() => null))
12
+ : null;
10
13
  return {
11
14
  item,
12
15
  data,
13
16
  };
14
17
  }
18
+ /**
19
+ * Determine if we should attempt to fetch the item data
20
+ * @param item
21
+ * @returns
22
+ */
23
+ export function shouldFetchItemData(item) {
24
+ // This function can and should be expanded as we discover
25
+ // more item types or families that should not attempt to
26
+ // fetch data for. Example: "Image Collection" will try
27
+ // to download the entire image collection to the browser
28
+ const typesToExclude = ["Image Collection"];
29
+ return !includes(typesToExclude, item.type);
30
+ }
15
31
  //# sourceMappingURL=fetchModelFromItem.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetchModelFromItem.js","sourceRoot":"","sources":["../../../src/models/fetchModelFromItem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAS,MAAM,0BAA0B,CAAC;AAI9D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,IAAW,EACX,cAA+B;IAE/B,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IAC1E,OAAO;QACL,IAAI;QACJ,IAAI;KACK,CAAC;AACd,CAAC"}
1
+ {"version":3,"file":"fetchModelFromItem.js","sourceRoot":"","sources":["../../../src/models/fetchModelFromItem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAS,MAAM,0BAA0B,CAAC;AAG9D,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,IAAW,EACX,cAA+B;IAE/B,MAAM,IAAI,GAAG,mBAAmB,CAAC,IAAI,CAAC;QACpC,CAAC,CAAE,CAAC,MAAM,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAG5D;QACJ,CAAC,CAAC,IAAI,CAAC;IACT,OAAO;QACL,IAAI;QACJ,IAAI;KACK,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAW;IAC7C,0DAA0D;IAC1D,yDAAyD;IACzD,uDAAuD;IACvD,yDAAyD;IACzD,MAAM,cAAc,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC5C,OAAO,CAAC,QAAQ,CAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9C,CAAC"}
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchModelFromItem = void 0;
3
+ exports.shouldFetchItemData = exports.fetchModelFromItem = void 0;
4
4
  const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
5
+ const utils_1 = require("../utils");
5
6
  /**
6
7
  * Given an Item, fetch the data json and return an IModel
7
8
  * @param item
@@ -9,11 +10,27 @@ const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
9
10
  * @returns
10
11
  */
11
12
  async function fetchModelFromItem(item, requestOptions) {
12
- const data = await arcgis_rest_portal_1.getItemData(item.id, requestOptions).catch(() => null);
13
+ const data = shouldFetchItemData(item)
14
+ ? (await arcgis_rest_portal_1.getItemData(item.id, requestOptions).catch(() => null))
15
+ : null;
13
16
  return {
14
17
  item,
15
18
  data,
16
19
  };
17
20
  }
18
21
  exports.fetchModelFromItem = fetchModelFromItem;
22
+ /**
23
+ * Determine if we should attempt to fetch the item data
24
+ * @param item
25
+ * @returns
26
+ */
27
+ function shouldFetchItemData(item) {
28
+ // This function can and should be expanded as we discover
29
+ // more item types or families that should not attempt to
30
+ // fetch data for. Example: "Image Collection" will try
31
+ // to download the entire image collection to the browser
32
+ const typesToExclude = ["Image Collection"];
33
+ return !utils_1.includes(typesToExclude, item.type);
34
+ }
35
+ exports.shouldFetchItemData = shouldFetchItemData;
19
36
  //# sourceMappingURL=fetchModelFromItem.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetchModelFromItem.js","sourceRoot":"","sources":["../../../src/models/fetchModelFromItem.ts"],"names":[],"mappings":";;;AAAA,iEAA8D;AAI9D;;;;;GAKG;AACI,KAAK,UAAU,kBAAkB,CACtC,IAAW,EACX,cAA+B;IAE/B,MAAM,IAAI,GAAG,MAAM,gCAAW,CAAC,IAAI,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IAC1E,OAAO;QACL,IAAI;QACJ,IAAI;KACK,CAAC;AACd,CAAC;AATD,gDASC"}
1
+ {"version":3,"file":"fetchModelFromItem.js","sourceRoot":"","sources":["../../../src/models/fetchModelFromItem.ts"],"names":[],"mappings":";;;AAAA,iEAA8D;AAG9D,oCAAoC;AAEpC;;;;;GAKG;AACI,KAAK,UAAU,kBAAkB,CACtC,IAAW,EACX,cAA+B;IAE/B,MAAM,IAAI,GAAG,mBAAmB,CAAC,IAAI,CAAC;QACpC,CAAC,CAAE,CAAC,MAAM,gCAAW,CAAC,IAAI,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAG5D;QACJ,CAAC,CAAC,IAAI,CAAC;IACT,OAAO;QACL,IAAI;QACJ,IAAI;KACK,CAAC;AACd,CAAC;AAdD,gDAcC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,IAAW;IAC7C,0DAA0D;IAC1D,yDAAyD;IACzD,uDAAuD;IACvD,yDAAyD;IACzD,MAAM,cAAc,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC5C,OAAO,CAAC,gBAAQ,CAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9C,CAAC;AAPD,kDAOC"}
@@ -1,4 +1,4 @@
1
- import { Polygon } from "geojson";
1
+ import type { Polygon } from "geojson";
2
2
  import { IHubRequestOptions } from "../../hub-types";
3
3
  import { IEntitySetting } from "../../discussions/api/types";
4
4
  import { IWithDiscussions } from "../traits/IWithDiscussions";
@@ -1,5 +1,5 @@
1
1
  import { IPagingParams, IPagedResponse as IRestPagedResponse, IUser } from "@esri/arcgis-rest-portal";
2
- import { Geometry, Polygon } from "geojson";
2
+ import type { Geometry, Polygon } from "geojson";
3
3
  import { IHubRequestOptions } from "../../hub-types";
4
4
  /**
5
5
  * sort orders
@@ -1,7 +1,7 @@
1
1
  import type { IExtent } from "@esri/arcgis-rest-feature-service";
2
2
  import type { IPoint, IPolygon } from "@esri/arcgis-rest-request";
3
3
  import { IHubRequestOptions, BBox } from "./hub-types";
4
- import { Polygon } from "geojson";
4
+ import type { Polygon } from "geojson";
5
5
  /**
6
6
  * Turns an bounding box coordinate array into an extent object
7
7
  * @param bBox bounding box coordinate array
@@ -8,3 +8,9 @@ import { IModel } from "../hub-types";
8
8
  * @returns
9
9
  */
10
10
  export declare function fetchModelFromItem(item: IItem, requestOptions: IRequestOptions): Promise<IModel>;
11
+ /**
12
+ * Determine if we should attempt to fetch the item data
13
+ * @param item
14
+ * @returns
15
+ */
16
+ export declare function shouldFetchItemData(item: IItem): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esri/hub-common",
3
- "version": "20.16.2",
3
+ "version": "20.16.4",
4
4
  "description": "Common TypeScript types and utility functions for @esri/hub.js.",
5
5
  "main": "dist/node/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -17,6 +17,7 @@
17
17
  "adlib": "^3.0.8",
18
18
  "ajv": "^6.12.6",
19
19
  "fast-xml-parser": "^3.21.0",
20
+ "geojson": "^0.5.0",
20
21
  "json-schema-typed": "^7.0.3",
21
22
  "jsonapi-typescript": "^0.1.3",
22
23
  "tslib": "^1.13.0"