@esri/hub-common 9.25.0 → 9.25.3

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.
Files changed (51) hide show
  1. package/dist/es2017/content/_fetch.js +16 -3
  2. package/dist/es2017/content/_fetch.js.map +1 -1
  3. package/dist/es2017/content/_internal.js +7 -17
  4. package/dist/es2017/content/_internal.js.map +1 -1
  5. package/dist/es2017/content/compose.js +11 -15
  6. package/dist/es2017/content/compose.js.map +1 -1
  7. package/dist/es2017/content/fetch.js +27 -23
  8. package/dist/es2017/content/fetch.js.map +1 -1
  9. package/dist/es2017/items/_enrichments.js +29 -14
  10. package/dist/es2017/items/_enrichments.js.map +1 -1
  11. package/dist/es2017/search/utils.js +3 -0
  12. package/dist/es2017/search/utils.js.map +1 -1
  13. package/dist/es2017/utils/_array.js +13 -0
  14. package/dist/es2017/utils/_array.js.map +1 -0
  15. package/dist/esm/content/_fetch.js +14 -3
  16. package/dist/esm/content/_fetch.js.map +1 -1
  17. package/dist/esm/content/_internal.js +7 -17
  18. package/dist/esm/content/_internal.js.map +1 -1
  19. package/dist/esm/content/compose.js +12 -14
  20. package/dist/esm/content/compose.js.map +1 -1
  21. package/dist/esm/content/fetch.js +40 -31
  22. package/dist/esm/content/fetch.js.map +1 -1
  23. package/dist/esm/items/_enrichments.js +29 -14
  24. package/dist/esm/items/_enrichments.js.map +1 -1
  25. package/dist/esm/search/utils.js +3 -0
  26. package/dist/esm/search/utils.js.map +1 -1
  27. package/dist/esm/utils/_array.js +13 -0
  28. package/dist/esm/utils/_array.js.map +1 -0
  29. package/dist/node/content/_fetch.js +16 -3
  30. package/dist/node/content/_fetch.js.map +1 -1
  31. package/dist/node/content/_internal.js +8 -18
  32. package/dist/node/content/_internal.js.map +1 -1
  33. package/dist/node/content/compose.js +10 -14
  34. package/dist/node/content/compose.js.map +1 -1
  35. package/dist/node/content/fetch.js +27 -23
  36. package/dist/node/content/fetch.js.map +1 -1
  37. package/dist/node/items/_enrichments.js +30 -15
  38. package/dist/node/items/_enrichments.js.map +1 -1
  39. package/dist/node/search/utils.js +3 -0
  40. package/dist/node/search/utils.js.map +1 -1
  41. package/dist/node/utils/_array.js +16 -0
  42. package/dist/node/utils/_array.js.map +1 -0
  43. package/dist/types/content/_fetch.d.ts +9 -4
  44. package/dist/types/content/_internal.d.ts +0 -8
  45. package/dist/types/items/_enrichments.d.ts +10 -1
  46. package/dist/types/utils/_array.d.ts +9 -0
  47. package/dist/umd/common.umd.js +116 -79
  48. package/dist/umd/common.umd.js.map +1 -1
  49. package/dist/umd/common.umd.min.js +1 -1
  50. package/dist/umd/common.umd.min.js.map +1 -1
  51. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /* @preserve
2
- * @esri/hub-common - v9.24.2 - Wed Mar 23 2022 22:47:07 GMT+0000 (Coordinated Universal Time)
2
+ * @esri/hub-common - v9.25.2 - Wed Mar 30 2022 22:05:13 GMT+0000 (Coordinated Universal Time)
3
3
  * Copyright (c) 2022 Environmental Systems Research Institute, Inc.
4
4
  * Apache-2.0
5
5
  */
@@ -6588,23 +6588,12 @@
6588
6588
  }
6589
6589
  return date && precision && { date: date, precision: precision };
6590
6590
  }
6591
- /**
6592
- * Get the spatial reference from layer or server info
6593
- * @param server
6594
- * @param layer
6595
- * @returns
6596
- * @private
6597
- */
6598
- var getServerSpatialReference = function (server, layer) {
6599
- var _a;
6600
- var layerSpatialReference = (_a = layer === null || layer === void 0 ? void 0 : layer.extent) === null || _a === void 0 ? void 0 : _a.spatialReference;
6601
- return layerSpatialReference || (server === null || server === void 0 ? void 0 : server.spatialReference);
6602
- };
6603
6591
  // NOTE: IItem has spatialRefernce: ISpatialReference, but
