@esri/hub-common 9.48.0 → 9.49.2

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 (115) hide show
  1. package/dist/es2017/core/traits/WithCatalog.js +1 -0
  2. package/dist/es2017/core/traits/WithCatalog.js.map +1 -0
  3. package/dist/es2017/index.js +1 -0
  4. package/dist/es2017/index.js.map +1 -1
  5. package/dist/es2017/search/Catalog.js +346 -0
  6. package/dist/es2017/search/Catalog.js.map +1 -0
  7. package/dist/es2017/search/Collection.js +38 -19
  8. package/dist/es2017/search/Collection.js.map +1 -1
  9. package/dist/es2017/search/_internal/{ipredicate-utils.js → expandPredicate.js} +1 -1
  10. package/dist/es2017/search/_internal/expandPredicate.js.map +1 -0
  11. package/dist/es2017/search/_internal/portalSearchGroups.js +1 -1
  12. package/dist/es2017/search/_internal/portalSearchGroups.js.map +1 -1
  13. package/dist/es2017/search/_internal/portalSearchItems.js +1 -1
  14. package/dist/es2017/search/_internal/portalSearchItems.js.map +1 -1
  15. package/dist/es2017/search/_internal/portalSearchUsers.js +1 -1
  16. package/dist/es2017/search/_internal/portalSearchUsers.js.map +1 -1
  17. package/dist/es2017/search/fetchCatalog.js +46 -0
  18. package/dist/es2017/search/fetchCatalog.js.map +1 -0
  19. package/dist/es2017/search/hubSearch.js +1 -1
  20. package/dist/es2017/search/hubSearch.js.map +1 -1
  21. package/dist/es2017/search/index.js +3 -1
  22. package/dist/es2017/search/index.js.map +1 -1
  23. package/dist/es2017/search/serializeQueryForPortal.js +3 -2
  24. package/dist/es2017/search/serializeQueryForPortal.js.map +1 -1
  25. package/dist/es2017/search/upgradeCatalogSchema.js +66 -0
  26. package/dist/es2017/search/upgradeCatalogSchema.js.map +1 -0
  27. package/dist/es2017/types/IMessage.js +1 -0
  28. package/dist/es2017/types/IMessage.js.map +1 -0
  29. package/dist/es2017/types/index.js +2 -0
  30. package/dist/es2017/types/index.js.map +1 -0
  31. package/dist/esm/core/traits/WithCatalog.js +1 -0
  32. package/dist/esm/core/traits/WithCatalog.js.map +1 -0
  33. package/dist/esm/index.js +1 -0
  34. package/dist/esm/index.js.map +1 -1
  35. package/dist/esm/search/Catalog.js +404 -0
  36. package/dist/esm/search/Catalog.js.map +1 -0
  37. package/dist/esm/search/Collection.js +40 -24
  38. package/dist/esm/search/Collection.js.map +1 -1
  39. package/dist/esm/search/_internal/{ipredicate-utils.js → expandPredicate.js} +1 -1
  40. package/dist/esm/search/_internal/expandPredicate.js.map +1 -0
  41. package/dist/esm/search/_internal/portalSearchGroups.js +1 -1
  42. package/dist/esm/search/_internal/portalSearchGroups.js.map +1 -1
  43. package/dist/esm/search/_internal/portalSearchItems.js +1 -1
  44. package/dist/esm/search/_internal/portalSearchItems.js.map +1 -1
  45. package/dist/esm/search/_internal/portalSearchUsers.js +1 -1
  46. package/dist/esm/search/_internal/portalSearchUsers.js.map +1 -1
  47. package/dist/esm/search/fetchCatalog.js +59 -0
  48. package/dist/esm/search/fetchCatalog.js.map +1 -0
  49. package/dist/esm/search/hubSearch.js +1 -1
  50. package/dist/esm/search/hubSearch.js.map +1 -1
  51. package/dist/esm/search/index.js +3 -1
  52. package/dist/esm/search/index.js.map +1 -1
  53. package/dist/esm/search/serializeQueryForPortal.js +3 -2
  54. package/dist/esm/search/serializeQueryForPortal.js.map +1 -1
  55. package/dist/esm/search/upgradeCatalogSchema.js +66 -0
  56. package/dist/esm/search/upgradeCatalogSchema.js.map +1 -0
  57. package/dist/esm/types/IMessage.js +1 -0
  58. package/dist/esm/types/IMessage.js.map +1 -0
  59. package/dist/esm/types/index.js +2 -0
  60. package/dist/esm/types/index.js.map +1 -0
  61. package/dist/node/core/traits/WithCatalog.js +3 -0
  62. package/dist/node/core/traits/WithCatalog.js.map +1 -0
  63. package/dist/node/index.js +1 -0
  64. package/dist/node/index.js.map +1 -1
  65. package/dist/node/search/Catalog.js +350 -0
  66. package/dist/node/search/Catalog.js.map +1 -0
  67. package/dist/node/search/Collection.js +37 -18
  68. package/dist/node/search/Collection.js.map +1 -1
  69. package/dist/node/search/_internal/{ipredicate-utils.js → expandPredicate.js} +1 -1
  70. package/dist/node/search/_internal/expandPredicate.js.map +1 -0
  71. package/dist/node/search/_internal/portalSearchGroups.js +2 -2
  72. package/dist/node/search/_internal/portalSearchGroups.js.map +1 -1
  73. package/dist/node/search/_internal/portalSearchItems.js +2 -2
  74. package/dist/node/search/_internal/portalSearchItems.js.map +1 -1
  75. package/dist/node/search/_internal/portalSearchUsers.js +2 -2
  76. package/dist/node/search/_internal/portalSearchUsers.js.map +1 -1
  77. package/dist/node/search/fetchCatalog.js +50 -0
  78. package/dist/node/search/fetchCatalog.js.map +1 -0
  79. package/dist/node/search/hubSearch.js +1 -1
  80. package/dist/node/search/hubSearch.js.map +1 -1
  81. package/dist/node/search/index.js +3 -1
  82. package/dist/node/search/index.js.map +1 -1
  83. package/dist/node/search/serializeQueryForPortal.js +4 -3
  84. package/dist/node/search/serializeQueryForPortal.js.map +1 -1
  85. package/dist/node/search/upgradeCatalogSchema.js +71 -0
  86. package/dist/node/search/upgradeCatalogSchema.js.map +1 -0
  87. package/dist/node/types/IMessage.js +3 -0
  88. package/dist/node/types/IMessage.js.map +1 -0
  89. package/dist/node/types/index.js +5 -0
  90. package/dist/node/types/index.js.map +1 -0
  91. package/dist/types/core/traits/WithCatalog.d.ts +7 -0
  92. package/dist/types/index.d.ts +1 -0
  93. package/dist/types/search/Catalog.d.ts +143 -0
  94. package/dist/types/search/Collection.d.ts +23 -2
  95. package/dist/types/search/_internal/{ipredicate-utils.d.ts → expandPredicate.d.ts} +0 -0
  96. package/dist/types/search/fetchCatalog.d.ts +10 -0
  97. package/dist/types/search/index.d.ts +3 -1
  98. package/dist/types/search/types/IHubSearchOptions.d.ts +5 -1
  99. package/dist/types/search/types/IHubSearchResponse.d.ts +5 -0
  100. package/dist/types/search/upgradeCatalogSchema.d.ts +12 -0
  101. package/dist/types/types/IMessage.d.ts +32 -0
  102. package/dist/types/types/index.d.ts +1 -0
  103. package/dist/umd/common.umd.js +635 -33
  104. package/dist/umd/common.umd.js.map +1 -1
  105. package/package.json +1 -1
  106. package/dist/es2017/search/_internal/ipredicate-utils.js.map +0 -1
  107. package/dist/es2017/search/convertCatalog.js +0 -33
  108. package/dist/es2017/search/convertCatalog.js.map +0 -1
  109. package/dist/esm/search/_internal/ipredicate-utils.js.map +0 -1
  110. package/dist/esm/search/convertCatalog.js +0 -33
  111. package/dist/esm/search/convertCatalog.js.map +0 -1
  112. package/dist/node/search/_internal/ipredicate-utils.js.map +0 -1
  113. package/dist/node/search/convertCatalog.js +0 -37
  114. package/dist/node/search/convertCatalog.js.map +0 -1
  115. package/dist/types/search/convertCatalog.d.ts +0 -6
