@esri/hub-common 9.9.0 → 9.10.0

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 (36) hide show
  1. package/dist/es2017/content/_internal.js +64 -0
  2. package/dist/es2017/content/_internal.js.map +1 -0
  3. package/dist/es2017/{content.js → content/index.js} +12 -20
  4. package/dist/es2017/content/index.js.map +1 -0
  5. package/dist/es2017/extent.js +49 -16
  6. package/dist/es2017/extent.js.map +1 -1
  7. package/dist/es2017/objects/deep-set.js +1 -1
  8. package/dist/es2017/objects/deep-set.js.map +1 -1
  9. package/dist/esm/content/_internal.js +65 -0
  10. package/dist/esm/content/_internal.js.map +1 -0
  11. package/dist/esm/{content.js → content/index.js} +12 -20
  12. package/dist/esm/content/index.js.map +1 -0
  13. package/dist/esm/extent.js +44 -11
  14. package/dist/esm/extent.js.map +1 -1
  15. package/dist/esm/objects/deep-set.js +1 -1
  16. package/dist/esm/objects/deep-set.js.map +1 -1
  17. package/dist/node/content/_internal.js +67 -0
  18. package/dist/node/content/_internal.js.map +1 -0
  19. package/dist/node/{content.js → content/index.js} +12 -20
  20. package/dist/node/content/index.js.map +1 -0
  21. package/dist/node/extent.js +50 -17
  22. package/dist/node/extent.js.map +1 -1
  23. package/dist/node/objects/deep-set.js +1 -1
  24. package/dist/node/objects/deep-set.js.map +1 -1
  25. package/dist/types/content/_internal.d.ts +91 -0
  26. package/dist/types/{content.d.ts → content/index.d.ts} +2 -2
  27. package/dist/types/extent.d.ts +11 -4
  28. package/dist/types/types.d.ts +4 -1
  29. package/dist/umd/common.umd.js +101 -25
  30. package/dist/umd/common.umd.js.map +1 -1
  31. package/dist/umd/common.umd.min.js +1 -1
  32. package/dist/umd/common.umd.min.js.map +1 -1
  33. package/package.json +2 -2
  34. package/dist/es2017/content.js.map +0 -1
  35. package/dist/esm/content.js.map +0 -1
  36. package/dist/node/content.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /* @preserve
2
- * @esri/hub-common - v9.8.1 - Tue Dec 14 2021 12:30:36 GMT-0500 (Eastern Standard Time)
2
+ * @esri/hub-common - v9.9.0 - Wed Dec 22 2021 11:46:07 GMT-0800 (Pacific Standard Time)
3
3
  * Copyright (c) 2021 Environmental Systems Research Institute, Inc.
4
4
  * Apache-2.0
5
5
  */
@@ -528,7 +528,7 @@
528
528
  var worker = target;
529
529
  var lastIdx = parts.length - 1;
530
530
  parts.forEach(function (p, idx) {
531
- if (!worker.hasOwnProperty(p) || worker[p] === null) {
531
+ if (!worker.hasOwnProperty(p) || worker[p] == null) {
532
532
  if (idx === lastIdx) {
533
533
  worker[p] = value;
534
534
  }
@@ -5169,8 +5169,8 @@
5169
5169
  ymax: ymax,
5170
5170
  // type: 'extent',
5171
5171
  spatialReference: {
5172
- wkid: wkid
5173
- }
5172
+ wkid: wkid,
5173
+ },
5174
5174
  };
5175
5175
  }
5176
5176
  /**
@@ -5178,7 +5178,10 @@
5178
5178
  * @param envelope extent
5179
5179
  */
5180
5180
  function extentToBBox(envelope) {
5181
- return [[envelope.xmin, envelope.ymin], [envelope.xmax, envelope.ymax]];
5181
+ return [
5182
+ [envelope.xmin, envelope.ymin],
5183
+ [envelope.xmax, envelope.ymax],
5184
+ ];
5182
5185
  }
5183
5186
  var GLOBAL_EXTENT = {
5184
5187
  xmin: -180,
@@ -5186,8 +5189,8 @@
5186
5189
  xmax: 180,
5187
5190
  ymax: 90,
5188
5191
  spatialReference: {
5189
- wkid: 4326
5190
- }
5192
+ wkid: 4326,
5193
+ },
5191
5194
  };
