@esri/hub-common 9.45.3 → 9.45.6

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 (48) hide show
  1. package/dist/es2017/search/_internal/ipredicate-utils.js +38 -0
  2. package/dist/es2017/search/_internal/ipredicate-utils.js.map +1 -0
  3. package/dist/es2017/search/_internal/portalSearchGroups.js +2 -1
  4. package/dist/es2017/search/_internal/portalSearchGroups.js.map +1 -1
  5. package/dist/es2017/search/_internal/portalSearchItems.js +2 -1
  6. package/dist/es2017/search/_internal/portalSearchItems.js.map +1 -1
  7. package/dist/es2017/search/_internal/portalSearchUsers.js +2 -1
  8. package/dist/es2017/search/_internal/portalSearchUsers.js.map +1 -1
  9. package/dist/es2017/search/index.js +1 -0
  10. package/dist/es2017/search/index.js.map +1 -1
  11. package/dist/es2017/search/{_internal/ifilter-utils.js → serializeQueryForPortal.js} +39 -50
  12. package/dist/es2017/search/serializeQueryForPortal.js.map +1 -0
  13. package/dist/esm/search/_internal/ipredicate-utils.js +40 -0
  14. package/dist/esm/search/_internal/ipredicate-utils.js.map +1 -0
  15. package/dist/esm/search/_internal/portalSearchGroups.js +2 -1
  16. package/dist/esm/search/_internal/portalSearchGroups.js.map +1 -1
  17. package/dist/esm/search/_internal/portalSearchItems.js +2 -1
  18. package/dist/esm/search/_internal/portalSearchItems.js.map +1 -1
  19. package/dist/esm/search/_internal/portalSearchUsers.js +2 -1
  20. package/dist/esm/search/_internal/portalSearchUsers.js.map +1 -1
  21. package/dist/esm/search/index.js +1 -0
  22. package/dist/esm/search/index.js.map +1 -1
  23. package/dist/esm/search/{_internal/ifilter-utils.js → serializeQueryForPortal.js} +39 -51
  24. package/dist/esm/search/serializeQueryForPortal.js.map +1 -0
  25. package/dist/node/search/_internal/ipredicate-utils.js +42 -0
  26. package/dist/node/search/_internal/ipredicate-utils.js.map +1 -0
  27. package/dist/node/search/_internal/portalSearchGroups.js +4 -3
  28. package/dist/node/search/_internal/portalSearchGroups.js.map +1 -1
  29. package/dist/node/search/_internal/portalSearchItems.js +4 -3
  30. package/dist/node/search/_internal/portalSearchItems.js.map +1 -1
  31. package/dist/node/search/_internal/portalSearchUsers.js +4 -3
  32. package/dist/node/search/_internal/portalSearchUsers.js.map +1 -1
  33. package/dist/node/search/index.js +1 -0
  34. package/dist/node/search/index.js.map +1 -1
  35. package/dist/node/search/{_internal/ifilter-utils.js → serializeQueryForPortal.js} +41 -53
  36. package/dist/node/search/serializeQueryForPortal.js.map +1 -0
  37. package/dist/types/search/_internal/ipredicate-utils.d.ts +2 -0
  38. package/dist/types/search/index.d.ts +1 -0
  39. package/dist/types/search/{_internal/ifilter-utils.d.ts → serializeQueryForPortal.d.ts} +6 -2
  40. package/dist/types/search/types/IHubAggregation.d.ts +9 -0
  41. package/dist/types/search/types/IHubSearchOptions.d.ts +18 -8
  42. package/dist/types/search/types/IHubSearchResponse.d.ts +18 -0
  43. package/dist/umd/common.umd.js +174 -147
  44. package/dist/umd/common.umd.js.map +1 -1
  45. package/package.json +1 -1
  46. package/dist/es2017/search/_internal/ifilter-utils.js.map +0 -1
  47. package/dist/esm/search/_internal/ifilter-utils.js.map +0 -1
  48. package/dist/node/search/_internal/ifilter-utils.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /* @preserve
2
- * @esri/hub-common - v9.45.2 - Thu Jun 30 2022 13:33:18 GMT+0000 (Coordinated Universal Time)
2
+ * @esri/hub-common - v9.45.5 - Thu Jul 07 2022 20:50:46 GMT+0000 (Coordinated Universal Time)
3
3
  * Copyright (c) 2022 Environmental Systems Research Institute, Inc.
4
4
  * Apache-2.0
5
5
  */