@@ -1,5 +1,5 @@
1
1
  /* @preserve
2
- * @esri/hub-common - v9.47.0 - Wed Jul 20 2022 22:15:24 GMT+0000 (Coordinated Universal Time)
2
+ * @esri/hub-common - v9.49.1 - Tue Aug 02 2022 21:59:32 GMT+0000 (Coordinated Universal Time)
3
3
  * Copyright (c) 2022 Environmental Systems Research Institute, Inc.
4
4
  * Apache-2.0
5
5
  */
@@ -14985,36 +14985,68 @@
14985
14985
  return __assign(__assign({}, state), facetState);
14986
14986
  }
14987
14987
 
14988
+ var CATALOG_SCHEMA_VERSION = 1.0;
14988
14989
  /**
14989
- * Convert the original site catalog structure into a formal ICatalog
14990
- * @param original
14990
+ * Apply schema upgrades to Catalog objects
14991
+ * @param catalog
14992
+ * @returns
14991
14993
  */
14992
- function convertCatalog(original) {
14993
- var catalog = {
14994
- schemaVersion: 1,
14995
- title: "Default Catalog",
14996
- scopes: {
14997
- item: {
14998
- targetEntity: "item",
14999
- filters: [],
15000
- },
15001
- },
15002
- collections: [],
15003
- };
15004
- var rawGroups = getProp(original, "groups");
15005
- var groups = [];
15006
- if (Array.isArray(rawGroups) && rawGroups.length) {
15007
- groups = rawGroups;
14994
+ function upgradeCatalogSchema(catalog) {
14995
+ var clone = cloneObject$1(catalog);
14996
+ if (getProp(clone, "schemaVersion") === CATALOG_SCHEMA_VERSION) {
14997
+ return clone;
15008
14998
  }
15009
- else if (typeof rawGroups === "string") {
15010
- groups = [rawGroups];
14999
+ else {
15000
+ // apply migrations in order
15001
+ clone = applyCatalogSchema(clone);
15002
+ return clone;
15011
15003
  }
15012
- if (groups.length) {
15013
- catalog.scopes.item.filters.push({
15014
- predicates: [{ group: groups }],
15015
- });
15004
+ }
15005
+ /**
15006
+ * Apply the Catalog schema to the original, unversioned
15007
+ * site catalog objects
15008
+ * @param original
15009
+ * @returns
15010
+ */
15011
+ function applyCatalogSchema(original) {
15012
+ if (getProp(original, "schemaVersion") > 1.0) {
15013
+ return original;
15014
+ }
15015
+ else {
15016
+ var catalog = {
15017
+ schemaVersion: 1,
15018
+ title: "Default Catalog",
15019
+ scopes: {
15020
+ item: {
15021
+ targetEntity: "item",
15022
+ filters: [],
15023
+ },
15024
+ },
15025
+ collections: [],
15026
+ };
15027
+ var rawGroups = getProp(original, "groups");
15028
+ var groups = [];
15029
+ if (Array.isArray(rawGroups) && rawGroups.length) {
15030
+ groups = rawGroups;
15031
+ }
15032
+ else if (typeof rawGroups === "string") {
15033
+ groups = [rawGroups];
15034
+ }
15035
+ if (groups.length) {
15036
+ catalog.scopes.item.filters.push({
15037
+ predicates: [{ group: groups }],
15038
+ });
15039
+ }
15040
+ return catalog;
15016
15041
  }
15017
- return catalog;
15042
+ }
15043
+ /**
15044
+ * DEPRECATED: Use upgradeCatalogSchema(...)
15045
+ * @param original
15046
+ */
15047
+ /* istanbul ignore next */
15048
+ function convertCatalog(original) {
15049
+ return upgradeCatalogSchema(original);
15018
15050
  }
15019
15051
 
15020
15052
  /**
@@ -15166,6 +15198,7 @@
15166
15198
  var portalAllowList = [
15167
15199
  "access",
15168
15200
  "categories",
15201
+ "capabilities",
15169
15202
  "created",
15170
15203
  "description",
15171
15204
  "disabled",
@@ -15199,7 +15232,6 @@
15199
15232
  "userlicensetype",
15200
15233
  "username",
15201
15234
  ];
15202
- var qCount = 0;
15203
15235
  // TODO: Look at using reduce vs .map and remove the `.filter`
15204
15236
  var opts = Object.entries(predicate)
15205
15237
  .map(function (_a) {
@@ -15210,22 +15242,18 @@
15210
15242
  if (portalAllowList.includes(key)) {
15211
15243
  var so = { q: "" };
15212
15244
  if (!specialProps.includes(key) && key !== "term") {
15213
- qCount++;
15214
15245
  so.q = serializeMatchOptions(key, value);
15215
15246
  }
15216
15247
  if (dateProps.includes(key)) {
15217
- qCount++;
15218
15248
  so.q = serializeDateRange(key, value);
15219
15249
  }
15220
15250
  if (boolProps.includes(key)) {
15221
- qCount++;
15222
15251
  so.q = key + ":" + value;
15223
15252
  }
15224
15253
  if (passThroughProps.includes(key)) {
15225
15254
  so[key] = value;
15226
15255
  }
15227
15256
  if (key === "term") {
15228
- qCount++;
15229
15257
  so.q = value;
15230
15258
  }
15231
15259
  return so;
@@ -15235,7 +15263,7 @@
15235
15263
  // merge up all the searchOptions
15236
15264
  if (opts.length) {
15237
15265
  var searchOptions = mergeSearchOptions(opts, "AND");
15238
- if (qCount > 1) {
15266
+ if (searchOptions.q) {
15239
15267
  searchOptions.q = "(" + searchOptions.q + ")";
15240
15268
  }
15241
15269
  return searchOptions;
@@ -18813,13 +18841,584 @@
18813
18841
  };
18814
18842
  fn = getProp(fnHash, apiType + "." + filterType);
18815
18843
  if (!fn) {
18816
- throw new HubError$1("hubSearch", "Search via \"" + filterType + "\" filter against \"" + apiType + "\" api is not implemented");
18844
+ throw new HubError$1("hubSearch", "Search via \"" + filterType + "\" filter against \"" + apiType + "\" api is not implemented. Please ensure \"targetEntity\" is defined on the query.");
18817
18845
  }
18818
18846
  return [2 /*return*/, fn(cloneObject$1(query), options)];
18819
18847
  });
18820
18848
  });