6604
6592
  // the portal REST API returns spatialReference as as string
6605
- // that is always either WKID like "102100" or
6606
- // WKT like "NAD_1983_HARN_StatePlane_Hawaii_3_FIPS_5103_Feet"
6607
- // so we coerce those string into a ISpatialReference object
6593
+ // that is always either WKID like "102100" or the name of a
6594
+ // WKT like "NAD_1983_HARN_StatePlane_Hawaii_3_FIPS_5103_Feet".
6595
+ // We only coerce WKIDs into a ISpatialReference objects since we
6596
+ // can't easily lookup a complete WKT.
6608
6597
  /**
6609
6598
  * Get the spatial reference as an object for an item
6610
6599
  * @param item
@@ -6622,8 +6611,9 @@
6622
6611
  var spatialReferenceString = spatialReference + "";
6623
6612
  var wkid = parseInt(spatialReferenceString, 10);
6624
6613
  return isNaN(wkid)
6625
- ? // string is not a number, assume it is WKT
6626
- { wkt: spatialReferenceString }
6614
+ ? // It looks like the portal api returns the name of a WKT, but we'd
6615
+ // need to perform a lookup to get the full WKT. Return null for now.
6616
+ null
6627
6617
  : //
6628
6618
  { wkid: wkid };
6629
6619
  };
@@ -7487,7 +7477,7 @@
7487
7477
  return name;
7488
7478
  },
7489
7479
  get description() {
7490
- return searchDescription || _layerDescription || item.description;
7480
+ return _layerDescription || item.description;
7491
7481
  }, type: type, get family() {
7492
7482
  return getFamily(type);
7493
7483
  }, get url() {
@@ -7534,12 +7524,11 @@
7534
7524
  return boundary || getContentBoundary(item);
7535
7525
  },
7536
7526
  get summary() {
7537
- return _layerDescription
7538
- ? _layerDescription
7539
- : // TODO: this should use the logic for the Hub API's searchDescription
7540
- // see: https://github.com/ArcGIS/hub-indexer/blob/b352cfded8221a967ac80447879d493db6476d7a/packages/duke/compose/dataset.js#L238-L250
7541
- // TODO: can we strip HTML from description, and do we need to trim it to a X chars?
7542
- item.snippet || item.description;
7527
+ return (searchDescription ||
7528
+ // TODO: this should use the logic for the Hub API's searchDescription
7529
+ // see: https://github.com/ArcGIS/hub-indexer/blob/b352cfded8221a967ac80447879d493db6476d7a/packages/duke/compose/dataset.js#L238-L250
7530
+ item.snippet ||
7531
+ item.description);
7543
7532
  }, urls: urls, get portalHomeUrl() {
7544
7533
  return urls.portalHome;
7545
7534
  },
@@ -7602,14 +7591,13 @@
7602
7591
  // TODO: is metrics in use?
7603
7592
  get metrics() {
7604
7593
  return item.properties && item.properties.metrics;
7605
- },
7606
- get spatialReference() {
7594
+ }, get spatialReference() {
7595
+ var _a;
7607
7596
  // NOTE: I had to add || null just so packages/content/test/portal.test.ts would pass
7608
7597
  // we can remove that when that package is deprecated
7609
- return (getItemSpatialReference(item) ||
7610
- getServerSpatialReference(server, layer) ||
7611
- null);
7612
- }, get viewDefinition() {
7598
+ return (((_a = layer === null || layer === void 0 ? void 0 : layer.extent) === null || _a === void 0 ? void 0 : _a.spatialReference) || getItemSpatialReference(item) || null);
7599
+ },
7600
+ get viewDefinition() {
7613
7601
  // if this is a layer view and we have the item data
7614
7602
  // find the definition that corresponds to the current layer
7615
7603
  var dataLayer = layer &&
@@ -8755,29 +8743,44 @@
8755
8743
  var handleEnrichmentError = function (error, input, opId) {
8756
8744
  var data = input.data, stack = input.stack, requestOptions = input.requestOptions;
8757
8745
  stack.finish(opId, { error: error });
8758
- var message = typeof error === "string"
8759
- ? /* istanbul ignore next our tests only throw Error objects */
8760
- error
8761
- : error.message;
8762
- var errors = data.errors || [];
8763
- errors.push({
8764
- // NOTE: for now we just return the message and type "Other"
8765
- // but we could later introspect for HTTP or AGO errors
8766
- // and/or return the status code if available
8767
- type: "Other",
8768
- message: message,
8769
- });
8770
- return { data: __assign(__assign({}, data), { errors: errors }), stack: stack, requestOptions: requestOptions };
8746
+ return {
8747
+ data: __assign(__assign({}, data), { errors: getEnrichmentErrors(error, data.errors) }),
8748
+ stack: stack,
8749
+ requestOptions: requestOptions,
8750
+ };
8771
8751
  };