@@ -15006,140 +15006,6 @@
15006
15006
  }
15007
15007
  }
15008
15008
 
15009
- /**
15010
- * Generic Hub Error with an Error stack as well
15011
- * as an optional serialized OperationStack.
15012
- *
15013
- * Also accepts a `rootCause` Error object
15014
- */
15015
- var HubError = /** @class */ (function (_super) {
15016
- __extends(HubError, _super);
15017
- /**
15018
- * Creates an instance of HubError.
15019
- * @param {string} operation
15020
- * @param {string} [message]
15021
- * @param {Error} [rootCause]
15022
- * @memberof HubError
15023
- */
15024
- function HubError(operation, message, rootCause) {
15025
- var _this = this;
15026
- message = message || "UNKNOWN_ERROR";
15027
- // if the rootCause has a .rootCause, use that so we don't deeply nest
15028
- rootCause = getWithDefault$1(rootCause, "rootCause", rootCause);
15029
- /* Skip coverage on super(...) as per:
15030
- https://github.com/Microsoft/TypeScript/issues/13029
15031
- https://github.com/SitePen/remap-istanbul/issues/106
15032
- */
15033
- /* istanbul ignore next */
15034
- _this = _super.call(this, operation, message, rootCause) || this;
15035
- _this.name = "HubError";
15036
- // if the original error has a stack use it, otherwise create a new
15037
- // stack. Note: a new Stack will make it look like the error origninated
15038
- // in the HubError constructor. This is only an issue in tests but
15039
- // it can be confusing to debug
15040
- _this.stack = getWithDefault$1(rootCause, "stack", new Error().stack);
15041
- return _this;
15042
- }
15043
- return HubError;
15044
- }(OperationError$1));
15045
- var HubError$1 = HubError;
15046
-
15047
- /**
15048
- * Generic search that returns Hub Entity types converted from items
15049
- * by the passed in `ItemToEntityFunction`
15050
- *
15051
- * This abstraction is used to ensure that searching from any of the
15052
- * entity managers / modules is consistent, and returns the entity
15053
- * types, instead of `IItem` or `IHubContent`
15054
- *
15055
- * @param filter
15056
- * @param convertFn
15057
- * @param options
15058
- * @returns
15059
- */
15060
- function searchContentEntities(filter, convertFn, options) {
15061
- var _a, _b;
15062
- // expand filter so we can serialize to either api
15063
- var expanded = expandContentFilter(filter);
15064
- var searchOptions = serializeContentFilterForPortal(expanded);
15065
- // DEPRECATION
15066
- /* istanbul ignore next */
15067
- if ((_a = options.aggregations) === null || _a === void 0 ? void 0 : _a.length) {
15068
- // tslint:disable-next-line:no-console
15069
- console.warn("IHubSearchOptions.aggregations is deprecated. Please use .aggFields instead.");
15070
- searchOptions.countFields = options.aggregations.join(",");
15071
- searchOptions.countSize = options.aggLimit || 10;
15072
- }
15073
- // Aggregations
15074
- if ((_b = options.aggFields) === null || _b === void 0 ? void 0 : _b.length) {
15075
- searchOptions.countFields = options.aggFields.join(",");
15076
- searchOptions.countSize = options.aggLimit || 10;
15077
- }
15078
- // properties to copy from IHubSearchOptions to the ISearchOptions
15079
- var props = [
15080
- "authentication",
15081
- "num",
15082
- "sortField",
15083
- "sortOrder",
15084
- "site",
15085
- "start",
15086
- ];
15087
- // Include "start" here
15088
- // copy the props over
15089
- props.forEach(function (prop) {
15090
- if (options.hasOwnProperty(prop)) {
15091
- searchOptions[prop] = options[prop];
15092
- }
15093
- });
15094
- // create the entitySearchFn
15095
- var searchFn = createContentEntitySearchFn(convertFn);
15096
- // execute the search
15097
- // Add ArcGIS API
15098
- if (options.api && !options.authentication) {
15099
- var expandedApi = expandApi(options.api);
15100
- searchOptions.portal = expandedApi.url;
15101
- }
15102
- return searchFn(searchOptions);
15103
- }
15104
- /**
15105
- * Return a function that holds a closure containing
15106
- * a hub entity specific conversion function. This
15107
- * allows the `.next()` function to use the function on
15108
- * subsequent calls
15109
- * @param convertFn
15110
- * @returns
15111
- */
15112
- function createContentEntitySearchFn(convertFn) {
15113
- // Return a function that does the search, with a closure over the
15114
- // conversion function. Naming this function is important as it's
15115
- // referenced in the `next` section below
15116
- return function searchEntities(searchOptions) {
15117
- return __awaiter(this, void 0, void 0, function () {
15118
- var response, entities, facets;
15119
- return __generator(this, function (_a) {
15120
- switch (_a.label) {
15121
- case 0: return [4 /*yield*/, searchItems(searchOptions)];
15122
- case 1:
15123
- response = _a.sent();
15124
- return [4 /*yield*/, Promise.all(response.results.map(function (itm) {
15125
- return convertFn(itm, searchOptions);
15126
- }))];
15127
- case 2:
15128
- entities = _a.sent();
15129
- facets = convertPortalResponseToFacets(response);
15130
- return [2 /*return*/, {
15131
- total: response.total,
15132
- results: entities,
15133
- facets: facets,
15134
- hasNext: response.nextStart > -1,
15135
- next: getNextFunction(searchOptions, response.nextStart, response.total, searchEntities),
15136
- }];
15137
- }
15138
- });
15139
- });
15140
- };
15141
- }
15142
-
15143
15009
  function expandPredicate(predicate) {
15144
15010
  var result = {};
15145
15011
  var dateProps = ["created", "modified", "lastlogin"];
@@ -15175,24 +15041,42 @@
15175
15041
  });