18821
18849
  }
18822
18850
 
18851
+ /**
18852
+ * Collection Class
18853
+ *
18854
+ * Abstracts searching a Collection
18855
+ *
18856
+ * For more information, check out the [Catalog & Collection Guide](/hub.js/guides/concepts/catalog-collection/)
18857
+ */
18858
+ var Collection = /** @class */ (function () {
18859
+ function Collection(collection, context) {
18860
+ this._collection = collection;
18861
+ this._context = context;
18862
+ }
18863
+ /**
18864
+ * Create an instance of a Collection from a JSON object
18865
+ * @param collection
18866
+ * @param context
18867
+ * @returns
18868
+ */
18869
+ Collection.fromJson = function (collection, context) {
18870
+ return new Collection(collection, context);
18871
+ };
18872
+ /**
18873
+ * Return the JSON object backing the instance
18874
+ * @returns
18875
+ */
18876
+ Collection.prototype.toJson = function () {
18877
+ return cloneObject$1(this._collection);
18878
+ };
18879
+ Object.defineProperty(Collection.prototype, "label", {
18880
+ // Getters
18881
+ get: function () {
18882
+ return this._collection.label;
18883
+ },
18884
+ enumerable: false,
18885
+ configurable: true
18886
+ });
18887
+ Object.defineProperty(Collection.prototype, "key", {
18888
+ get: function () {
18889
+ return this._collection.key;
18890
+ },
18891
+ enumerable: false,
18892
+ configurable: true
18893
+ });
18894
+ Object.defineProperty(Collection.prototype, "include", {
18895
+ get: function () {
18896
+ return this._collection.include || [];
18897
+ },
18898
+ enumerable: false,
18899
+ configurable: true
18900
+ });
18901
+ Object.defineProperty(Collection.prototype, "scope", {
18902
+ get: function () {
18903
+ return this._collection.scope;
18904
+ },
18905
+ enumerable: false,
18906
+ configurable: true
18907
+ });
18908
+ Object.defineProperty(Collection.prototype, "sortField", {
18909
+ get: function () {
18910
+ return this._collection.sortField || "title";
18911
+ },
18912
+ enumerable: false,
18913
+ configurable: true
18914
+ });
18915
+ Object.defineProperty(Collection.prototype, "sortDirection", {
18916
+ get: function () {
18917
+ return this._collection.sortDirection || "asc";
18918
+ },
18919
+ enumerable: false,
18920
+ configurable: true
18921
+ });
18922
+ Object.defineProperty(Collection.prototype, "targetEntity", {
18923
+ get: function () {
18924
+ return this._collection.targetEntity;
18925
+ },
18926
+ enumerable: false,
18927
+ configurable: true
18928
+ });
18929
+ /**
18930
+ * Search the collection using a string or IQuery
18931
+ * @param query
18932
+ * @param options
18933
+ * @returns
18934
+ */
18935
+ Collection.prototype.search = function (query, options) {
18936
+ if (options === void 0) { options = {}; }
18937
+ return __awaiter(this, void 0, void 0, function () {
18938
+ var qry, opts;
18939
+ return __generator(this, function (_a) {
18940
+ if (typeof query === "string") {
18941
+ // construct a query from that...
18942
+ qry = {
18943
+ targetEntity: this._collection.targetEntity,
18944
+ filters: [
18945
+ {
18946
+ predicates: [
18947
+ {
18948
+ term: query,
18949
+ },
18950
+ ],
18951
+ },
18952
+ ],
18953
+ };
18954
+ }
18955
+ else {
18956
+ qry = query;
18957
+ }
18958
+ // TODO: What should happen when a Query is passed in that has a targetEntity that doesn't match the collection's targetEntity?
18959
+ // merge the passed in query w/ the scope
18960
+ qry.filters = __spreadArrays(qry.filters, this.scope.filters);
18961
+ opts = cloneObject$1(options);
18962
+ opts.requestOptions = this._context.hubRequestOptions;
18963
+ // inject default sort info if not specified
18964
+ opts.sortField = options.sortField || this.sortField;
18965
+ opts.sortOrder = options.sortOrder || this.sortDirection;
18966
+ // inject default includes if not specified
18967
+ opts.include = options.include || this.include;
18968
+ // execute the search and return results
18969
+ return [2 /*return*/, hubSearch(qry, opts)];
18970
+ });
18971
+ });
18972
+ };
18973
+ return Collection;
18974
+ }());
18975
+
18976
+ /**
18977
+ * Fetch a IHubCatalog from a backing item.
18978
+ * This will apply schema upgrades to the structure
18979
+ * @param identifier
18980
+ * @param requestOptions
18981
+ * @returns
18982
+ */
18983
+ function fetchCatalog(identifier, requestOptions) {
18984
+ return __awaiter(this, void 0, void 0, function () {
18985
+ var getPrms, url, fetched;
18986
+ return __generator(this, function (_a) {
18987
+ switch (_a.label) {
18988
+ case 0:
18989
+ // identifier can be a guid or a url
18990
+ if (identifier.indexOf("http") === 0) {
18991
+ url = identifier;
18992
+ // get down the the hostname
18993
+ url = stripProtocol(url);
18994
+ // if url does not include a hash (i.e. it's not portal)
18995
+ // then we want to split on the first slash to get the hostname
18996
+ // lookupDomain will handle the enterprise base urls
18997
+ if (!url.includes("#")) {
18998
+ url = url.split("/")[0];
18999
+ }
19000
+ getPrms = lookupDomain(url, requestOptions)
19001
+ // get the item's data, and read the catalog out of it
19002
+ .then(function (_a) {
19003
+ var siteId = _a.siteId;
19004
+ return getItemData(siteId, requestOptions);
19005
+ })
19006
+ .then(function (data) {
19007
+ return upgradeCatalogSchema(data.catalog || {});
19008
+ });
19009
+ }
19010
+ else if (isGuid(identifier)) {
19011
+ // get the item's data, and read the catalog out of it
19012
+ getPrms = getItemData(identifier, requestOptions).then(function (data) {
19013
+ return upgradeCatalogSchema(data.catalog || {});
19014
+ });
19015
+ }
19016
+ else {
19017
+ throw new HubError$1("Catalog.create", "Identifier must be a url, guid");
19018
+ }
19019
+ return [4 /*yield*/, getPrms];
19020
+ case 1:
19021
+ fetched = _a.sent();
19022
+ return [2 /*return*/, fetched];
19023
+ }
19024
+ });
19025
+ });
19026
+ }
19027
+
19028
+ /**
19029
+ * Catalog Class
19030
+ *
19031
+ * Abstracts working with Catalogs and fetching collections with
19032
+ * the correct scope applied.
19033
+ *
19034
+ * For more information, check out the [Catalog & Collection Guide](/hub.js/guides/concepts/catalog-collection/)
19035
+ */
19036
+ var Catalog = /** @class */ (function () {
19037
+ // internal - use static factory methods
19038
+ function Catalog(catalog, context) {
19039
+ this._catalog = catalog;
19040
+ this._context = context;
19041
+ }
19042
+ /**
19043
+ * Create a Collection instance from a Catalog json object, a site url or itemId
19044
+ * '''js
19045
+ * const catalog = await Catalog.create('https://site-org.hub.arcgis.com', context);
19046
+ * '''
19047
+ *
19048
+ * @param identifier
19049
+ * @param context
19050
+ * @returns
19051
+ */
19052
+ Catalog.init = function (identifier, context) {
19053
+ return __awaiter(this, void 0, void 0, function () {
19054
+ var mgr, fetched;
19055
+ return __generator(this, function (_a) {
19056
+ switch (_a.label) {
19057
+ case 0:
19058
+ if (!!context) return [3 /*break*/, 2];
19059
+ return [4 /*yield*/, ArcGISContextManager.create()];
19060
+ case 1:
19061
+ mgr = _a.sent();
19062
+ context = mgr.context;
19063
+ _a.label = 2;
19064
+ case 2: return [4 /*yield*/, fetchCatalog(identifier, context.hubRequestOptions)];
19065
+ case 3:
19066
+ fetched = _a.sent();
19067
+ // return an instance
19068
+ return [2 /*return*/, new Catalog(fetched, context)];
19069
+ }
19070
+ });
19071
+ });
19072
+ };
19073
+ /**
19074
+ * Create a Catalog instance from a Catalog Json object
19075
+ * @param json
19076
+ * @param context
19077
+ * @returns
19078
+ */
19079
+ Catalog.fromJson = function (json, context) {
19080
+ // ensure it's in the latest structure
19081
+ var catalog = upgradeCatalogSchema(json);
19082
+ return new Catalog(catalog, context);
19083
+ };
19084
+ /**
19085
+ * Return the JSON object backing the instance
19086
+ * @returns
19087
+ */
19088
+ Catalog.prototype.toJson = function () {
19089
+ return cloneObject$1(this._catalog);
19090
+ };
19091
+ Object.defineProperty(Catalog.prototype, "schemaVersion", {
19092
+ /**
19093
+ * Return the schema version
19094
+ */
19095
+ get: function () {
19096
+ return this._catalog.schemaVersion;
19097
+ },
19098
+ enumerable: false,
19099
+ configurable: true
19100
+ });
19101
+ Object.defineProperty(Catalog.prototype, "title", {
19102
+ /**
19103
+ * Title getter
19104
+ */
19105
+ get: function () {
19106
+ return this._catalog.title;
19107
+ },
19108
+ /**
19109
+ * Title setter
19110
+ */
19111
+ set: function (v) {
19112
+ this._catalog.title = v;
19113
+ },
19114
+ enumerable: false,
19115
+ configurable: true
19116
+ });
19117
+ Object.defineProperty(Catalog.prototype, "scopes", {
19118
+ /**
19119
+ * Return the existing scopes hash
19120
+ */
19121
+ get: function () {
19122
+ return this._catalog.scopes;
19123
+ },
19124
+ enumerable: false,
19125
+ configurable: true
19126
+ });
19127
+ Object.defineProperty(Catalog.prototype, "availableScopes", {
19128
+ /**
19129
+ * Return an array of the entity types available in this Catalog
19130
+ */
19131
+ get: function () {
19132
+ return Object.keys(this.scopes);
19133
+ },
19134
+ enumerable: false,
19135
+ configurable: true
19136
+ });
19137
+ /**
19138
+ * Get the scope's query for a particular entity type
19139
+ * @param type
19140
+ * @returns
19141
+ */
19142
+ Catalog.prototype.getScope = function (type) {
19143
+ return this._catalog.scopes[type];
19144
+ };
19145
+ /**
19146
+ * Set the scope for a specific entity type
19147
+ * @param type
19148
+ * @param query
19149
+ */
19150
+ Catalog.prototype.setScope = function (type, query) {
19151
+ this._catalog.scopes[type] = query;
19152
+ };
19153
+ Object.defineProperty(Catalog.prototype, "collections", {
19154
+ /**
19155
+ * Get the collections array. Returns simple objects not Collection instances
19156
+ */
19157
+ get: function () {
19158
+ return this._catalog.collections || [];
19159
+ },
19160
+ enumerable: false,
19161
+ configurable: true
19162
+ });
19163
+ Object.defineProperty(Catalog.prototype, "collectionNames", {
19164
+ /**
19165
+ * Get the names of the collections
19166
+ */
19167
+ get: function () {
19168
+ return mapBy("key", this.collections);
19169
+ },
19170
+ enumerable: false,
19171
+ configurable: true
19172
+ });
19173
+ /**
19174
+ * Get a Collection instance by name
19175
+ * @param name
19176
+ * @returns
19177
+ */
19178
+ Catalog.prototype.getCollection = function (name) {
19179
+ var json = this.collections.find(function (entry) { return entry.key === name; });
19180
+ if (json) {
19181
+ // clone it then merge in the associated scope filter
19182
+ var clone = cloneObject$1(json);
19183
+ var catalogScope = this.getScope(clone.scope.targetEntity);
19184
+ if (catalogScope === null || catalogScope === void 0 ? void 0 : catalogScope.filters) {
19185
+ clone.scope.filters = __spreadArrays(clone.scope.filters, catalogScope.filters);
19186
+ }
19187
+ return Collection.fromJson(clone, this._context);
19188
+ }
19189
+ else {
19190
+ throw new HubError$1("getCollection", "Collection \"" + name + "\" is not present in the Catalog");
19191
+ }
19192
+ };
19193
+ /**
19194
+ * Search for Items
19195
+ * Will throw if the Catalog does not have a scope defined for items
19196
+ * @param query
19197
+ * @param options
19198
+ * @returns
19199
+ */
19200
+ Catalog.prototype.searchItems = function (query, options) {
19201
+ if (options === void 0) { options = {}; }
19202
+ if (!this.getScope("item")) {
19203
+ var result = this.getEmptyResult();
19204
+ result.messages = [
19205
+ {
19206
+ code: "missingScope",
19207
+ message: "Catalog does not have a scope for items",
19208
+ data: {
19209
+ scope: "item",
19210
+ },
19211
+ },
19212
+ ];
19213
+ return Promise.resolve(result);
19214
+ }
19215
+ else {
19216
+ // ensure it's an item search
19217
+ options.targetEntity = "item";
19218
+ return this.search(query, options);
19219
+ }
19220
+ };
19221
+ /**
19222
+ * Search for Groups
19223
+ * Will throw if the Catalog does not have a scope defined for groups
19224
+ * @param query
19225
+ * @param options
19226
+ * @returns
19227
+ */
19228
+ Catalog.prototype.searchGroups = function (query, options) {
19229
+ if (options === void 0) { options = {}; }
19230
+ if (!this.getScope("group")) {
19231
+ var result = this.getEmptyResult();
19232
+ result.messages = [
19233
+ {
19234
+ code: "missingScope",
19235
+ message: "Catalog does not have a scope for groups",
19236
+ data: {
19237
+ scope: "group",
19238
+ },
19239
+ },
19240
+ ];
19241
+ return Promise.resolve(result);
19242
+ }
19243
+ else {
19244
+ // ensure it's an group search
19245
+ options.targetEntity = "group";
19246
+ return this.search(query, options);
19247
+ }
19248
+ };
19249
+ /**
19250
+ * Search for Users
19251
+ * Will throw if the Catalog does not have a scope defined for users
19252
+ * @param query
19253
+ * @param options
19254
+ * @returns
19255
+ */
19256
+ Catalog.prototype.searchUsers = function (query, options) {
19257
+ if (options === void 0) { options = {}; }
19258
+ if (!this.getScope("user")) {
19259
+ var result = this.getEmptyResult();
19260
+ result.messages = [
19261
+ {
19262
+ code: "missingScope",
19263
+ message: "Catalog does not have a scope for user",
19264
+ data: {
19265
+ scope: "user",
19266
+ },
19267
+ },
19268
+ ];
19269
+ return Promise.resolve(result);
19270
+ }
19271
+ else {
19272
+ // ensure it's an group search
19273
+ options.targetEntity = "user";
19274
+ return this.search(query, options);
19275
+ }
19276
+ };
19277
+ /**
19278
+ * Execute a search against all the collections in the Catalog
19279
+ * @param query
19280
+ * @param options
19281
+ * @returns
19282
+ */
19283
+ Catalog.prototype.searchCollections = function (query, options) {
19284
+ if (options === void 0) { options = {}; }
19285
+ return __awaiter(this, void 0, void 0, function () {
19286
+ var qry, promiseKeys, promises, responses, hash, i;
19287
+ var _this = this;
19288
+ return __generator(this, function (_a) {
19289
+ switch (_a.label) {
19290
+ case 0:
19291
+ qry = {
19292
+ targetEntity: "item",
19293
+ filters: [
19294
+ {
19295
+ predicates: [
19296
+ {
19297
+ term: query,
19298
+ },
19299
+ ],
19300
+ },
19301
+ ],
19302
+ };
19303
+ promiseKeys = [];
19304
+ promises = this.collectionNames.map(function (name) {
19305
+ var col = _this.getCollection(name);
19306
+ promiseKeys.push(name);
19307
+ qry.targetEntity = col.targetEntity;
19308
+ return col.search(qry, options);
19309
+ });
19310
+ return [4 /*yield*/, Promise.all(promises)];
19311
+ case 1:
19312
+ responses = _a.sent();
19313
+ hash = {};
19314
+ for (i = 0; i < promiseKeys.length; i++) {
19315
+ hash[promiseKeys[i]] = responses[i];
19316
+ }
19317
+ return [2 /*return*/, hash];
19318
+ }
19319
+ });
19320
+ });
19321
+ };
19322
+ /**
19323
+ * Execute a search against all the scopes in the Catalog
19324
+ * @param query
19325
+ * @param options
19326
+ * @returns
19327
+ */
19328
+ Catalog.prototype.searchScopes = function (query, options) {
19329
+ if (options === void 0) { options = {}; }
19330
+ return __awaiter(this, void 0, void 0, function () {
19331
+ var qry, promiseKeys, promises, responses, hash, i;
19332
+ var _this = this;
19333
+ return __generator(this, function (_a) {
19334
+ switch (_a.label) {
19335
+ case 0:
19336
+ qry = {
19337
+ targetEntity: "item",
19338
+ filters: [
19339
+ {
19340
+ predicates: [
19341
+ {
19342
+ term: query,
19343
+ },
19344
+ ],
19345
+ },
19346
+ ],
19347
+ };
19348
+ promiseKeys = [];
19349
+ promises = this.availableScopes.map(function (name) {
19350
+ promiseKeys.push(name);
19351
+ // make clones
19352
+ var qryClone = cloneObject$1(qry);
19353
+ var optsClone = cloneObject$1(options);
19354
+ // set the target entity
19355
+ qryClone.targetEntity = name;
19356
+ optsClone.targetEntity = name;
19357
+ // return the search promise
19358
+ return _this.search(qryClone, optsClone);
19359
+ });
19360
+ return [4 /*yield*/, Promise.all(promises)];
19361
+ case 1:
19362
+ responses = _a.sent();
19363
+ hash = {};
19364
+ for (i = 0; i < promiseKeys.length; i++) {
19365
+ hash[promiseKeys[i]] = responses[i];
19366
+ }
19367
+ return [2 /*return*/, hash];
19368
+ }
19369
+ });
19370
+ });
19371
+ };
19372
+ /**
19373
+ * Execute a search against the Catalog as a whole
19374
+ * @param query
19375
+ * @param targetEntity
19376
+ * @returns
19377
+ */
19378
+ Catalog.prototype.search = function (query, options) {
19379
+ var targetEntity = options.targetEntity;
19380
+ var qry;
19381
+ if (typeof query === "string") {
19382
+ qry = {
19383
+ targetEntity: targetEntity,
19384
+ filters: [
19385
+ {
19386
+ predicates: [
19387
+ {
19388
+ term: query,
19389
+ },
19390
+ ],
19391
+ },
19392
+ ],
19393
+ };
19394
+ }
19395
+ else {
19396
+ qry = cloneObject$1(query);
19397
+ }
19398
+ // Now merge in catalog scope level filters
19399
+ qry.filters = __spreadArrays(qry.filters, this.getScope(targetEntity).filters);
19400
+ var opts = cloneObject$1(options);
19401
+ // An Catalog instance always uses the context so we remove/replace any passed in auth
19402
+ delete opts.authentication;
19403
+ opts.requestOptions = this._context.hubRequestOptions;
19404
+ return hubSearch(qry, opts);
19405
+ };
19406
+ /**
19407
+ * Construct an empty result. Returned when a search is performed against an entity type that
19408
+ * does not have a scope defined.
19409
+ * @returns
19410
+ */
19411
+ Catalog.prototype.getEmptyResult = function () {
19412
+ return {
19413
+ results: [],
19414
+ total: 0,
19415
+ hasNext: false,
19416
+ next: null,
19417
+ };
19418
+ };
19419
+ return Catalog;
19420
+ }());
19421
+
18823
19422
  /**
18824
19423
  * Enrich a generic search result
18825
19424
  * @param group
@@ -20430,6 +21029,8 @@
20430
21029
 
20431
21030
  exports.ArcGISContext = ArcGISContext;
20432
21031
  exports.ArcGISContextManager = ArcGISContextManager;
21032
+ exports.Catalog = Catalog;
21033
+ exports.Collection = Collection;
20433
21034
  exports.DEFAULT_THEME = DEFAULT_THEME;
20434
21035
  exports.ENTERPRISE_SITE_ITEM_TYPE = ENTERPRISE_SITE_ITEM_TYPE;
20435
21036
  exports.GLOBAL_EXTENT = GLOBAL_EXTENT;
@@ -20741,6 +21342,7 @@
20741
21342
  exports.updateModel = updateModel;
20742
21343
  exports.updateProject = updateProject;
20743
21344
  exports.updateSite = updateSite;
21345
+ exports.upgradeCatalogSchema = upgradeCatalogSchema;
20744
21346
  exports.upgradeProtocol = upgradeProtocol;
20745
21347
  exports.upgradeSiteSchema = upgradeSiteSchema;
20746
21348
  exports.uploadResourcesFromUrl = uploadResourcesFromUrl;