@internetarchive/collection-browser 3.4.1 → 3.4.2-alpha-webdev7761.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 (195) hide show
  1. package/.editorconfig +29 -29
  2. package/.github/workflows/ci.yml +27 -27
  3. package/.github/workflows/gh-pages-main.yml +39 -39
  4. package/.github/workflows/npm-publish.yml +39 -39
  5. package/.github/workflows/pr-preview.yml +38 -38
  6. package/.husky/pre-commit +4 -4
  7. package/.prettierignore +1 -1
  8. package/LICENSE +661 -661
  9. package/README.md +83 -83
  10. package/dist/src/app-root.js +19 -28
  11. package/dist/src/app-root.js.map +1 -1
  12. package/dist/src/collection-browser.d.ts +27 -4
  13. package/dist/src/collection-browser.js +973 -801
  14. package/dist/src/collection-browser.js.map +1 -1
  15. package/dist/src/collection-facets/facet-row.js +143 -143
  16. package/dist/src/collection-facets/facet-row.js.map +1 -1
  17. package/dist/src/collection-facets/more-facets-content.js +148 -159
  18. package/dist/src/collection-facets/more-facets-content.js.map +1 -1
  19. package/dist/src/collection-facets/more-facets-pagination.js +6 -10
  20. package/dist/src/collection-facets/more-facets-pagination.js.map +1 -1
  21. package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.js +16 -21
  22. package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.js.map +1 -1
  23. package/dist/src/collection-facets/smart-facets/smart-facet-bar.js +7 -10
  24. package/dist/src/collection-facets/smart-facets/smart-facet-bar.js.map +1 -1
  25. package/dist/src/collection-facets/smart-facets/smart-facet-button.js +3 -2
  26. package/dist/src/collection-facets/smart-facets/smart-facet-button.js.map +1 -1
  27. package/dist/src/collection-facets/smart-facets/smart-facet-dropdown.js +9 -11
  28. package/dist/src/collection-facets/smart-facets/smart-facet-dropdown.js.map +1 -1
  29. package/dist/src/collection-facets/smart-facets/smart-facet-heuristics.js +7 -7
  30. package/dist/src/collection-facets/smart-facets/smart-facet-heuristics.js.map +1 -1
  31. package/dist/src/collection-facets/toggle-switch.js +4 -6
  32. package/dist/src/collection-facets/toggle-switch.js.map +1 -1
  33. package/dist/src/collection-facets.js +309 -310
  34. package/dist/src/collection-facets.js.map +1 -1
  35. package/dist/src/data-source/collection-browser-data-source-interface.d.ts +10 -1
  36. package/dist/src/data-source/collection-browser-data-source-interface.js.map +1 -1
  37. package/dist/src/data-source/collection-browser-data-source.d.ts +19 -1
  38. package/dist/src/data-source/collection-browser-data-source.js +71 -65
  39. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  40. package/dist/src/data-source/collection-browser-query-state.d.ts +1 -2
  41. package/dist/src/data-source/collection-browser-query-state.js.map +1 -1
  42. package/dist/src/data-source/models.d.ts +11 -0
  43. package/dist/src/data-source/models.js.map +1 -1
  44. package/dist/src/empty-placeholder.js +19 -18
  45. package/dist/src/empty-placeholder.js.map +1 -1
  46. package/dist/src/expanded-date-picker.js +6 -10
  47. package/dist/src/expanded-date-picker.js.map +1 -1
  48. package/dist/src/language-code-handler/language-code-handler.js +2 -2
  49. package/dist/src/language-code-handler/language-code-handler.js.map +1 -1
  50. package/dist/src/manage/manage-bar.js +9 -15
  51. package/dist/src/manage/manage-bar.js.map +1 -1
  52. package/dist/src/manage/remove-items-modal-content.js +2 -2
  53. package/dist/src/manage/remove-items-modal-content.js.map +1 -1
  54. package/dist/src/models.d.ts +2 -6
  55. package/dist/src/models.js +44 -54
  56. package/dist/src/models.js.map +1 -1
  57. package/dist/src/restoration-state-handler.d.ts +1 -2
  58. package/dist/src/restoration-state-handler.js +12 -19
  59. package/dist/src/restoration-state-handler.js.map +1 -1
  60. package/dist/src/sort-filter-bar/alpha-bar.js +9 -14
  61. package/dist/src/sort-filter-bar/alpha-bar.js.map +1 -1
  62. package/dist/src/sort-filter-bar/sort-filter-bar.js +14 -24
  63. package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
  64. package/dist/src/tiles/base-tile-component.js +1 -2
  65. package/dist/src/tiles/base-tile-component.js.map +1 -1
  66. package/dist/src/tiles/grid/account-tile.js +5 -7
  67. package/dist/src/tiles/grid/account-tile.js.map +1 -1
  68. package/dist/src/tiles/grid/collection-tile.js +3 -6
  69. package/dist/src/tiles/grid/collection-tile.js.map +1 -1
  70. package/dist/src/tiles/grid/item-tile.js +23 -33
  71. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  72. package/dist/src/tiles/grid/search-tile.js +1 -2
  73. package/dist/src/tiles/grid/search-tile.js.map +1 -1
  74. package/dist/src/tiles/grid/tile-stats.js +2 -3
  75. package/dist/src/tiles/grid/tile-stats.js.map +1 -1
  76. package/dist/src/tiles/hover/hover-pane-controller.js +21 -28
  77. package/dist/src/tiles/hover/hover-pane-controller.js.map +1 -1
  78. package/dist/src/tiles/hover/tile-hover-pane.js +3 -4
  79. package/dist/src/tiles/hover/tile-hover-pane.js.map +1 -1
  80. package/dist/src/tiles/image-block.js +5 -8
  81. package/dist/src/tiles/image-block.js.map +1 -1
  82. package/dist/src/tiles/item-image.js +12 -19
  83. package/dist/src/tiles/item-image.js.map +1 -1
  84. package/dist/src/tiles/list/tile-list-compact.js +17 -25
  85. package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
  86. package/dist/src/tiles/list/tile-list.js +34 -55
  87. package/dist/src/tiles/list/tile-list.js.map +1 -1
  88. package/dist/src/tiles/overlay/icon-overlay.js +1 -2
  89. package/dist/src/tiles/overlay/icon-overlay.js.map +1 -1
  90. package/dist/src/tiles/overlay/text-overlay.js +2 -4
  91. package/dist/src/tiles/overlay/text-overlay.js.map +1 -1
  92. package/dist/src/tiles/text-snippet-block.js +2 -4
  93. package/dist/src/tiles/text-snippet-block.js.map +1 -1
  94. package/dist/src/tiles/tile-dispatcher.js +22 -30
  95. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  96. package/dist/src/tiles/tile-display-value-provider.js +5 -9
  97. package/dist/src/tiles/tile-display-value-provider.js.map +1 -1
  98. package/dist/src/tiles/tile-mediatype-icon.js +12 -19
  99. package/dist/src/tiles/tile-mediatype-icon.js.map +1 -1
  100. package/dist/src/utils/collapse-repeated-quotes.js +1 -1
  101. package/dist/src/utils/collapse-repeated-quotes.js.map +1 -1
  102. package/dist/src/utils/facet-utils.js +3 -5
  103. package/dist/src/utils/facet-utils.js.map +1 -1
  104. package/dist/src/utils/format-count.js +10 -10
  105. package/dist/src/utils/format-count.js.map +1 -1
  106. package/dist/src/utils/resolve-mediatype.js +2 -3
  107. package/dist/src/utils/resolve-mediatype.js.map +1 -1
  108. package/dist/test/collection-browser.test.js +336 -380
  109. package/dist/test/collection-browser.test.js.map +1 -1
  110. package/dist/test/collection-facets/facet-row.test.js +37 -52
  111. package/dist/test/collection-facets/facet-row.test.js.map +1 -1
  112. package/dist/test/collection-facets/facets-template.test.js +17 -23
  113. package/dist/test/collection-facets/facets-template.test.js.map +1 -1
  114. package/dist/test/collection-facets/more-facets-content.test.js +22 -32
  115. package/dist/test/collection-facets/more-facets-content.test.js.map +1 -1
  116. package/dist/test/collection-facets/more-facets-pagination.test.js +16 -22
  117. package/dist/test/collection-facets/more-facets-pagination.test.js.map +1 -1
  118. package/dist/test/collection-facets/toggle-switch.test.js +22 -19
  119. package/dist/test/collection-facets/toggle-switch.test.js.map +1 -1
  120. package/dist/test/collection-facets.test.js +60 -77
  121. package/dist/test/collection-facets.test.js.map +1 -1
  122. package/dist/test/empty-placeholder.test.js +11 -17
  123. package/dist/test/empty-placeholder.test.js.map +1 -1
  124. package/dist/test/expanded-date-picker.test.js +8 -14
  125. package/dist/test/expanded-date-picker.test.js.map +1 -1
  126. package/dist/test/icon-overlay.test.js +7 -6
  127. package/dist/test/icon-overlay.test.js.map +1 -1
  128. package/dist/test/image-block.test.js +16 -26
  129. package/dist/test/image-block.test.js.map +1 -1
  130. package/dist/test/item-image.test.js +23 -32
  131. package/dist/test/item-image.test.js.map +1 -1
  132. package/dist/test/manage/manage-bar.test.js +21 -33
  133. package/dist/test/manage/manage-bar.test.js.map +1 -1
  134. package/dist/test/manage/remove-items-modal-content.test.js +10 -15
  135. package/dist/test/manage/remove-items-modal-content.test.js.map +1 -1
  136. package/dist/test/mocks/mock-search-service.js +2 -3
  137. package/dist/test/mocks/mock-search-service.js.map +1 -1
  138. package/dist/test/restoration-state-handler.test.js +14 -54
  139. package/dist/test/restoration-state-handler.test.js.map +1 -1
  140. package/dist/test/review-block.test.js +16 -18
  141. package/dist/test/review-block.test.js.map +1 -1
  142. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.js +2 -3
  143. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.js.map +1 -1
  144. package/dist/test/sort-filter-bar/alpha-bar.test.js +18 -24
  145. package/dist/test/sort-filter-bar/alpha-bar.test.js.map +1 -1
  146. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +178 -180
  147. package/dist/test/sort-filter-bar/sort-filter-bar.test.js.map +1 -1
  148. package/dist/test/text-overlay.test.js +16 -15
  149. package/dist/test/text-overlay.test.js.map +1 -1
  150. package/dist/test/text-snippet-block.test.js +14 -19
  151. package/dist/test/text-snippet-block.test.js.map +1 -1
  152. package/dist/test/tile-stats.test.js +73 -34
  153. package/dist/test/tile-stats.test.js.map +1 -1
  154. package/dist/test/tiles/grid/account-tile.test.js +25 -25
  155. package/dist/test/tiles/grid/account-tile.test.js.map +1 -1
  156. package/dist/test/tiles/grid/collection-tile.test.js +13 -19
  157. package/dist/test/tiles/grid/collection-tile.test.js.map +1 -1
  158. package/dist/test/tiles/grid/item-tile.test.js +64 -91
  159. package/dist/test/tiles/grid/item-tile.test.js.map +1 -1
  160. package/dist/test/tiles/grid/search-tile.test.js +9 -13
  161. package/dist/test/tiles/grid/search-tile.test.js.map +1 -1
  162. package/dist/test/tiles/hover/hover-pane-controller.test.js +23 -35
  163. package/dist/test/tiles/hover/hover-pane-controller.test.js.map +1 -1
  164. package/dist/test/tiles/hover/tile-hover-pane.test.js +12 -16
  165. package/dist/test/tiles/hover/tile-hover-pane.test.js.map +1 -1
  166. package/dist/test/tiles/list/tile-list-compact.test.js +34 -48
  167. package/dist/test/tiles/list/tile-list-compact.test.js.map +1 -1
  168. package/dist/test/tiles/list/tile-list.test.js +76 -105
  169. package/dist/test/tiles/list/tile-list.test.js.map +1 -1
  170. package/dist/test/tiles/tile-dispatcher.test.js +17 -30
  171. package/dist/test/tiles/tile-dispatcher.test.js.map +1 -1
  172. package/dist/test/tiles/tile-mediatype-icon.test.js +12 -24
  173. package/dist/test/tiles/tile-mediatype-icon.test.js.map +1 -1
  174. package/eslint.config.mjs +53 -53
  175. package/index.html +24 -24
  176. package/local.archive.org.cert +86 -86
  177. package/local.archive.org.key +27 -27
  178. package/package.json +119 -118
  179. package/renovate.json +6 -6
  180. package/src/collection-browser.ts +3071 -2829
  181. package/src/collection-facets/facet-row.ts +299 -296
  182. package/src/collection-facets/more-facets-content.ts +642 -642
  183. package/src/collection-facets.ts +1010 -995
  184. package/src/data-source/collection-browser-data-source-interface.ts +345 -333
  185. package/src/data-source/collection-browser-data-source.ts +1441 -1401
  186. package/src/data-source/collection-browser-query-state.ts +59 -65
  187. package/src/data-source/models.ts +56 -43
  188. package/src/models.ts +864 -870
  189. package/src/restoration-state-handler.ts +546 -544
  190. package/test/collection-browser.test.ts +2413 -2403
  191. package/test/restoration-state-handler.test.ts +480 -510
  192. package/tsconfig.json +25 -20
  193. package/vite.config.ts +29 -22
  194. package/web-dev-server.config.mjs +30 -30
  195. package/web-test-runner.config.mjs +41 -41