5192
5195
  /**
5193
5196
  * Gets the geographic extent for an org
@@ -5208,7 +5211,7 @@
5208
5211
  // geometry params...
5209
5212
  var geometryParam = {
5210
5213
  geometryType: "esriGeometryEnvelope",
5211
- geometries: [orgExtent]
5214
+ geometries: [orgExtent],
5212
5215
  };
5213
5216
  var options = {
5214
5217
  httpMethod: "POST",
@@ -5218,8 +5221,8 @@
5218
5221
  transformation: "",
5219
5222
  inSR: orgExtent.spatialReference.wkid,
5220
5223
  outSR: 4326,
5221
- f: "json"
5222
- }
5224
+ f: "json",
5225
+ },
5223
5226
  };
5224
5227
  // add in auth if it's passed
5225
5228
  if (hubRequestOptions.authentication) {
@@ -5234,8 +5237,8 @@
5234
5237
  xmax: geom.xmax,
5235
5238
  ymax: geom.ymax,
5236
5239
  spatialReference: {
5237
- wkid: 4326
5238
- }
5240
+ wkid: 4326,
5241
+ },
5239
5242
  };
5240
5243
  })
5241
5244
  .catch(function (ex) {
@@ -5251,10 +5254,21 @@
5251
5254
  return extentToBBox(extent);
5252
5255
  });
5253
5256
  }
5254
- function isExtentCoordinateArray(extent) {
5257
+ /**
5258
+ * checks if the extent is a valid BBox (2 element array of coordinate pair arrays)
5259
+ * @param extent
5260
+ * @returns
5261
+ */
5262
+ var isBBox = function (extent) {
5255
5263
  return (Array.isArray(extent) &&
5256
5264
  Array.isArray(extent[0]) &&
5257
5265
  Array.isArray(extent[1]));
5266
+ };
5267
+ function isExtentCoordinateArray(extent) {
5268
+ /* tslint:disable no-console */
5269
+ console.warn("DEPRECATED: use isBBox() instead");
5270
+ /* tslint:enable no-console */
5271
+ return isBBox(extent);
5258
5272
  }
5259
5273
  function isExtentJSON(extent) {
5260
5274
  return ["xmin", "ymin", "xmax", "ymax"].every(function (key) { return typeof extent[key] === "number"; });
@@ -5268,6 +5282,25 @@
5268
5282
  return (!!extent &&
5269
5283
  [isExtentCoordinateArray, isExtentJSON].some(function (test) { return test(extent); }));
5270
5284
  }
5285
+ var bBoxToPolygon = function (bBox) {
5286
+ var _a = bBox[0], xmin = _a[0], ymin = _a[1], _b = bBox[1], xmax = _b[0], ymax = _b[1];
5287
+ var rings = [
5288
+ [
5289
+ [xmin, ymin],
5290
+ [xmax, ymin],
5291
+ [xmax, ymax],
5292
+ [xmin, ymax],
5293
+ [xmin, ymin],
5294
+ ],
5295
+ ];
5296
+ var wkid = 4326;
5297
+ return {
5298
+ rings: rings,
5299
+ spatialReference: {
5300
+ wkid: wkid,
5301
+ },
5302
+ };
5303
+ };
5271
5304
 