8772
8752
  var enrichmentOperations = {
8773
8753
  groupIds: enrichGroupIds,
8774
8754
  metadata: enrichMetadata,
8775
8755
  ownerUser: enrichOwnerUser,
8776
- // TOOD: org
8777
8756
  data: enrichData,
8778
8757
  server: enrichServer,
8779
8758
  layers: enrichLayers,
8780
8759
  };
8760
+ /**
8761
+ * convert an error to an enrichment error info format
8762
+ * and optionally append it to an existing array of those
8763
+ * @param error
8764
+ * @param errors an array of existing enrichment error info
8765
+ * @returns a new array of enrichment error info
8766
+ * @private
8767
+ */
8768
+ var getEnrichmentErrors = function (error, errors) {
8769
+ if (errors === void 0) { errors = []; }
8770
+ var message = typeof error === "string"
8771
+ ? /* istanbul ignore next our tests only throw Error objects */
8772
+ error
8773
+ : error.message;
8774
+ return __spreadArrays(errors, [
8775
+ {
8776
+ // NOTE: for now we just return the message and type "Other"
8777
+ // but we could later introspect for HTTP or AGO errors
8778
+ // and/or return the status code if available
8779
+ type: "Other",
8780
+ message: message,
8781
+ },
8782
+ ]);
8783
+ };
8781
8784
  /**
8782
8785
  * Fetch enrichments for an item
8783
8786
  * @param item
@@ -8803,6 +8806,19 @@
8803
8806
  }).then(function (output) { return output.data; });
8804
8807
  };
8805
8808
 
8809
+ /**
8810
+ * concat an array of arrays
8811
+ * excluding any elements of the top level array
8812
+ * that are not actually arrays
8813
+ * @param arrays An array of arrays
8814
+ * @returns concatenated array
8815
+ * @private
8816
+ */
8817
+ var maybeConcat = function (arrays) {
8818
+ var result = [].concat.apply([], arrays.filter(Array.isArray));
8819
+ return result.length ? result : undefined;
8820
+ };
8821
+
8806
8822
  /**
8807
8823
  * remote server error
8808
8824
  */
@@ -8906,7 +8922,9 @@
8906
8922
  // that we fetch from the Hub API, and to optionally filter by slug