15176
15042
  return result;
15177
15043
  }
15044
+
15045
+ /**
15046
+ * Serialize IQuery into ISearchOptions for ArcGIS Portal
15047
+ * @param query
15048
+ * @returns
15049
+ */
15178
15050
  function serializeQueryForPortal(query) {
15179
15051
  var filterSearchOptions = query.filters.map(serializeFilter);
15180
- var result = mergeSearchOptions(filterSearchOptions, "AND");
15052
+ // remove any empty entries
15053
+ var nonEmptyOptions = filterSearchOptions.filter(removeEmptyEntries);
15054
+ var result = mergeSearchOptions(nonEmptyOptions, "AND");
15181
15055
  return result;
15182
15056
  }
15057
+ /**
15058
+ * Predicate to remove things from array
15059
+ * @param e
15060
+ * @returns
15061
+ */
15062
+ function removeEmptyEntries(e) {
15063
+ return !(typeof e === "undefined" || e === null || e === "");
15064
+ }
15183
15065
  function mergeSearchOptions(options, operation) {
15184
15066
  var result = options.reduce(function (acc, entry) {
15185
15067
  // walk the props
15186
15068
  Object.entries(entry).forEach(function (_a) {
15187
15069
  var key = _a[0], value = _a[1];
15188
- // if prop exists
15189
- if (acc[key]) {
15070
+ // if prop exists and is not empty string
15071
+ if (acc[key] && value !== "") {
15190
15072
  // combine via operation
15191
15073
  acc[key] = acc[key] + " " + operation + " " + value;
15192
15074
  }
15193
15075
  else {
15194
- // just copy the value
15195
- acc[key] = value;
15076
+ // just copy the value if it's not empty string
15077
+ if (value !== "") {
15078
+ acc[key] = value;
15079
+ }
15196
15080
  }
15197
15081
  });
15198
15082
  return acc;
@@ -15207,7 +15091,9 @@
15207
15091
  function serializeFilter(filter) {
15208
15092
  var operation = filter.operation || "AND";
15209
15093
  var predicates = filter.predicates.map(expandPredicate);
15210
- var predicateSearchOptions = predicates.map(serializePredicate);
15094
+ var predicateSearchOptions = predicates
15095
+ .map(serializePredicate)
15096
+ .filter(function (e) { return e !== undefined && e !== null; });
15211
15097
  // combine these searchOptions
15212
15098
  var searchOptions = mergeSearchOptions(predicateSearchOptions, operation);
15213
15099
  // wrap in parens if we have more than one predicate
@@ -15259,6 +15145,7 @@
15259
15145
  "snippet",
15260
15146
  "tags",
15261
15147
  "term",
15148
+ "title",
15262
15149
  "type",
15263
15150
  "typekeywords",
15264
15151
  "userlicensetype",
@@ -15274,7 +15161,7 @@
15274
15161
  // not attempt to ensure the properties are used in the correct combinations
15275
15162
  if (portalAllowList.includes(key)) {
15276
15163
  var so = { q: "" };
15277
- if (!specialProps.includes(key)) {
15164
+ if (!specialProps.includes(key) && key !== "term") {
15278
15165
  qCount++;
15279
15166
  so.q = serializeMatchOptions(key, value);
15280
15167
  }
@@ -15296,13 +15183,18 @@
15296
15183
  return so;
15297
15184
  }
15298
15185
  })
15299
- .filter(function (e) { return e !== undefined; });
15186
+ .filter(removeEmptyEntries);
15300
15187
  // merge up all the searchOptions
15301
- var searchOptions = mergeSearchOptions(opts, "AND");
15302
- if (qCount > 1) {
15303
- searchOptions.q = "(" + searchOptions.q + ")";
15188
+ if (opts.length) {
15189
+ var searchOptions = mergeSearchOptions(opts, "AND");
15190
+ if (qCount > 1) {
15191
+ searchOptions.q = "(" + searchOptions.q + ")";
15192
+ }
15193
+ return searchOptions;
15194
+ }
15195
+ else {
15196
+ return null;
15304
15197
  }
15305
- return searchOptions;
15306
15198
  }
15307
15199
  /**
15308
15200
  * Serialize MatchOptions into portal syntax
@@ -15358,6 +15250,140 @@
15358
15250
  return q;
15359
15251
  }
15360
15252
 
15253
+ /**
15254
+ * Generic Hub Error with an Error stack as well
15255
+ * as an optional serialized OperationStack.
15256
+ *
15257
+ * Also accepts a `rootCause` Error object
15258
+ */
15259
+ var HubError = /** @class */ (function (_super) {
15260
+ __extends(HubError, _super);
15261
+ /**
15262
+ * Creates an instance of HubError.
15263
+ * @param {string} operation
15264
+ * @param {string} [message]
15265
+ * @param {Error} [rootCause]
15266
+ * @memberof HubError
15267
+ */
15268
+ function HubError(operation, message, rootCause) {
15269
+ var _this = this;
15270
+ message = message || "UNKNOWN_ERROR";
15271
+ // if the rootCause has a .rootCause, use that so we don't deeply nest
15272
+ rootCause = getWithDefault$1(rootCause, "rootCause", rootCause);
15273
+ /* Skip coverage on super(...) as per:
15274
+ https://github.com/Microsoft/TypeScript/issues/13029
15275
+ https://github.com/SitePen/remap-istanbul/issues/106
15276
+ */
15277
+ /* istanbul ignore next */
15278
+ _this = _super.call(this, operation, message, rootCause) || this;
15279
+ _this.name = "HubError";
15280
+ // if the original error has a stack use it, otherwise create a new
15281
+ // stack. Note: a new Stack will make it look like the error origninated
15282
+ // in the HubError constructor. This is only an issue in tests but
15283
+ // it can be confusing to debug
15284
+ _this.stack = getWithDefault$1(rootCause, "stack", new Error().stack);
15285
+ return _this;
15286
+ }
15287
+ return HubError;
15288
+ }(OperationError$1));
15289
+ var HubError$1 = HubError;
15290
+
15291
+ /**
15292
+ * Generic search that returns Hub Entity types converted from items
15293
+ * by the passed in `ItemToEntityFunction`
15294
+ *
15295
+ * This abstraction is used to ensure that searching from any of the
15296
+ * entity managers / modules is consistent, and returns the entity
15297
+ * types, instead of `IItem` or `IHubContent`
15298
+ *
15299
+ * @param filter
15300
+ * @param convertFn
15301
+ * @param options
15302
+ * @returns
15303
+ */
15304
+ function searchContentEntities(filter, convertFn, options) {
15305
+ var _a, _b;
15306
+ // expand filter so we can serialize to either api
15307
+ var expanded = expandContentFilter(filter);
15308
+ var searchOptions = serializeContentFilterForPortal(expanded);
15309
+ // DEPRECATION
15310
+ /* istanbul ignore next */
15311
+ if ((_a = options.aggregations) === null || _a === void 0 ? void 0 : _a.length) {
15312
+ // tslint:disable-next-line:no-console
15313
+ console.warn("IHubSearchOptions.aggregations is deprecated. Please use .aggFields instead.");
15314
+ searchOptions.countFields = options.aggregations.join(",");
15315
+ searchOptions.countSize = options.aggLimit || 10;
15316
+ }
15317
+ // Aggregations
15318
+ if ((_b = options.aggFields) === null || _b === void 0 ? void 0 : _b.length) {
15319
+ searchOptions.countFields = options.aggFields.join(",");
15320
+ searchOptions.countSize = options.aggLimit || 10;
15321
+ }
15322
+ // properties to copy from IHubSearchOptions to the ISearchOptions
15323
+ var props = [
15324
+ "authentication",
15325
+ "num",
15326
+ "sortField",
15327
+ "sortOrder",
15328
+ "site",
15329
+ "start",
15330
+ ];
15331
+ // Include "start" here
15332
+ // copy the props over
15333
+ props.forEach(function (prop) {
15334
+ if (options.hasOwnProperty(prop)) {
15335
+ searchOptions[prop] = options[prop];
15336
+ }
15337
+ });
15338
+ // create the entitySearchFn
15339
+ var searchFn = createContentEntitySearchFn(convertFn);
15340
+ // execute the search
15341
+ // Add ArcGIS API
15342
+ if (options.api && !options.authentication) {
15343
+ var expandedApi = expandApi(options.api);
15344
+ searchOptions.portal = expandedApi.url;
15345
+ }
15346
+ return searchFn(searchOptions);
15347
+ }
15348
+ /**
15349
+ * Return a function that holds a closure containing
15350
+ * a hub entity specific conversion function. This
15351
+ * allows the `.next()` function to use the function on
15352
+ * subsequent calls
15353
+ * @param convertFn
15354
+ * @returns
15355
+ */
15356
+ function createContentEntitySearchFn(convertFn) {
15357
+ // Return a function that does the search, with a closure over the
15358
+ // conversion function. Naming this function is important as it's
15359
+ // referenced in the `next` section below
15360
+ return function searchEntities(searchOptions) {
15361
+ return __awaiter(this, void 0, void 0, function () {
15362
+ var response, entities, facets;
15363
+ return __generator(this, function (_a) {
15364
+ switch (_a.label) {
15365
+ case 0: return [4 /*yield*/, searchItems(searchOptions)];
15366
+ case 1:
15367
+ response = _a.sent();
15368
+ return [4 /*yield*/, Promise.all(response.results.map(function (itm) {
15369
+ return convertFn(itm, searchOptions);
15370
+ }))];
15371
+ case 2:
15372
+ entities = _a.sent();
15373
+ facets = convertPortalResponseToFacets(response);
15374
+ return [2 /*return*/, {
15375
+ total: response.total,
15376
+ results: entities,
15377
+ facets: facets,
15378
+ hasNext: response.nextStart > -1,
15379
+ next: getNextFunction(searchOptions, response.nextStart, response.total, searchEntities),
15380
+ }];
15381
+ }
15382
+ });
15383
+ });
15384
+ };
15385
+ }
15386
+
15361
15387
  /**
15362
15388
  * Fetch Page specific Enrichments
15363
15389
  * @param item
@@ -20610,6 +20636,7 @@
20610
20636
  exports.serializeGroupFilterForPortal = serializeGroupFilterForPortal;
20611
20637
  exports.serializeMatchOptions = serializeMatchOptions$1;
20612
20638
  exports.serializeModel = serializeModel;
20639
+ exports.serializeQueryForPortal = serializeQueryForPortal;
20613
20640
  exports.serializeSpatialReference = serializeSpatialReference;
20614
20641
  exports.serializeStringOrArray = serializeStringOrArray$1;
20615
20642
  exports.serializeUserFilterForPortal = serializeUserFilterForPortal;