@@ -1,6 +1,6 @@
1
1
  import { FilterConstraint, FilterMapBuilder, SearchType, } from '@internetarchive/search-service';
2
2
  import { prefixFilterAggregationKeys, TileModel, SortField, SORT_OPTIONS, } from '../models';
3
- import { FACETLESS_PAGE_ELEMENTS } from './models';
3
+ import { FACETLESS_PAGE_ELEMENTS, } from './models';
4
4
  import { sha1 } from '../utils/sha1';
5
5
  import { log } from '../utils/log';
6
6
  import { mergeSelectedFacets } from '../utils/facet-utils';
@@ -81,6 +81,10 @@ export class CollectionBrowserDataSource {
81
81
  * @inheritdoc
82
82
  */
83
83
  this.collectionTitles = new Map();
84
+ /**
85
+ * @inheritdoc
86
+ */
87
+ this.tvChannelMaps = {};
84
88
  /**
85
89
  * @inheritdoc
86
90
  */
@@ -286,7 +290,6 @@ export class CollectionBrowserDataSource {
286
290
  * @inheritdoc
287
291
  */
288
292
  getTileModelAt(index) {
289
- var _a, _b;
290
293
  const offsetIndex = index + this.offset;
291
294
  const expectedPageNum = Math.floor(offsetIndex / this.pageSize) + 1;
292
295
  const expectedIndexOnPage = offsetIndex % this.pageSize;
@@ -296,7 +299,7 @@ export class CollectionBrowserDataSource {
296
299
  if (!this.pages[page]) {
297
300
  // If we encounter a missing page, either we're past all the results or the page data is sparse.
298
301
  // So just return the tile at the expected position if it exists.
299
- return (_a = this.pages[expectedPageNum]) === null || _a === void 0 ? void 0 : _a[expectedIndexOnPage];
302
+ return this.pages[expectedPageNum]?.[expectedIndexOnPage];
300
303
  }
301
304
  if (tilesSeen + this.pages[page].length > offsetIndex) {
302
305
  return this.pages[page][offsetIndex - tilesSeen];
@@ -304,7 +307,7 @@ export class CollectionBrowserDataSource {
304
307
  tilesSeen += this.pages[page].length;
305
308
  page += 1;
306
309
  }
307
- return (_b = this.pages[expectedPageNum]) === null || _b === void 0 ? void 0 : _b[expectedIndexOnPage];
310
+ return this.pages[expectedPageNum]?.[expectedIndexOnPage];
308
311
  }
309
312
  /**
310
313
  * @inheritdoc
@@ -390,7 +393,6 @@ export class CollectionBrowserDataSource {
390
393
  * (i.e., they aren't suppressed or already loading, etc.)
391
394
  */
392
395
  get canFetchFacets() {
393
- var _a;
394
396
  // Don't fetch facets if they are suppressed entirely or not required for the current profile page element
395
397
  if (this.host.facetLoadStrategy === 'off')
396
398
  return false;
@@ -401,7 +403,7 @@ export class CollectionBrowserDataSource {
401
403
  if (this.host.facetLoadStrategy !== 'eager' && !this.facetsReadyToLoad)
402
404
  return false;
403
405
  // Don't fetch facets again if they are already fetched or pending
404
- const facetsAlreadyFetched = Object.keys((_a = this.aggregations) !== null && _a !== void 0 ? _a : {}).length > 0;
406
+ const facetsAlreadyFetched = Object.keys(this.aggregations ?? {}).length > 0;
405
407
  if (this.facetsLoading || facetsAlreadyFetched)
406
408
  return false;
407
409
  return true;
@@ -447,12 +449,11 @@ export class CollectionBrowserDataSource {
447
449
  * @inheritdoc
448
450
  */
449
451
  get canPerformSearch() {
450
- var _a, _b;
451
452
  if (!this.host.searchService)
452
453
  return false;
453
- const trimmedQuery = (_a = this.host.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
454
+ const trimmedQuery = this.host.baseQuery?.trim();
454
455
  const hasNonEmptyQuery = !!trimmedQuery;
455
- const hasIdentifiers = !!((_b = this.host.identifiers) === null || _b === void 0 ? void 0 : _b.length);
456
+ const hasIdentifiers = !!this.host.identifiers?.length;
456
457
  const isCollectionSearch = !!this.host.withinCollection;
457
458
  const isProfileSearch = !!this.host.withinProfile;
458
459
  const hasProfileElement = !!this.host.profileElement;
@@ -521,11 +522,10 @@ export class CollectionBrowserDataSource {
521
522
  * no longer relevant. Not meant to be human-readable.
522
523
  */
523
524
  get pageFetchQueryKey() {
524
- var _a, _b, _c;
525
525
  const profileKey = `pf;${this.host.withinProfile}--pe;${this.host.profileElement}`;
526
- const pageTarget = (_a = this.host.withinCollection) !== null && _a !== void 0 ? _a : profileKey;
527
- const sortField = (_b = this.host.selectedSort) !== null && _b !== void 0 ? _b : 'none';
528
- const sortDirection = (_c = this.host.sortDirection) !== null && _c !== void 0 ? _c : 'none';
526
+ const pageTarget = this.host.withinCollection ?? profileKey;
527
+ const sortField = this.host.selectedSort ?? 'none';
528
+ const sortDirection = this.host.sortDirection ?? 'none';
529
529
  return `fq:${this.fullQuery}-pt:${pageTarget}-st:${this.host.searchType}-sf:${sortField}-sd:${sortDirection}`;
530
530
  }
531
531
  /**
@@ -533,9 +533,8 @@ export class CollectionBrowserDataSource {
533
533
  * are not relevant in determining aggregation queries.
534
534
  */
535
535
  get facetFetchQueryKey() {
536
- var _a;
537
536
  const profileKey = `pf;${this.host.withinProfile}--pe;${this.host.profileElement}`;
538
- const pageTarget = (_a = this.host.withinCollection) !== null && _a !== void 0 ? _a : profileKey;
537
+ const pageTarget = this.host.withinCollection ?? profileKey;
539
538
  return `facets-fq:${this.fullQuery}-pt:${pageTarget}-st:${this.host.searchType}`;
540
539
  }
541
540
  /**
@@ -579,23 +578,6 @@ export class CollectionBrowserDataSource {
579
578
  if (selectedCreatorFilter) {
580
579
  builder.addFilter('firstCreator', selectedCreatorFilter, FilterConstraint.INCLUDE);
581
580
  }
582
- // Add any TV clip type filter, if applicable
583
- if (this.host.searchType === SearchType.TV) {
584
- switch (this.host.tvClipFilter) {
585
- case 'commercials':
586
- builder.addFilter('ad_id', '*', FilterConstraint.INCLUDE);
587
- break;
588
- case 'factchecks':
589
- builder.addFilter('factcheck', '*', FilterConstraint.INCLUDE);
590
- break;
591
- case 'quotes':
592
- builder.addFilter('clip', '1', FilterConstraint.INCLUDE);
593
- break;
594
- case 'all':
595
- default:
596
- break;
597
- }
598
- }
599
581
  const filterMap = builder.build();
600
582
  return filterMap;
601
583
  }
@@ -609,7 +591,6 @@ export class CollectionBrowserDataSource {
609
591
  * @returns A Promise resolving to the uid to apply to the request
610
592
  */
611
593
  async requestUID(params, kind) {
612
- var _a;
613
594
  const paramsToHash = JSON.stringify({
614
595
  pageType: params.pageType,
615
596
  pageTarget: params.pageTarget,
@@ -621,7 +602,7 @@ export class CollectionBrowserDataSource {
621
602
  });
622
603
  const fullQueryHash = (await sha1(paramsToHash)).slice(0, 20); // First 80 bits of SHA-1 are plenty for this
623
604
  const sessionId = (await this.host.getSessionId()).slice(0, 20); // Likewise
624
- const page = (_a = params.page) !== null && _a !== void 0 ? _a : 0;
605
+ const page = params.page ?? 0;
625
606
  const kindPrefix = kind.charAt(0); // f = full, h = hits, a = aggregations
626
607
  const currentTime = Date.now();
627
608
  return `R:${fullQueryHash}-S:${sessionId}-P:${page}-K:${kindPrefix}-T:${currentTime}`;
@@ -630,8 +611,7 @@ export class CollectionBrowserDataSource {
630
611
  * @inheritdoc
631
612
  */
632
613
  get pageSpecifierParams() {
633
- var _a;
634
- if ((_a = this.host.identifiers) === null || _a === void 0 ? void 0 : _a.length) {
614
+ if (this.host.identifiers?.length) {
635
615
  return {
636
616
  pageType: 'client_document_fetch',
637
617
  };
@@ -657,9 +637,8 @@ export class CollectionBrowserDataSource {
657
637
  * The full query, including year facets and date range clauses
658
638
  */
659
639
  get fullQuery() {
660
- var _a;
661
640
  const parts = [];
662
- const trimmedQuery = (_a = this.host.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
641
+ const trimmedQuery = this.host.baseQuery?.trim();
663
642
  if (trimmedQuery)
664
643
  parts.push(trimmedQuery);
665
644
  if (this.host.identifiers) {
@@ -680,14 +659,13 @@ export class CollectionBrowserDataSource {
680
659
  * Example: `mediatype:("collection" OR "audio" OR -"etree") AND year:("2000" OR "2001")`
681
660
  */
682
661
  get facetQuery() {
683
- var _a;
684
662
  if (!this.host.selectedFacets)
685
663
  return undefined;
686
664
  const facetClauses = [];
687
665
  for (const [facetName, facetValues] of Object.entries(this.host.selectedFacets)) {
688
666
  facetClauses.push(this.buildFacetClause(facetName, facetValues));
689
667
  }
690
- return (_a = this.joinFacetClauses(facetClauses)) === null || _a === void 0 ? void 0 : _a.trim();
668
+ return this.joinFacetClauses(facetClauses)?.trim();
691
669
  }
692
670
  get dateRangeQueryClause() {
693
671
  if (!this.host.minSelectedDate || !this.host.maxSelectedDate) {
@@ -775,8 +753,7 @@ export class CollectionBrowserDataSource {
775
753
  * the current search state.
776
754
  */
777
755
  async fetchFacets() {
778
- var _a, _b, _c, _d, _e, _f, _g;
779
- const trimmedQuery = (_a = this.host.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
756
+ const trimmedQuery = this.host.baseQuery?.trim();
780
757
  if (!this.canPerformSearch)
781
758
  return;
782
759
  const { facetFetchQueryKey } = this;
@@ -797,8 +774,8 @@ export class CollectionBrowserDataSource {
797
774
  // The default aggregations for the search_results page type should be what we need here.
798
775
  };
799
776
  params.uid = await this.requestUID({ ...params, sort: sortParams }, 'aggregations');
800
- const searchResponse = await ((_b = this.host.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.host.searchType));
801
- const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
777
+ const searchResponse = await this.host.searchService?.search(params, this.host.searchType);
778
+ const success = searchResponse?.success;
802
779
  // This is checking to see if the query has changed since the data was fetched.
803
780
  // If so, we just want to discard this set of aggregations because they are
804
781
  // likely no longer valid for the newer query.
@@ -807,11 +784,11 @@ export class CollectionBrowserDataSource {
807
784
  if (queryChangedSinceFetch)
808
785
  return;
809
786
  if (!success) {
810
- const errorMsg = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _c === void 0 ? void 0 : _c.message;
811
- const detailMsg = (_e = (_d = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _d === void 0 ? void 0 : _d.details) === null || _e === void 0 ? void 0 : _e.message;
787
+ const errorMsg = searchResponse?.error?.message;
788
+ const detailMsg = searchResponse?.error?.details?.message;
812
789
  if (!errorMsg && !detailMsg) {
813
790
  // @ts-expect-error: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
814
- (_g = (_f = window === null || window === void 0 ? void 0 : window.Sentry) === null || _f === void 0 ? void 0 : _f.captureMessage) === null || _g === void 0 ? void 0 : _g.call(_f, 'Missing or malformed facet response from backend', 'error');
791
+ window?.Sentry?.captureMessage?.('Missing or malformed facet response from backend', 'error');
815
792
  }
816
793
  this.setFacetsLoading(false);
817
794
  return;
@@ -820,8 +797,8 @@ export class CollectionBrowserDataSource {
820
797
  this.aggregations = aggregations;
821
798
  this.histogramAggregation =
822
799
  this.host.searchType === SearchType.TV
823
- ? aggregations === null || aggregations === void 0 ? void 0 : aggregations.date_histogram
824
- : aggregations === null || aggregations === void 0 ? void 0 : aggregations.year_histogram;
800
+ ? aggregations?.date_histogram
801
+ : aggregations?.year_histogram;
825
802
  if (collectionTitles) {
826
803
  for (const [id, title] of Object.entries(collectionTitles)) {
827
804
  this.collectionTitles.set(id, title);
@@ -852,8 +829,7 @@ export class CollectionBrowserDataSource {
852
829
  * if `pageNumber != 1`, defaulting to a single page.
853
830
  */
854
831
  async fetchPage(pageNumber, numInitialPages = 1) {
855
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
856
- const trimmedQuery = (_a = this.host.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
832
+ const trimmedQuery = this.host.baseQuery?.trim();
857
833
  // reset loading status
858
834
  if (!this.canPerformSearch) {
859
835
  this.setSearchResultsLoading(false);
@@ -904,9 +880,9 @@ export class CollectionBrowserDataSource {
904
880
  };
905
881
  params.uid = await this.requestUID(params, 'hits');
906
882
  // log('=== FIRING PAGE REQUEST ===', params);
907
- const searchResponse = await ((_b = this.host.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.host.searchType));
883
+ const searchResponse = await this.host.searchService?.search(params, this.host.searchType);
908
884
  // log('=== RECEIVED PAGE RESPONSE IN CB ===', searchResponse);
909
- const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
885
+ const success = searchResponse?.success;
910
886
  // This is checking to see if the fetch has been invalidated since it was fired off.
911
887
  // If so, we just want to discard the response since it is for an obsolete query state.
912
888
  if (!this.fetchesInProgress.has(currentPageKey))
@@ -915,13 +891,13 @@ export class CollectionBrowserDataSource {
915
891
  this.fetchesInProgress.delete(`${pageFetchQueryKey}-p:${pageNumber + i}`);
916
892
  }
917
893
  if (!success) {
918
- const errorMsg = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _c === void 0 ? void 0 : _c.message;
919
- const detailMsg = (_e = (_d = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _d === void 0 ? void 0 : _d.details) === null || _e === void 0 ? void 0 : _e.message;
920
- this.queryErrorMessage = `${errorMsg !== null && errorMsg !== void 0 ? errorMsg : ''}${detailMsg ? `; ${detailMsg}` : ''}`;
894
+ const errorMsg = searchResponse?.error?.message;
895
+ const detailMsg = searchResponse?.error?.details?.message;
896
+ this.queryErrorMessage = `${errorMsg ?? ''}${detailMsg ? `; ${detailMsg}` : ''}`;
921
897
  if (!this.queryErrorMessage) {
922
898
  this.queryErrorMessage = 'Missing or malformed response from backend';
923
899
  // @ts-expect-error: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
924
- (_g = (_f = window === null || window === void 0 ? void 0 : window.Sentry) === null || _f === void 0 ? void 0 : _f.captureMessage) === null || _g === void 0 ? void 0 : _g.call(_f, this.queryErrorMessage, 'error');
900
+ window?.Sentry?.captureMessage?.(this.queryErrorMessage, 'error');
925
901
  }
926
902
  this.setSearchResultsLoading(false);
927
903
  this.requestHostUpdate();
@@ -942,10 +918,10 @@ export class CollectionBrowserDataSource {
942
918
  this.host.applyDefaultCollectionSort(this.collectionExtraInfo);
943
919
  }
944
920
  if (this.collectionExtraInfo) {
945
- this.parentCollections = [].concat((_j = (_h = this.collectionExtraInfo.public_metadata) === null || _h === void 0 ? void 0 : _h.collection) !== null && _j !== void 0 ? _j : []);
921
+ this.parentCollections = [].concat(this.collectionExtraInfo.public_metadata?.collection ?? []);
946
922
  // Update the TV collection status now that we know the parent collections
947
923
  this.host.isTVCollection =
948
- ((_k = this.host.withinCollection) === null || _k === void 0 ? void 0 : _k.startsWith('TV-')) ||
924
+ this.host.withinCollection?.startsWith('TV-') ||
949
925
  this.host.withinCollection === 'tvnews' ||
950
926
  this.host.withinCollection === 'tvarchive' ||
951
927
  this.parentCollections.includes('tvnews') ||
@@ -965,7 +941,7 @@ export class CollectionBrowserDataSource {
965
941
  this.collectionTitles.set(id, title);
966
942
  }
967
943
  // Also add the target collection's title if available
968
- const targetTitle = (_m = (_l = this.collectionExtraInfo) === null || _l === void 0 ? void 0 : _l.public_metadata) === null || _m === void 0 ? void 0 : _m.title;
944
+ const targetTitle = this.collectionExtraInfo?.public_metadata?.title;
969
945
  if (withinCollection && targetTitle) {
970
946
  this.collectionTitles.set(withinCollection, targetTitle);
971
947
  }
@@ -1024,7 +1000,7 @@ export class CollectionBrowserDataSource {
1024
1000
  addFetchedResultsToDataSource(pageNumber, results, needsReload = true) {
1025
1001
  const tiles = [];
1026
1002
  const requestSource = this.hitRequestSource;
1027
- results === null || results === void 0 ? void 0 : results.forEach(result => {
1003
+ results?.forEach(result => {
1028
1004
  if (!result.identifier)
1029
1005
  return;
1030
1006
  tiles.push(new TileModel(result, requestSource));
@@ -1038,8 +1014,7 @@ export class CollectionBrowserDataSource {
1038
1014
  * Fetches the aggregation buckets for the given prefix filter type.
1039
1015
  */
1040
1016
  async fetchPrefixFilterBuckets(filterType) {
1041
- var _a, _b, _c, _d, _e, _f, _g;
1042
- const trimmedQuery = (_a = this.host.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1017
+ const trimmedQuery = this.host.baseQuery?.trim();
1043
1018
  if (!this.canPerformSearch)
1044
1019
  return [];
1045
1020
  const filterAggregationKey = prefixFilterAggregationKeys[filterType];
@@ -1056,8 +1031,8 @@ export class CollectionBrowserDataSource {
1056
1031
  aggregationsSize: 26,
1057
1032
  };
1058
1033
  params.uid = await this.requestUID({ ...params, sort: sortParams }, 'aggregations');
1059
- const searchResponse = await ((_b = this.host.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.host.searchType));
1060
- return ((_g = (_f = (_e = (_d = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.aggregations) === null || _e === void 0 ? void 0 : _e[filterAggregationKey]) === null || _f === void 0 ? void 0 : _f.buckets) !== null && _g !== void 0 ? _g : []);
1034
+ const searchResponse = await this.host.searchService?.search(params, this.host.searchType);
1035
+ return (searchResponse?.success?.response?.aggregations?.[filterAggregationKey]?.buckets ?? []);
1061
1036
  }
1062
1037
  /**
1063
1038
  * Fetches and caches the prefix filter counts for the given filter type.
@@ -1099,5 +1074,36 @@ export class CollectionBrowserDataSource {
1099
1074
  this.updatePrefixFiltersForCurrentSort();
1100
1075
  this.requestHostUpdate();
1101
1076
  }
1077
+ /**
1078
+ * @inheritdoc
1079
+ */
1080
+ populateTVChannelMaps() {
1081
+ // To ensure that we only make these requests once, cache the Promise returned by the
1082
+ // first call, and return the same Promise on repeated calls.
1083
+ // Resolves once both maps have been retrieved and saved in the data source.
1084
+ if (!this._tvMapsPromise) {
1085
+ this._tvMapsPromise = this._fetchTVChannelMaps();
1086
+ }
1087
+ return this._tvMapsPromise;
1088
+ }
1089
+ /**
1090
+ * Internal function implementing the actual fetches for TV channel mappings.
1091
+ * This should only called by the public populateTVChannelMaps method, which is guarded so
1092
+ * that we do not make extra requests for these rather large mappings.
1093
+ */
1094
+ async _fetchTVChannelMaps() {
1095
+ const baseURL = 'https://av.archive.org/etc';
1096
+ const dateStr = new Date().toISOString().slice(0, 10); // YYYY-MM-DD
1097
+ const chan2networkPromise = fetch(`${baseURL}/chan2network.json?date=${dateStr}`);
1098
+ const program2chansPromise = fetch(`${baseURL}/program2chans.json?date=${dateStr}`);
1099
+ const [chan2networkResponse, program2chansResponse] = await Promise.all([
1100
+ chan2networkPromise,
1101
+ program2chansPromise,
1102
+ ]);
1103
+ this.tvChannelMaps.channelToNetwork = new Map(Object.entries(await chan2networkResponse.json()));
1104
+ this.tvChannelMaps.programToChannels = new Map(Object.entries(await program2chansResponse.json()));
1105
+ this.requestHostUpdate();
1106
+ return this.tvChannelMaps;
1107
+ }
1102
1108
  }
1103
1109
  //# sourceMappingURL=collection-browser-data-source.js.map