8907
8923
  var getHubEnrichmentsOptions = function (requestOptions, slug) {
8908
8924
  var opts = cloneObject$1(requestOptions);
8909
- opts.params = __assign(__assign({}, opts.params), { "fields[datasets]": "slug,boundary,extent,searchDescription,statistics" });
8925
+ opts.params = __assign(__assign({}, opts.params), {
8926
+ // TODO: we should fetch errors too
8927
+ "fields[datasets]": "slug,boundary,extent,searchDescription,statistics" });
8910
8928
  if (slug) {
8911
8929
  opts.params["filter[slug]"] = slug;
8912
8930
  }
@@ -8953,13 +8971,21 @@
8953
8971
  * @private
8954
8972
  */
8955
8973
  var fetchHubEnrichmentsById = function (hubId, requestOptions) { return __awaiter(void 0, void 0, void 0, function () {
8956
- var response;
8974
+ var response, e_1;
8957
8975
  return __generator(this, function (_a) {
8958
8976
  switch (_a.label) {
8959
- case 0: return [4 /*yield*/, hubApiRequest("/datasets/" + hubId, getHubEnrichmentsOptions(requestOptions))];
8977
+ case 0:
8978
+ _a.trys.push([0, 2, , 3]);
8979
+ return [4 /*yield*/, hubApiRequest("/datasets/" + hubId, getHubEnrichmentsOptions(requestOptions))];
8960
8980
  case 1:
8961
8981
  response = _a.sent();
8962
8982
  return [2 /*return*/, getDatasetEnrichments(response.data)];
8983
+ case 2:
8984
+ e_1 = _a.sent();
8985
+ // dataset record not found, just log the error
8986
+ // b/c we can still look up the item and enrichments by id
8987
+ return [2 /*return*/, { errors: getEnrichmentErrors(e_1) }];
8988
+ case 3: return [2 /*return*/];
8963
8989
  }
8964
8990
  });
8965
8991
  }); };
@@ -8990,8 +9016,9 @@
8990
9016
  _b.label = 3;
8991
9017
  case 3:
8992
9018
  layerEnrichments = _a;
8993
- // TODO: merge errors
8994
- return [2 /*return*/, __assign(__assign({}, itemAndEnrichments), layerEnrichments)];
9019
+ return [2 /*return*/, __assign(__assign(__assign({}, itemAndEnrichments), layerEnrichments), {
9020
+ // merge error arrays
9021
+ errors: maybeConcat([itemAndEnrichments.errors, layerEnrichments === null || layerEnrichments === void 0 ? void 0 : layerEnrichments.errors]) })];
8995
9022
  }
8996
9023
  });
8997
9024
  }); };
@@ -9011,62 +9038,69 @@
9011
9038
  });
9012
9039
  }); };
