@esri/hub-common 9.26.2 → 9.29.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 (108) hide show
  1. package/dist/es2017/search/_internal/index.js +3 -0
  2. package/dist/es2017/search/_internal/index.js.map +1 -0
  3. package/dist/es2017/search/_internal/searchContentEntities.js +15 -5
  4. package/dist/es2017/search/_internal/searchContentEntities.js.map +1 -1
  5. package/dist/es2017/search/_internal/state.js +147 -0
  6. package/dist/es2017/search/_internal/state.js.map +1 -0
  7. package/dist/es2017/search/_searchContent.js +11 -4
  8. package/dist/es2017/search/_searchContent.js.map +1 -1
  9. package/dist/es2017/search/collectionState.js +60 -0
  10. package/dist/es2017/search/collectionState.js.map +1 -0
  11. package/dist/es2017/search/content-utils.js +14 -7
  12. package/dist/es2017/search/content-utils.js.map +1 -1
  13. package/dist/es2017/search/convertCatalog.js +23 -0
  14. package/dist/es2017/search/convertCatalog.js.map +1 -0
  15. package/dist/es2017/search/index.js +3 -1
  16. package/dist/es2017/search/index.js.map +1 -1
  17. package/dist/es2017/search/types/ICatalog.js +1 -0
  18. package/dist/es2017/search/types/ICatalog.js.map +1 -0
  19. package/dist/es2017/search/types/ICollection.js +1 -0
  20. package/dist/es2017/search/types/ICollection.js.map +1 -0
  21. package/dist/es2017/search/types/IFacet.js +1 -0
  22. package/dist/es2017/search/types/IFacet.js.map +1 -0
  23. package/dist/es2017/search/types/IFacetOption.js +1 -0
  24. package/dist/es2017/search/types/IFacetOption.js.map +1 -0
  25. package/dist/es2017/search/types/index.js +6 -0
  26. package/dist/es2017/search/types/index.js.map +1 -0
  27. package/dist/es2017/search/{types.js → types/types.js} +0 -0
  28. package/dist/{node/search → es2017/search/types}/types.js.map +1 -1
  29. package/dist/es2017/search/utils.js.map +1 -1
  30. package/dist/esm/search/_internal/index.js +3 -0
  31. package/dist/esm/search/_internal/index.js.map +1 -0
  32. package/dist/esm/search/_internal/searchContentEntities.js +15 -6
  33. package/dist/esm/search/_internal/searchContentEntities.js.map +1 -1
  34. package/dist/esm/search/_internal/state.js +147 -0
  35. package/dist/esm/search/_internal/state.js.map +1 -0
  36. package/dist/esm/search/_searchContent.js +12 -5
  37. package/dist/esm/search/_searchContent.js.map +1 -1
  38. package/dist/esm/search/collectionState.js +61 -0
  39. package/dist/esm/search/collectionState.js.map +1 -0
  40. package/dist/esm/search/content-utils.js +15 -7
  41. package/dist/esm/search/content-utils.js.map +1 -1
  42. package/dist/esm/search/convertCatalog.js +23 -0
  43. package/dist/esm/search/convertCatalog.js.map +1 -0
  44. package/dist/esm/search/index.js +3 -1
  45. package/dist/esm/search/index.js.map +1 -1
  46. package/dist/esm/search/types/ICatalog.js +1 -0
  47. package/dist/esm/search/types/ICatalog.js.map +1 -0
  48. package/dist/esm/search/types/ICollection.js +1 -0
  49. package/dist/esm/search/types/ICollection.js.map +1 -0
  50. package/dist/esm/search/types/IFacet.js +1 -0
  51. package/dist/esm/search/types/IFacet.js.map +1 -0
  52. package/dist/esm/search/types/IFacetOption.js +1 -0
  53. package/dist/esm/search/types/IFacetOption.js.map +1 -0
  54. package/dist/esm/search/types/index.js +6 -0
  55. package/dist/esm/search/types/index.js.map +1 -0
  56. package/dist/esm/search/{types.js → types/types.js} +0 -0
  57. package/dist/{es2017/search → esm/search/types}/types.js.map +1 -1
  58. package/dist/esm/search/utils.js.map +1 -1
  59. package/dist/node/search/_internal/index.js +6 -0
  60. package/dist/node/search/_internal/index.js.map +1 -0
  61. package/dist/node/search/_internal/searchContentEntities.js +14 -4
  62. package/dist/node/search/_internal/searchContentEntities.js.map +1 -1
  63. package/dist/node/search/_internal/state.js +158 -0
  64. package/dist/node/search/_internal/state.js.map +1 -0
  65. package/dist/node/search/_searchContent.js +13 -6
  66. package/dist/node/search/_searchContent.js.map +1 -1
  67. package/dist/node/search/collectionState.js +65 -0
  68. package/dist/node/search/collectionState.js.map +1 -0
  69. package/dist/node/search/content-utils.js +14 -7
  70. package/dist/node/search/content-utils.js.map +1 -1
  71. package/dist/node/search/convertCatalog.js +27 -0
  72. package/dist/node/search/convertCatalog.js.map +1 -0
  73. package/dist/node/search/index.js +3 -1
  74. package/dist/node/search/index.js.map +1 -1
  75. package/dist/node/search/types/ICatalog.js +3 -0
  76. package/dist/node/search/types/ICatalog.js.map +1 -0
  77. package/dist/node/search/types/ICollection.js +3 -0
  78. package/dist/node/search/types/ICollection.js.map +1 -0
  79. package/dist/node/search/types/IFacet.js +3 -0
  80. package/dist/node/search/types/IFacet.js.map +1 -0
  81. package/dist/node/search/types/IFacetOption.js +3 -0
  82. package/dist/node/search/types/IFacetOption.js.map +1 -0
  83. package/dist/node/search/types/index.js +9 -0
  84. package/dist/node/search/types/index.js.map +1 -0
  85. package/dist/node/search/{types.js → types/types.js} +0 -0
  86. package/dist/{esm/search → node/search/types}/types.js.map +1 -1
  87. package/dist/node/search/utils.js.map +1 -1
  88. package/dist/types/core/types/IHubEntityManager.d.ts +1 -1
  89. package/dist/types/search/_internal/index.d.ts +2 -0
  90. package/dist/types/search/_internal/searchContentEntities.d.ts +1 -1
  91. package/dist/types/search/_internal/state.d.ts +62 -0
  92. package/dist/types/search/_searchGroups.d.ts +1 -1
  93. package/dist/types/search/collectionState.d.ts +19 -0
  94. package/dist/types/search/content-utils.d.ts +6 -4
  95. package/dist/types/search/convertCatalog.d.ts +6 -0
  96. package/dist/types/search/index.d.ts +3 -1
  97. package/dist/types/search/types/ICatalog.d.ts +76 -0
  98. package/dist/types/search/types/ICollection.d.ts +14 -0
  99. package/dist/types/search/types/IFacet.d.ts +15 -0
  100. package/dist/types/search/types/IFacetOption.d.ts +8 -0
  101. package/dist/types/search/types/index.d.ts +5 -0
  102. package/dist/types/search/{types.d.ts → types/types.d.ts} +23 -86
  103. package/dist/types/search/utils.d.ts +1 -1
  104. package/dist/umd/common.umd.js +256 -17
  105. package/dist/umd/common.umd.js.map +1 -1
  106. package/dist/umd/common.umd.min.js +1 -1
  107. package/dist/umd/common.umd.min.js.map +1 -1
  108. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /* @preserve
2
- * @esri/hub-common - v9.26.1 - Fri Apr 08 2022 17:54:59 GMT+0000 (Coordinated Universal Time)
2
+ * @esri/hub-common - v9.28.0 - Thu Apr 21 2022 15:27:55 GMT+0000 (Coordinated Universal Time)
3
3
  * Copyright (c) 2022 Environmental Systems Research Institute, Inc.
4
4
  * Apache-2.0
5
5
  */