5272
5305
  var STANDARD_LICENSES = [
5273
5306
  {
@@ -5564,6 +5597,56 @@
5564
5597
  return isSingleAnchorTagRegex.test(rawLicense);
5565
5598
  }
5566
5599
 
5600
+ /**
5601
+ * Use this module for functions that do not need to be used by consumers (yet),
5602
+ * but may be shared between hub.js modules, and/or need to be tested
5603
+ * to get 100% coverage w/o writing cumbersome tests of higher level functions.
5604
+ *
5605
+ * Consuming will not be able to import these functions.
5606
+ *
5607
+ * It's probably a good pattern to add functions here first and then
5608
+ * move them to index.ts only when they are needed by a consumer.
5609
+ */
5610
+ /**
5611
+ * Create a new content with updated extent and derived properties like boundary
5612
+ * @param content original content
5613
+ * @param extent new extent
5614
+ * @returns a new content with the updated extent and boundary
5615
+ */
5616
+ var setContentExtent = function (content, extent) {
5617
+ // update content's item and extent
5618
+ var item = __assign(__assign({}, content.item), { extent: extent });
5619
+ var updated = __assign(__assign({}, content), { item: item, extent: extent });
5620
+ // derive boundary from content properties
5621
+ var boundary = getContentBoundary(updated);
5622
+ return __assign(__assign({}, updated), { boundary: boundary });
5623
+ };
5624
+ var getContentBoundary = function (content) {
5625
+ var _a;
5626
+ var item = content.item;
5627
+ var extent = item.extent;
5628
+ var isValidItemExtent = isBBox(extent);
5629
+ // user specified provenance is stored in item.properties
5630
+ var provenance = ((_a = item.properties) === null || _a === void 0 ? void 0 : _a.boundary) ||
5631
+ // but we default to item if the item has an extent
5632
+ (isValidItemExtent ? "item" : undefined);
5633
+ var geometry;
5634
+ switch (provenance) {
5635
+ case "item":
5636
+ geometry = isValidItemExtent ? bBoxToPolygon(extent) : null;
5637
+ break;
5638
+ case "none":
5639
+ geometry = null;
5640
+ break;
5641
+ // TODO: handle other provenances
5642
+ }
5643
+ // TODO: derive and return center
5644
+ return {
5645
+ provenance: provenance,
5646
+ geometry: geometry,
5647
+ };
5648
+ };
5649
+
5567
5650
  function collectionToFamily(collection) {
5568
5651
  var overrides = {
5569
5652
  other: "content",
@@ -5571,13 +5654,6 @@
5571
5654
  };
5572
5655
  return overrides[collection] || collection;
5573
5656
  }
5574
- function itemExtentToBoundary(extent) {
5575
- return (extent &&
5576
- extent.length && {
5577
- // TODO: center?
5578
- geometry: createExtent(extent[0][0], extent[0][1], extent[1][0], extent[1][1]),
5579
- });
5580
- }
5581
5657
  var cache = {};
5582
5658
  // TODO: remove this at next breaking version
5583
5659
  /**
@@ -5977,7 +6053,6 @@
5977
6053
  metrics: properties && properties.metrics,
5978
6054
  isDownloadable: isDownloadable(item),
5979
6055
  // default boundary from item.extent
5980
- boundary: itemExtentToBoundary(item.extent),
5981
6056
  license: { name: "Custom License", description: item.accessInformation },
5982
6057
  // dates and sources we will enrich these later...
5983
6058
  createdDate: createdDate,
@@ -5988,7 +6063,7 @@
5988
6063
  updatedDateSource: "item.modified",
5989
6064
  structuredLicense: getStructuredLicense(item.licenseInfo),
5990
6065
  });
5991
- return setContentType(content, item.type);
6066
+ return setContentExtent(setContentType(content, item.type), item.extent);
5992
6067
  }
5993
6068
  /**
5994
6069
  * Convert a Hub API dataset resource to Hub Content
@@ -6031,9 +6106,7 @@
6031
6106
  content.errors = errors;
6032
6107
  // common enrichments
6033
6108
  content.boundary = boundary;
6034
- if (!isExtentCoordinateArray(item.extent) &&
6035
- extent &&
6036
- isExtentCoordinateArray(extent.coordinates)) {
6109
+ if (!isBBox(item.extent) && extent && isBBox(extent.coordinates)) {
6037
6110
  // we fall back to the extent derived by the API
6038
6111
  // which prefers layer or service extents and ultimately
6039
6112
  // falls back to the org's extent
@@ -6189,6 +6262,7 @@
6189
6262
  // get family and normalized type based on new type
6190
6263
  var normalizedType = normalizeItemType(__assign(__assign({}, content.item), { type: type }));
6191
6264
  var family = getFamily(normalizedType);
6265
+ // TODO: don't we need to update content.item.type too?
6192
6266
  var updated = __assign(__assign({}, content), { type: type, family: family, normalizedType: normalizedType });
6193
6267
  // update the relative URL to the content
6194
6268
  // which is based on type and family
@@ -10735,6 +10809,7 @@
10735
10809
  exports.arrayToObject = arrayToObject;
10736
10810
  exports.atob = abab.atob;
10737
10811
  exports.autoAddUsers = autoAddUsers;
10812
+ exports.bBoxToPolygon = bBoxToPolygon;
10738
10813
  exports.batch = batch;
10739
10814
  exports.btoa = abab.btoa;
10740
10815
  exports.buildDraft = buildDraft;
@@ -10850,6 +10925,7 @@
10850
10925
  exports.interpolate = interpolate;
10851
10926
  exports.interpolateItemId = interpolateItemId;
10852
10927
  exports.inviteUsers = inviteUsers;
10928
+ exports.isBBox = isBBox;
10853
10929
  exports.isDomainForLegacySite = isDomainForLegacySite;
10854
10930
  exports.isDomainUsedElsewhere = isDomainUsedElsewhere;
10855
10931
  exports.isDownloadable = isDownloadable;