9013
9040
  var fetchContentById = function (hubId, options) { return __awaiter(void 0, void 0, void 0, function () {
9014
- var itemId, _a, item, itemEnrichments, specifiedLayerId, _b, slug, layerId, boundary, extent, searchDescription, statistics, _c;
9015
- return __generator(this, function (_d) {
9016
- switch (_d.label) {
9041
+ var itemId, _a, item, itemEnrichments, specifiedLayerId, hubEnrichments, _b, layerId;
9042
+ return __generator(this, function (_c) {
9043
+ switch (_c.label) {
9017
9044
  case 0:
9018
9045
  itemId = parseDatasetId(hubId).itemId;
9019
9046
  return [4 /*yield*/, fetchItemAndEnrichments(itemId, options)];
9020
9047
  case 1:
9021
- _a = _d.sent(), item = _a.item, itemEnrichments = __rest(_a, ["item"]);
9048
+ _a = _c.sent(), item = _a.item, itemEnrichments = __rest(_a, ["item"]);
9022
9049
  specifiedLayerId = options && options.layerId;
9023
9050
  if (!canUseHubApiForItem(item, options)) return [3 /*break*/, 3];
9024
9051
  return [4 /*yield*/, fetchHubEnrichmentsById(hubId, options)];
9025
9052
  case 2:
9026
- _c = _d.sent();
9053
+ _b = _c.sent();
9027
9054
  return [3 /*break*/, 4];
9028
9055
  case 3:
9029
- _c = {};
9030
- _d.label = 4;
9056
+ _b = {};
9057
+ _c.label = 4;
9031
9058
  case 4:
9032
- _b = _c, slug = _b.slug, layerId = _b.layerId, boundary = _b.boundary, extent = _b.extent, searchDescription = _b.searchDescription, statistics = _b.statistics;
9059
+ hubEnrichments = _b;
9060
+ layerId = hubEnrichments.layerId;
9033
9061
  // return a new content object composed from the item and enrichments we fetched
9034
- return [2 /*return*/, composeContent(item, __assign(__assign({ requestOptions: options }, itemEnrichments), { slug: slug, layerId: isNil(specifiedLayerId) ? layerId : specifiedLayerId, boundary: boundary,
9035
- extent: extent,
9036
- searchDescription: searchDescription,
9037
- statistics: statistics }))];
9062
+ return [2 /*return*/, composeContent(item, __assign(__assign(__assign({ requestOptions: options }, itemEnrichments), hubEnrichments), {
9063
+ // prefer specified layer id if any
9064
+ layerId: isNil(specifiedLayerId) ? layerId : specifiedLayerId,
9065
+ // merge error arrays
9066
+ errors: maybeConcat([itemEnrichments.errors, hubEnrichments.errors]) }))];
9038
9067
  }
9039
9068
  });
9040
9069
  }); };
9041
9070
  var fetchContentBySlug = function (fullyQualifiedSlug, options) { return __awaiter(void 0, void 0, void 0, function () {
9042
- var hubEnrichments, itemId, layerId, _a, item, itemEnrichments, specifiedLayerId, boundary, extent, searchDescription, statistics;
9043
- return __generator(this, function (_b) {
9044
- switch (_b.label) {
9071
+ var hubEnrichments, itemId, layerId, _a, item, itemEnrichments, specifiedLayerId, _b;
9072
+ return __generator(this, function (_c) {
9073
+ switch (_c.label) {
9045
9074
  case 0: return [4 /*yield*/, fetchHubEnrichmentsBySlug(fullyQualifiedSlug, options)];
9046
9075
  case 1:
9047
- hubEnrichments = _b.sent();
9076
+ hubEnrichments = _c.sent();
9048
9077
  itemId = hubEnrichments.itemId;
9049
9078
  layerId = hubEnrichments.layerId;
9050
9079
  return [4 /*yield*/, fetchItemAndEnrichments(itemId, options)];
9051
9080
  case 2:
9052
- _a = _b.sent(), item = _a.item, itemEnrichments = __rest(_a, ["item"]);
9081
+ _a = _c.sent(), item = _a.item, itemEnrichments = __rest(_a, ["item"]);
9053
9082
  specifiedLayerId = options && options.layerId;
9054
9083
  if (!(!isNil(specifiedLayerId) && specifiedLayerId !== layerId)) return [3 /*break*/, 4];
9055
- // we fetched Hub enrichments by slug for another dataset,
9056
- // most likely for the parent service of this layer,
9057
- // we need to fetch them for the specified layer instead
9084
+ // we fetched Hub enrichments by slug for another record,
9085
+ // most likely the record for the parent service of this layer,
9086
+ // so we need to fetch them for the specified layer instead
9058
9087
  layerId = specifiedLayerId;
9088
+ _b = [__assign({}, hubEnrichments)];
9059
9089
  return [4 /*yield*/, fetchHubEnrichmentsById(itemId + "_" + layerId, options)];
9060
9090
  case 3:
9061
- hubEnrichments = _b.sent();
9062
- _b.label = 4;
9063
- case 4:
9064
- boundary = hubEnrichments.boundary, extent = hubEnrichments.extent, searchDescription = hubEnrichments.searchDescription, statistics = hubEnrichments.statistics;
9065
- // return a new content object composed from the item and enrichments we fetched
9066
- return [2 /*return*/, composeContent(item, __assign(__assign({ requestOptions: options }, itemEnrichments), { layerId: layerId, slug: fullyQualifiedSlug, boundary: boundary,
9067
- extent: extent,
9068
- searchDescription: searchDescription,
9069
- statistics: statistics }))];
9091
+ hubEnrichments = __assign.apply(void 0, _b.concat([(_c.sent())]));
9092
+ _c.label = 4;
9093
+ case 4: return [2 /*return*/, composeContent(item, __assign(__assign(__assign({ requestOptions: options }, itemEnrichments), hubEnrichments), { layerId: layerId,
9094
+ // Note that we are not extracting the slug for the specified layer.
9095
+ // It seems that the old client composer code always populated the slug
9096
+ // field with the slug that was passed into the function (typically the
9097
+ // slug of the parent service). To maintain parity, we do the same here.
9098
+ //
9099
+ // TODO: should we prefer the slug of the fetched layer instead?
9100
+ // return a new content object composed from the item and enrichments we fetched
9101
+ slug: fullyQualifiedSlug,
9102
+ // merge error arrays
9103
+ errors: maybeConcat([itemEnrichments.errors, hubEnrichments.errors]) }))];
9070
9104
  }
9071
9105
  });
9072
9106
  }); };
@@ -11638,6 +11672,9 @@
11638
11672
  break;
11639
11673
  case "months":
11640
11674
  // get the current month and subtract num
11675
+ // NOTE: when the previous month has fewer days than this month
11676
+ // setMonth() will return a date w/in the current month
11677
+ // example: 3/30 -> 3/2 b/c there is no 2/28
11641
11678
  now.setMonth(now.getMonth() - relative.num);
11642
11679
  result.from = now.getTime();
11643
11680
  break;