@@ -12110,29 +12110,37 @@
12110
12110
  };
12111
12111
  /**
12112
12112
  * @private
12113
- * Convert portal search response to items
12113
+ * Convert portal search response to facets
12114
+ * Note: Only applicable to a "content" search
12114
12115
  * @param response
12115
12116
  * @returns
12116
12117
  */
12117
- function convertPortalResponseToFacets(response) {
12118
+ function convertPortalResponseToFacets(response, operation) {
12118
12119
  var _a;
12120
+ if (operation === void 0) { operation = "OR"; }
12119
12121
  var result = [];
12120
12122
  if ((_a = response.aggregations) === null || _a === void 0 ? void 0 : _a.counts) {
12121
12123
  response.aggregations.counts.forEach(function (entry) {
12122
12124
  var facet = {
12123
12125
  label: entry.fieldName,
12124
- attribute: entry.fieldName,
12125
- type: "multi-select",
12126
+ key: entry.fieldName,
12127
+ aggField: entry.fieldName,
12128
+ display: "multi-select",
12126
12129
  };
12127
12130
  var options = [];
12128
12131
  entry.fieldValues.forEach(function (fv) {
12129
12132
  var filter = {
12130
12133
  filterType: "content",
12131
12134
  };
12132
- filter[entry.fieldName] = fv.value;
12135
+ // construct the filter based on the operation
12136
+ var matchKey = operation === "OR" ? "any" : "all";
12137
+ var filterMatchOption = {};
12138
+ filterMatchOption[matchKey] = [fv.value];
12139
+ filter[entry.fieldName] = filterMatchOption;
12140
+ // construct the FacetOption
12133
12141
  var fo = {
12134
- label: fv.value,
12135
- value: fv.value,
12142
+ label: fv.value + " (" + fv.count + ")",
12143
+ key: fv.value,
12136
12144
  count: fv.count,
12137
12145
  selected: false,
12138
12146
  filter: filter,
@@ -12406,14 +12414,22 @@
12406
12414
  * @returns
12407
12415
  */
12408
12416
  function searchContentEntities(filter, convertFn, options) {
12409
- var _a;
12417
+ var _a, _b;
12410
12418
  // expand filter so we can serialize to either api
12411
12419
  var expanded = expandContentFilter(filter);
12412
12420
  var searchOptions = serializeContentFilterForPortal(expanded);
12413
- // Aggregations
12421
+ // DEPRECATION
12422
+ /* istanbul ignore next */
12414
12423
  if ((_a = options.aggregations) === null || _a === void 0 ? void 0 : _a.length) {
12424
+ // tslint:disable-next-line:no-console
12425
+ console.warn("IHubSearchOptions.aggregations is deprecated. Please use .aggFields instead.");
12415
12426
  searchOptions.countFields = options.aggregations.join(",");
12416
- searchOptions.countSize = 200;
12427
+ searchOptions.countSize = options.aggLimit || 10;
12428
+ }
12429
+ // Aggregations
12430
+ if ((_b = options.aggFields) === null || _b === void 0 ? void 0 : _b.length) {
12431
+ searchOptions.countFields = options.aggFields.join(",");
12432
+ searchOptions.countSize = options.aggLimit || 10;
12417
12433
  }
12418
12434
  // properties to copy from IHubSearchOptions to the ISearchOptions
12419
12435
  var props = [
@@ -12455,7 +12471,7 @@
12455
12471
  // referenced in the `next` section below
12456
12472
  return function searchEntities(searchOptions) {
12457
12473
  return __awaiter(this, void 0, void 0, function () {
12458
- var response, entities;
12474
+ var response, entities, facets;
12459
12475
  return __generator(this, function (_a) {
12460
12476
  switch (_a.label) {
12461
12477
  case 0: return [4 /*yield*/, searchItems(searchOptions)];
@@ -12466,10 +12482,11 @@
12466
12482
  }))];
12467
12483
  case 2:
12468
12484
  entities = _a.sent();
12485
+ facets = convertPortalResponseToFacets(response);
12469
12486
  return [2 /*return*/, {
12470
12487
  total: response.total,
12471
12488
  results: entities,
12472
- facets: [],
12489
+ facets: facets,
12473
12490
  hasNext: response.nextStart > -1,
12474
12491
  next: getNextFunction(searchOptions, response.nextStart, response.total, searchEntities),
12475
12492
  }];
@@ -14781,10 +14798,10 @@
14781
14798
  * @param options
14782
14799
  */
14783
14800
  function _searchContent(filter, options) {
14784
- var _a;
14801
+ var _a, _b;
14785
14802
  return __awaiter(this, void 0, void 0, function () {
14786
14803
  var expanded, api, searchPromise, so_1, props;
14787
- return __generator(this, function (_b) {
14804
+ return __generator(this, function (_c) {
14788
14805
  expanded = expandContentFilter(filter);
14789
14806
  api = expandApi(options.api || "arcgis");
14790
14807
  // Portal Search
@@ -14808,10 +14825,17 @@
14808
14825
  if (!so_1.authentication) {
14809
14826
  so_1.portal = api.url + "/sharing/rest";
14810
14827
  }
14811
- // Aggregations
14828
+ // DEPRECATION
14812
14829
  if ((_a = options.aggregations) === null || _a === void 0 ? void 0 : _a.length) {
14830
+ // tslint:disable-next-line:no-console
14831
+ console.warn("IHubSearchOptions.aggregations is deprecated. Please use .aggFields instead.");
14813
14832
  so_1.countFields = options.aggregations.join(",");
14814
- so_1.countSize = 200;
14833
+ so_1.countSize = options.aggLimit || 10;
14834
+ }
14835
+ // Aggregations
14836
+ if ((_b = options.aggFields) === null || _b === void 0 ? void 0 : _b.length) {
14837
+ so_1.countFields = options.aggFields.join(",");
14838
+ so_1.countSize = options.aggLimit || 10;
14815
14839
  }
14816
14840
  searchPromise = searchPortal(so_1);
14817
14841
  }
@@ -15042,6 +15066,218 @@
15042
15066
  });
15043
15067
  }
15044
15068
 
15069
+ /**
15070
+ * Apply the sortState to SortOptions
15071
+ *
15072
+ * @param sortOptions
15073
+ * @param sortState
15074
+ * @returns
15075
+ */
15076
+ function applySortState(sortOptions, sortState) {
15077
+ var updated = cloneObject$1(sortOptions);
15078
+ if (sortState) {
15079
+ var _a = sortState.split("|"), label = _a[0], attribute = _a[1], order = _a[2];
15080
+ updated.label = label;
15081
+ updated.attribute = attribute;
15082
+ updated.order = order;
15083
+ }
15084
+ return updated;
15085
+ }
15086
+ /**
15087
+ * Apply FacetState to a Facet
15088
+ * @param facet
15089
+ * @param state
15090
+ * @returns
15091
+ */
15092
+ function applyFacetState(facet, state) {
15093
+ var updated = cloneObject$1(facet);
15094
+ switch (facet.display) {
15095
+ case "single-select":
15096
+ updated = applySingleSelectFacetState(facet, state);
15097
+ break;
15098
+ case "multi-select":
15099
+ updated = applyMultiSelectFacetState(facet, state);
15100
+ break;
15101
+ }
15102
+ return updated;
15103
+ }
15104
+ /**
15105
+ * Apply the Facet State onto a single-select facet
15106
+ *
15107
+ * Intentionally mutates the facet.
15108
+ * @param facet
15109
+ * @param state
15110
+ * @returns
15111
+ */
15112
+ function applySingleSelectFacetState(facet, state) {
15113
+ var updated = cloneObject$1(facet);
15114
+ updated.options = updated.options.map(function (o) {
15115
+ o.selected = o.key === state[facet.key];
15116
+ return o;
15117
+ });
15118
+ return updated;
15119
+ }
15120
+ /**
15121
+ * Serialize single-select facet into IFacetState
15122
+ * @param facet
15123
+ * @returns
15124
+ */
15125
+ function serializeSingleSelectFacetState(facet) {
15126
+ var state = {};
15127
+ var selected = facet.options.find(function (o) { return o.selected; });
15128
+ if (selected) {
15129
+ state[facet.key] = selected.key;
15130
+ }
15131
+ else {
15132
+ state[facet.key] = null;
15133
+ }
15134
+ return state;
15135
+ }
15136
+ /**
15137
+ * Apply the Facet State onto a multi-select Facet
15138
+ *
15139
+ * Intentionally mutates the facet.
15140
+ * @param facet
15141
+ * @param state
15142
+ * @returns
15143
+ */
15144
+ function applyMultiSelectFacetState(facet, state) {
15145
+ var _a;
15146
+ var updated = cloneObject$1(facet);
15147
+ var selectedKeys = ((_a = state[facet.key]) === null || _a === void 0 ? void 0 : _a.split(",")) || [];
15148
+ updated.options = updated.options.map(function (o) {
15149
+ o.selected = selectedKeys.includes(o.key);
15150
+ return o;
15151
+ });
15152
+ return updated;
15153
+ }
15154
+ /**
15155
+ * Serialize multi-select facet into IFacetState
15156
+ * @param facet
15157
+ * @returns
15158
+ */
15159
+ function serializeMultiSelectFacetState(facet) {
15160
+ var state = {};
15161
+ var selected = facet.options.filter(function (o) { return o.selected; });
15162
+ var value = selected.map(function (o) { return o.key; }).join(",");
15163
+ if (value.length) {
15164
+ state[facet.key] = value;
15165
+ }
15166
+ else {
15167
+ state[facet.key] = null;
15168
+ }
15169
+ return state;
15170
+ }
15171
+ /**
15172
+ * Serialize the state of the SortOption into a key/value pair
15173
+ *
15174
+ * Called from the Sort component
15175
+ * @param sort
15176
+ * @returns
15177
+ */
15178
+ function serializeSortState(sort) {
15179
+ return sort.label + "|" + sort.attribute + "|" + sort.order;
15180
+ }
15181
+ /**
15182
+ * Serialize the state of a facet into a key/value pair
15183
+ *
15184
+ * Called from the various facet components
15185
+ * @param facet
15186
+ * @returns
15187
+ */
15188
+ function serializeFacetState(facet) {
15189
+ var state = {};
15190
+ switch (facet.display) {
15191
+ case "single-select":
15192
+ state = serializeSingleSelectFacetState(facet);
15193
+ break;
15194
+ case "multi-select":
15195
+ state = serializeMultiSelectFacetState(facet);
15196
+ break;
15197
+ }
15198
+ return state;
15199
+ }
15200
+
15201
+ /**
15202
+ * Apply ICollectionState to an ICollection
15203
+ *
15204
+ * Typically used in a Gallery or Catalog component to
15205
+ * set the inital state, based on values deserialized
15206
+ * from a query string
15207
+ * @param collection
15208
+ * @param state
15209
+ * @returns
15210
+ */
15211
+ function applyCollectionState(collection, state) {
15212
+ var updated = cloneObject$1(collection);
15213
+ // Apply default query
15214
+ if (state.query) {
15215
+ updated.defaultQuery = state.query;
15216
+ }
15217
+ // Apply Sort State
15218
+ updated.sortOption = applySortState(updated.sortOption, state.sort);
15219
+ // Look for state props for the facets and apply them
15220
+ updated.facets = updated.facets.map(function (facet) {
15221
+ // see if there is a key for this facet on the state
15222
+ if (Object.keys(state).includes(facet.key)) {
15223
+ var facetState = {};
15224
+ facetState[facet.key] = state[facet.key];
15225
+ return applyFacetState(facet, facetState);
15226
+ }
15227
+ else {
15228
+ // Ensure all options are not selected
15229
+ // because they were not included in the state
15230
+ facet.options.forEach(function (opt) {
15231
+ opt.selected = false;
15232
+ });
15233
+ return facet;
15234
+ }
15235
+ });
15236
+ //
15237
+ return updated;
15238
+ }
15239
+ /**
15240
+ * Serialize the current state of a collection into a hash that
15241
+ * can be converted into a query string
15242
+ * @param collection
15243
+ * @returns
15244
+ */
15245
+ function serializeCollectionState(collection) {
15246
+ var state = {};
15247
+ if (collection.defaultQuery) {
15248
+ state.query = collection.defaultQuery;
15249
+ }
15250
+ if (collection.sortOption) {
15251
+ state.sort = serializeSortState(collection.sortOption);
15252
+ }
15253
+ var facetState = collection.facets.reduce(function (s, facet) {
15254
+ return __assign(__assign({}, s), serializeFacetState(facet));
15255
+ }, {});
15256
+ return __assign(__assign({}, state), facetState);
15257
+ }
15258
+
15259
+ /**
15260
+ * Convert the original site catalog structure into a formal ICatalog
15261
+ * @param original
15262
+ */
15263
+ function convertCatalog(original) {
15264
+ var filter = {
15265
+ filterType: "content",
15266
+ };
15267
+ var groups = getProp(original, "groups");
15268
+ if (Array.isArray(groups) && groups.length) {
15269
+ filter.group = groups;
15270
+ }
15271
+ else if (typeof groups === "string") {
15272
+ filter.group = [groups];
15273
+ }
15274
+ var catalog = {
15275
+ title: "Default Catalog",
15276
+ filter: filter,
15277
+ };
15278
+ return catalog;
15279
+ }
15280
+
15045
15281
  /**
15046
15282
  * Add telemetry config object
15047
15283
  * @private
@@ -16862,6 +17098,7 @@
16862
17098
  exports.addSiteDomains = addSiteDomains;
16863
17099
  exports.addSolutionResourceUrlToAssets = addSolutionResourceUrlToAssets;
16864
17100
  exports.addUsersToGroup = addUsersToGroup;
17101
+ exports.applyCollectionState = applyCollectionState;
16865
17102
  exports.applyPropertiesToItems = applyPropertiesToItems;
16866
17103
  exports.arrayToObject = arrayToObject;
16867
17104
  exports.atob = abab.atob;
@@ -16886,6 +17123,7 @@
16886
17123
  exports.compose = compose;
16887
17124
  exports.composeContent = composeContent;
16888
17125
  exports.constructSlug = constructSlug;
17126
+ exports.convertCatalog = convertCatalog;
16889
17127
  exports.convertContentDefinitionToFilter = convertContentDefinitionToFilter;
16890
17128
  exports.convertContentFilterToSearchOptions = convertContentFilterToSearchOptions;
16891
17129
  exports.convertItemToProject = convertItemToProject;
@@ -17060,6 +17298,7 @@
17060
17298
  exports.saveSession = saveSession;
17061
17299
  exports.searchProjects = searchProjects;
17062
17300
  exports.searchSites = searchSites;
17301
+ exports.serializeCollectionState = serializeCollectionState;
17063
17302
  exports.serializeContentFilterForPortal = serializeContentFilterForPortal;
17064
17303
  exports.serializeDateRange = serializeDateRange;
17065
17304
  exports.serializeGroupFilterForPortal = serializeGroupFilterForPortal;