@behindthemusictree/app-kit 33.2.0 → 34.0.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.
@@ -42,6 +42,10 @@ __export(genre_tree_exports, {
42
42
  CriteriaUpdateSchema: () => CriteriaUpdateSchema,
43
43
  FORM_RATING_NULL_VALUE: () => FORM_RATING_NULL_VALUE,
44
44
  FUZZY_MIN_SIMILARITY: () => FUZZY_MIN_SIMILARITY,
45
+ GenreCatalogueCountsSchema: () => GenreCatalogueCountsSchema,
46
+ GenreCountsSchema: () => GenreCountsSchema,
47
+ GenreCoverageSchema: () => GenreCoverageSchema,
48
+ GenrePlaylistSummarySchema: () => GenrePlaylistSummarySchema,
45
49
  GenrePlaylistUuidSchema: () => GenrePlaylistUuidSchema,
46
50
  GenreSearchResultSchema: () => GenreSearchResultSchema,
47
51
  GenreSearchResultsSchema: () => GenreSearchResultsSchema,
@@ -50,6 +54,8 @@ __export(genre_tree_exports, {
50
54
  MbArtistDetailedSchema: () => MbArtistDetailedSchema,
51
55
  MbRecordingDetailedSchema: () => MbRecordingDetailedSchema,
52
56
  NO_VIDEO_LABEL: () => NO_VIDEO_LABEL,
57
+ ReferenceGenreDetailedSchema: () => ReferenceGenreDetailedSchema,
58
+ ReferenceGenrePlaylistSchema: () => ReferenceGenrePlaylistSchema,
53
59
  RegionGenreLexiconEntrySchema: () => RegionGenreLexiconEntrySchema,
54
60
  RegionGenreLexiconSchema: () => RegionGenreLexiconSchema,
55
61
  SEARCH_DEBOUNCE_MS: () => SEARCH_DEBOUNCE_MS,
@@ -59,6 +65,8 @@ __export(genre_tree_exports, {
59
65
  SongHistorySchema: () => SongHistorySchema,
60
66
  SongSearchResultSchema: () => SongSearchResultSchema,
61
67
  SongSearchResultsSchema: () => SongSearchResultsSchema,
68
+ SubgenreCountsSchema: () => SubgenreCountsSchema,
69
+ SubgenreScopeSchema: () => SubgenreScopeSchema,
62
70
  TrackBaseSchema: () => TrackBaseSchema,
63
71
  TrackList: () => TrackList,
64
72
  TrackListFromArtist: () => TrackListFromArtist,
@@ -67,6 +75,7 @@ __export(genre_tree_exports, {
67
75
  TrackListOrigin: () => TrackListOrigin,
68
76
  TrackListOriginFromArtist: () => TrackListOriginFromArtist,
69
77
  TrackListOriginFromCriteriaPlaylist: () => TrackListOriginFromCriteriaPlaylist,
78
+ TrackListOriginFromGenreCatalogue: () => TrackListOriginFromGenreCatalogue,
70
79
  TrackListOriginFromTrack: () => TrackListOriginFromTrack,
71
80
  TrackListOriginType: () => TrackListOriginType,
72
81
  TrackListProvider: () => TrackListProvider,
@@ -78,12 +87,17 @@ __export(genre_tree_exports, {
78
87
  artistEndpoints: () => artistEndpoints,
79
88
  artistQueryKeys: () => artistQueryKeys,
80
89
  capitalizeFirstLetter: () => capitalizeFirstLetter,
90
+ defaultGenreMusicSelection: () => defaultGenreMusicSelection,
81
91
  editGenreSongPages: () => editGenreSongPages,
82
92
  foldSearchText: () => foldSearchText,
83
93
  formatTime: () => formatTime,
84
94
  genreEndpoints: () => genreEndpoints,
95
+ genreMusicCount: () => genreMusicCount,
96
+ genreMusicQueryParams: () => genreMusicQueryParams,
97
+ genreMusicSelectionKey: () => genreMusicSelectionKey,
85
98
  genrePlaylistEndpoints: () => genrePlaylistEndpoints,
86
99
  genrePlaylistQueryKeys: () => genrePlaylistQueryKeys,
100
+ genrePlaylistTrackCount: () => genrePlaylistTrackCount,
87
101
  genreQueryKeys: () => genreQueryKeys,
88
102
  genreSearchQueryKeys: () => genreSearchQueryKeys,
89
103
  genreUpdateMutationKey: () => genreUpdateMutationKey,
@@ -135,15 +149,206 @@ __export(genre_tree_exports, {
135
149
  module.exports = __toCommonJS(genre_tree_exports);
136
150
 
137
151
  // src/genre-tree/useGenre.ts
138
- var import_zod23 = require("zod");
152
+ var import_zod24 = require("zod");
153
+
154
+ // src/genre-tree/schemas/criteria/detailed.ts
155
+ var import_zod11 = require("zod");
156
+
157
+ // src/genre-tree/schemas/genre-music.ts
158
+ var import_zod3 = require("zod");
159
+
160
+ // src/genre-tree/schemas/criteria-playlist/minimum.ts
161
+ var import_zod2 = require("zod");
162
+
163
+ // src/genre-tree/schemas/ids.ts
164
+ var import_zod = require("zod");
165
+ var GenreUuidSchema = import_zod.z.string().uuid().brand();
166
+ var GenrePlaylistUuidSchema = import_zod.z.string().uuid().brand();
167
+
168
+ // src/genre-tree/schemas/criteria-playlist/minimum.ts
169
+ var CriteriaPlaylistMinimumSchema = import_zod2.z.object({
170
+ uuid: GenrePlaylistUuidSchema,
171
+ name: import_zod2.z.string()
172
+ });
173
+
174
+ // src/genre-tree/schemas/genre-music.ts
175
+ var CountSchema = import_zod3.z.number().int().nonnegative();
176
+ var SubgenreCountsSchema = import_zod3.z.union([
177
+ import_zod3.z.object({ canonical: CountSchema, regional: CountSchema, all: CountSchema }).strict(),
178
+ import_zod3.z.object({ all: CountSchema }).strict()
179
+ ]).refine(
180
+ (counts) => !("canonical" in counts) || counts.all >= counts.canonical && counts.all >= counts.regional,
181
+ "The combined count must include both scoped selections"
182
+ );
183
+ var GenreCountsSchema = import_zod3.z.object({
184
+ genreOnlyTracksCount: CountSchema,
185
+ genreAndSubgenresTracksCount: SubgenreCountsSchema
186
+ });
187
+ var includesDirectSongs = (counts) => Object.values(counts.genreAndSubgenresTracksCount).every((count) => count >= counts.genreOnlyTracksCount);
188
+ var GenreCatalogueCountsSchema = GenreCountsSchema.refine(includesDirectSongs, "Every inclusive count must include the genre itself").brand();
189
+ var GenrePlaylistSummarySchema = CriteriaPlaylistMinimumSchema.extend(GenreCountsSchema.shape).refine(includesDirectSongs, "Every inclusive count must include the genre itself").brand();
190
+ var GenreCoverageSchema = import_zod3.z.enum(["genreOnly", "genreAndSubgenres"]);
191
+ var SubgenreScopeSchema = import_zod3.z.enum(["canonical", "regional", "all"]);
192
+
193
+ // src/genre-tree/schemas/criteria/minimum.ts
194
+ var import_zod4 = require("zod");
195
+ var CriteriaMinimumSchema = import_zod4.z.object({
196
+ uuid: GenreUuidSchema,
197
+ name: import_zod4.z.string(),
198
+ side: import_zod4.z.enum(["core", "pop"]).nullable().optional(),
199
+ wikidataId: import_zod4.z.string().nullable().optional()
200
+ });
201
+
202
+ // src/genre-tree/schemas/track/base.ts
203
+ var import_zod8 = require("zod");
204
+
205
+ // src/genre-tree/schemas/artist-minimum.ts
206
+ var import_zod5 = require("zod");
207
+ var ArtistMinimumSchema = import_zod5.z.object({
208
+ uuid: import_zod5.z.string().uuid(),
209
+ name: import_zod5.z.string(),
210
+ isSpecialPurpose: import_zod5.z.boolean().optional()
211
+ });
212
+
213
+ // src/genre-tree/schemas/album-minimum.ts
214
+ var import_zod6 = require("zod");
215
+ var AlbumMinimumSchema = import_zod6.z.object({
216
+ uuid: import_zod6.z.string().uuid(),
217
+ name: import_zod6.z.string(),
218
+ albumArtists: import_zod6.z.array(ArtistMinimumSchema).nullable().optional()
219
+ });
220
+
221
+ // src/genre-tree/schemas/uuid-resource.ts
222
+ var import_zod7 = require("zod");
223
+ var UuidResourceSchema = import_zod7.z.object({
224
+ uuid: import_zod7.z.string().uuid()
225
+ });
226
+
227
+ // src/genre-tree/schemas/track/base.ts
228
+ var TrackBaseSchema = UuidResourceSchema.extend({
229
+ title: import_zod8.z.string(),
230
+ artists: import_zod8.z.array(ArtistMinimumSchema).nullable().optional(),
231
+ album: AlbumMinimumSchema.nullable().optional(),
232
+ trackNumber: import_zod8.z.number().nullable().optional(),
233
+ // null for a song not yet linked to a genre.
234
+ genre: CriteriaMinimumSchema.nullable(),
235
+ rating: import_zod8.z.number().min(0).max(10).nullable().optional(),
236
+ language: import_zod8.z.string().nullable().optional(),
237
+ playCount: import_zod8.z.number().min(0),
238
+ createdOn: import_zod8.z.string().datetime(),
239
+ updatedOn: import_zod8.z.string().datetime().nullable().optional()
240
+ });
241
+
242
+ // src/genre-tree/schemas/track/minimum.ts
243
+ var TrackMinimumSchema = TrackBaseSchema.pick({
244
+ uuid: true,
245
+ title: true,
246
+ artists: true
247
+ });
248
+
249
+ // src/genre-tree/schemas/criteria/lineage-rel/without-ascendant.ts
250
+ var import_zod9 = require("zod");
251
+ var CriteriaLineageRelWithoutAscendantSchema = import_zod9.z.object({
252
+ descendant: CriteriaMinimumSchema,
253
+ degree: import_zod9.z.number()
254
+ });
255
+
256
+ // src/genre-tree/schemas/criteria/lineage-rel/without-descendant.ts
257
+ var import_zod10 = require("zod");
258
+ var CriteriaLineageRelWithoutDescendantSchema = import_zod10.z.object({
259
+ ascendant: CriteriaMinimumSchema,
260
+ degree: import_zod10.z.number()
261
+ });
262
+
263
+ // src/genre-tree/schemas/criteria/detailed.ts
264
+ var CriteriaDetailedSchema = import_zod11.z.object({
265
+ uuid: GenreUuidSchema,
266
+ name: import_zod11.z.string(),
267
+ summary: import_zod11.z.string().nullable(),
268
+ // Optional until every deployed API serves it.
269
+ wikidataId: import_zod11.z.string().nullable().optional(),
270
+ parent: CriteriaMinimumSchema.nullable(),
271
+ ascendants: import_zod11.z.array(CriteriaLineageRelWithoutDescendantSchema),
272
+ descendants: import_zod11.z.array(CriteriaLineageRelWithoutAscendantSchema),
273
+ root: CriteriaMinimumSchema,
274
+ children: import_zod11.z.array(CriteriaMinimumSchema),
275
+ catalogue: GenreCatalogueCountsSchema.optional(),
276
+ criteriaPlaylist: import_zod11.z.union([GenrePlaylistSummarySchema, CriteriaPlaylistMinimumSchema]),
277
+ tracks: import_zod11.z.array(TrackMinimumSchema),
278
+ essentialSongs: import_zod11.z.array(TrackMinimumSchema),
279
+ tracksCount: import_zod11.z.number(),
280
+ updatedOn: import_zod11.z.string().datetime().nullable()
281
+ });
282
+
283
+ // src/genre-tree/schemas/criteria-playlist/simple.ts
284
+ var import_zod13 = require("zod");
285
+
286
+ // src/genre-tree/schemas/criteria-playlist/detailed.ts
287
+ var import_zod12 = require("zod");
288
+ var CriteriaPlaylistDetailedSchema = import_zod12.z.object({
289
+ uuid: GenrePlaylistUuidSchema,
290
+ name: import_zod12.z.string(),
291
+ tracksCount: import_zod12.z.number(),
292
+ genreOnlyTracksCount: GenreCountsSchema.shape.genreOnlyTracksCount.optional(),
293
+ genreAndSubgenresTracksCount: GenreCountsSchema.shape.genreAndSubgenresTracksCount.optional(),
294
+ catalogue: GenreCatalogueCountsSchema.optional(),
295
+ // Summed YouTube views of the same songs as `tracksCount`. Optional: hear-api has no view counts.
296
+ viewsCount: import_zod12.z.number().optional(),
297
+ durationInSec: import_zod12.z.number().min(0).nullable().optional(),
298
+ durationStrInHourMinSec: import_zod12.z.string().nullable().optional(),
299
+ // Nullable: the "Genreless" root playlist has no criteria attached and is never updated.
300
+ criteria: CriteriaMinimumSchema.nullable(),
301
+ parent: CriteriaPlaylistMinimumSchema.nullable(),
302
+ root: CriteriaPlaylistMinimumSchema,
303
+ createdOn: import_zod12.z.string(),
304
+ updatedOn: import_zod12.z.string().nullable()
305
+ });
306
+
307
+ // src/genre-tree/schemas/criteria-playlist/simple.ts
308
+ var CriteriaPlaylistSimpleSchema = CriteriaPlaylistDetailedSchema.pick({
309
+ uuid: true,
310
+ name: true,
311
+ criteria: true,
312
+ parent: true,
313
+ root: true,
314
+ tracksCount: true,
315
+ genreOnlyTracksCount: true,
316
+ genreAndSubgenresTracksCount: true,
317
+ catalogue: true,
318
+ viewsCount: true,
319
+ createdOn: true,
320
+ updatedOn: true
321
+ }).extend({
322
+ // Only on the tree/list payloads, not the detail endpoint — hence not on the detailed schema.
323
+ isUnacceptedRoot: import_zod13.z.boolean(),
324
+ // Optional: a backend that does not curate umbrella genres omits it.
325
+ isUmbrella: import_zod13.z.boolean().optional(),
326
+ // Optional: only the grow tree payload carries it; null when the genre has no scene.
327
+ scene: import_zod13.z.enum(["commercial", "underground"]).nullable().optional()
328
+ });
329
+
330
+ // src/genre-tree/schemas/reference-genre.ts
331
+ var ReferenceGenreDetailedSchema = CriteriaDetailedSchema.extend({
332
+ catalogue: GenreCatalogueCountsSchema,
333
+ criteriaPlaylist: GenrePlaylistSummarySchema
334
+ });
335
+ var ReferenceGenrePlaylistSchema = CriteriaPlaylistSimpleSchema.extend({
336
+ ...GenreCountsSchema.shape,
337
+ catalogue: GenreCatalogueCountsSchema
338
+ }).superRefine((playlist, ctx) => {
339
+ const counts = GenreCatalogueCountsSchema.safeParse(playlist);
340
+ if (!counts.success) for (const issue of counts.error.issues) ctx.addIssue({ code: "custom", path: issue.path, message: issue.message });
341
+ });
342
+
343
+ // src/genre-tree/useGenre.ts
139
344
  var import_react_query5 = require("@tanstack/react-query");
140
345
  var import_react6 = require("react");
141
346
 
142
347
  // src/transport/PlaybackContext.tsx
143
348
  var import_react = require("react");
144
- var import_zod = require("zod");
349
+ var import_zod14 = require("zod");
145
350
  var import_jsx_runtime = require("react/jsx-runtime");
146
- var PlaybackContextSchema = import_zod.z.object({ country: import_zod.z.string().regex(/^[A-Z]{2}$/).nullable() });
351
+ var PlaybackContextSchema = import_zod14.z.object({ country: import_zod14.z.string().regex(/^[A-Z]{2}$/).nullable() });
147
352
  var unmanaged = {
148
353
  country: null,
149
354
  key: null,
@@ -652,14 +857,14 @@ var useFetchWrapper = (getBackendBaseUrl) => {
652
857
  };
653
858
 
654
859
  // src/genre-tree/useGenrePlaylist.ts
655
- var import_zod9 = require("zod");
860
+ var import_zod17 = require("zod");
656
861
  var import_react_query3 = require("@tanstack/react-query");
657
862
 
658
863
  // src/transport/lib/use-query-with-parse.ts
659
864
  var import_react_query2 = require("@tanstack/react-query");
660
865
 
661
866
  // src/transport/lib/parse-with-log.ts
662
- var import_zod2 = require("zod");
867
+ var import_zod15 = require("zod");
663
868
  function parseWithLog(schema, data, context) {
664
869
  const result = schema.safeParse(data);
665
870
  if (!result.success) {
@@ -667,7 +872,7 @@ function parseWithLog(schema, data, context) {
667
872
  if (data == null) {
668
873
  throw new Error(`${prefix} received null response before schema validation`);
669
874
  }
670
- console.error(`${prefix} schema validation failed`, import_zod2.z.flattenError(result.error));
875
+ console.error(`${prefix} schema validation failed`, import_zod15.z.flattenError(result.error));
671
876
  throw result.error;
672
877
  }
673
878
  return result.data;
@@ -689,80 +894,16 @@ function useQueryWithParse({
689
894
  });
690
895
  }
691
896
 
692
- // src/genre-tree/schemas/criteria-playlist/simple.ts
693
- var import_zod7 = require("zod");
694
-
695
- // src/genre-tree/schemas/criteria-playlist/detailed.ts
696
- var import_zod6 = require("zod");
697
-
698
- // src/genre-tree/schemas/ids.ts
699
- var import_zod3 = require("zod");
700
- var GenreUuidSchema = import_zod3.z.string().uuid().brand();
701
- var GenrePlaylistUuidSchema = import_zod3.z.string().uuid().brand();
702
-
703
- // src/genre-tree/schemas/criteria/minimum.ts
704
- var import_zod4 = require("zod");
705
- var CriteriaMinimumSchema = import_zod4.z.object({
706
- uuid: GenreUuidSchema,
707
- name: import_zod4.z.string(),
708
- side: import_zod4.z.enum(["core", "pop"]).nullable().optional(),
709
- wikidataId: import_zod4.z.string().nullable().optional()
710
- });
711
-
712
- // src/genre-tree/schemas/criteria-playlist/minimum.ts
713
- var import_zod5 = require("zod");
714
- var CriteriaPlaylistMinimumSchema = import_zod5.z.object({
715
- uuid: GenrePlaylistUuidSchema,
716
- name: import_zod5.z.string()
717
- });
718
-
719
- // src/genre-tree/schemas/criteria-playlist/detailed.ts
720
- var CriteriaPlaylistDetailedSchema = import_zod6.z.object({
721
- uuid: GenrePlaylistUuidSchema,
722
- name: import_zod6.z.string(),
723
- tracksCount: import_zod6.z.number(),
724
- // Summed YouTube views of the same songs as `tracksCount`. Optional: hear-api has no view counts.
725
- viewsCount: import_zod6.z.number().optional(),
726
- durationInSec: import_zod6.z.number().min(0).nullable().optional(),
727
- durationStrInHourMinSec: import_zod6.z.string().nullable().optional(),
728
- // Nullable: the "Genreless" root playlist has no criteria attached and is never updated.
729
- criteria: CriteriaMinimumSchema.nullable(),
730
- parent: CriteriaPlaylistMinimumSchema.nullable(),
731
- root: CriteriaPlaylistMinimumSchema,
732
- createdOn: import_zod6.z.string(),
733
- updatedOn: import_zod6.z.string().nullable()
734
- });
735
-
736
- // src/genre-tree/schemas/criteria-playlist/simple.ts
737
- var CriteriaPlaylistSimpleSchema = CriteriaPlaylistDetailedSchema.pick({
738
- uuid: true,
739
- name: true,
740
- criteria: true,
741
- parent: true,
742
- root: true,
743
- tracksCount: true,
744
- viewsCount: true,
745
- createdOn: true,
746
- updatedOn: true
747
- }).extend({
748
- // Only on the tree/list payloads, not the detail endpoint — hence not on the detailed schema.
749
- isUnacceptedRoot: import_zod7.z.boolean(),
750
- // Optional: a backend that does not curate umbrella genres omits it.
751
- isUmbrella: import_zod7.z.boolean().optional(),
752
- // Optional: only the grow tree payload carries it; null when the genre has no scene.
753
- scene: import_zod7.z.enum(["commercial", "underground"]).nullable().optional()
754
- });
755
-
756
897
  // src/transport/lib/paginated-response.ts
757
- var import_zod8 = require("zod");
758
- var PaginatedResponseSchema = (itemSchema) => import_zod8.z.object({
759
- overallTotal: import_zod8.z.number(),
760
- next: import_zod8.z.string().url().nullable(),
761
- previous: import_zod8.z.string().url().nullable(),
762
- results: import_zod8.z.array(itemSchema),
763
- page: import_zod8.z.number(),
764
- pageSize: import_zod8.z.number(),
765
- totalPages: import_zod8.z.number()
898
+ var import_zod16 = require("zod");
899
+ var PaginatedResponseSchema = (itemSchema) => import_zod16.z.object({
900
+ overallTotal: import_zod16.z.number(),
901
+ next: import_zod16.z.string().url().nullable(),
902
+ previous: import_zod16.z.string().url().nullable(),
903
+ results: import_zod16.z.array(itemSchema),
904
+ page: import_zod16.z.number(),
905
+ pageSize: import_zod16.z.number(),
906
+ totalPages: import_zod16.z.number()
766
907
  });
767
908
 
768
909
  // src/genre-tree/api/genre-playlists/queryKeys.ts
@@ -800,6 +941,30 @@ var genrePlaylistEndpoints = {
800
941
  reference: { ...makeGenrePlaylistEndpoints(""), tree: () => "genre-playlists/tree/" }
801
942
  };
802
943
 
944
+ // src/genre-tree/lib/genre-music-selection.ts
945
+ function defaultGenreMusicSelection(counts) {
946
+ return { coverage: "genreAndSubgenres", subgenres: "canonical" in counts.genreAndSubgenresTracksCount ? "canonical" : "all" };
947
+ }
948
+ function genreMusicCount(counts, selection = defaultGenreMusicSelection(counts)) {
949
+ if (selection.coverage === "genreOnly") return counts.genreOnlyTracksCount;
950
+ const scopes = counts.genreAndSubgenresTracksCount;
951
+ if (selection.subgenres === "all") return scopes.all;
952
+ if (!("canonical" in scopes)) throw new Error("Regional genres only support all subgenres");
953
+ return scopes[selection.subgenres];
954
+ }
955
+ function genreMusicQueryParams(selection) {
956
+ if (!selection) return {};
957
+ return selection.coverage === "genreOnly" ? { coverage: "genre_only" } : { coverage: "genre_and_subgenres", subgenres: selection.subgenres };
958
+ }
959
+ function genreMusicSelectionKey(selection) {
960
+ return selection ? [selection.coverage, ...selection.coverage === "genreAndSubgenres" ? [selection.subgenres] : []] : [];
961
+ }
962
+ function genrePlaylistTrackCount(playlist) {
963
+ if (playlist.genreOnlyTracksCount === void 0 && playlist.genreAndSubgenresTracksCount === void 0) return playlist.tracksCount;
964
+ if (playlist.genreOnlyTracksCount === void 0 || playlist.genreAndSubgenresTracksCount === void 0) throw new Error("Incomplete genre playlist counts");
965
+ return genreMusicCount({ genreOnlyTracksCount: playlist.genreOnlyTracksCount, genreAndSubgenresTracksCount: playlist.genreAndSubgenresTracksCount });
966
+ }
967
+
803
968
  // src/genre-tree/api/library/songs/queryKeys.ts
804
969
  var makeSongQueryKeys = (prefix) => ({
805
970
  all: [`${prefix}Songs`],
@@ -808,7 +973,7 @@ var makeSongQueryKeys = (prefix) => ({
808
973
  history: (uuid) => [`${prefix}Songs`, "history", uuid],
809
974
  search: (params) => [`${prefix}Songs`, "search", params],
810
975
  // baseUrl keeps distinct backends sharing a scope (e.g. grow and its prototype proxy) apart.
811
- byGenre: (baseUrl, genreUuid) => [`${prefix}Songs`, baseUrl, "genre", genreUuid]
976
+ byGenre: (baseUrl, genreUuid, selection) => [`${prefix}Songs`, baseUrl, "genre", genreUuid, ...genreMusicSelectionKey(selection)]
812
977
  });
813
978
 
814
979
  // src/genre-tree/api/library/songs/endpoints.ts
@@ -878,7 +1043,7 @@ var useListFullGenrePlaylists = (scope, getBackendBaseUrl) => {
878
1043
  const queryClient2 = (0, import_react_query3.useQueryClient)();
879
1044
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
880
1045
  const { session, sessionRestored } = useSession();
881
- const queryKey = scope === "reference" ? genrePlaylistQueryKeys.reference.full(getBackendBaseUrl()) : genrePlaylistQueryKeys.me.full;
1046
+ const queryKey = scope === "reference" ? [...genrePlaylistQueryKeys.reference.full(getBackendBaseUrl()), "genreMusicV1"] : genrePlaylistQueryKeys.me.full;
882
1047
  const query = useQueryWithParse({
883
1048
  queryKey,
884
1049
  queryFn: () => scope === "reference" ? fetch2(genrePlaylistEndpoints.reference.tree(), true, false, {}, { treeName: "canonical" }) : fetchAllPages(
@@ -890,7 +1055,7 @@ var useListFullGenrePlaylists = (scope, getBackendBaseUrl) => {
890
1055
  { page, pageSize: FULL_LIST_PAGE_SIZE, treeName: "canonical" }
891
1056
  )
892
1057
  ),
893
- schema: import_zod9.z.array(CriteriaPlaylistSimpleSchema),
1058
+ schema: scope === "reference" ? import_zod17.z.array(ReferenceGenrePlaylistSchema) : import_zod17.z.array(CriteriaPlaylistSimpleSchema),
894
1059
  context: "useListFullGenrePlaylists",
895
1060
  enabled: scope === "reference" || sessionRestored && !!session?.accessToken
896
1061
  });
@@ -926,7 +1091,7 @@ var useInvalidateAllGenrePlaylistQueries = () => {
926
1091
  // src/transport/lib/use-validated-mutation.ts
927
1092
  var import_react_query4 = require("@tanstack/react-query");
928
1093
  var import_react5 = require("react");
929
- var import_zod10 = require("zod");
1094
+ var import_zod18 = require("zod");
930
1095
  function useValidatedMutation({
931
1096
  inputSchema,
932
1097
  outputSchema,
@@ -959,9 +1124,9 @@ function useValidatedMutation({
959
1124
  } catch (error) {
960
1125
  if (error instanceof Error && "json" in error) {
961
1126
  try {
962
- const errorResponse = import_zod10.z.object({
963
- details: import_zod10.z.object({
964
- fieldErrors: import_zod10.z.record(import_zod10.z.string(), import_zod10.z.array(import_zod10.z.object({ message: import_zod10.z.string() })))
1127
+ const errorResponse = import_zod18.z.object({
1128
+ details: import_zod18.z.object({
1129
+ fieldErrors: import_zod18.z.record(import_zod18.z.string(), import_zod18.z.array(import_zod18.z.object({ message: import_zod18.z.string() })))
965
1130
  })
966
1131
  }).parse(error.json);
967
1132
  setFormErrors(
@@ -984,131 +1149,48 @@ function useValidatedMutation({
984
1149
  return { ...validatedMutation, formErrors };
985
1150
  }
986
1151
 
987
- // src/genre-tree/schemas/criteria/detailed.ts
988
- var import_zod17 = require("zod");
989
-
990
- // src/genre-tree/schemas/track/base.ts
991
- var import_zod14 = require("zod");
992
-
993
- // src/genre-tree/schemas/artist-minimum.ts
994
- var import_zod11 = require("zod");
995
- var ArtistMinimumSchema = import_zod11.z.object({
996
- uuid: import_zod11.z.string().uuid(),
997
- name: import_zod11.z.string(),
998
- isSpecialPurpose: import_zod11.z.boolean().optional()
999
- });
1000
-
1001
- // src/genre-tree/schemas/album-minimum.ts
1002
- var import_zod12 = require("zod");
1003
- var AlbumMinimumSchema = import_zod12.z.object({
1004
- uuid: import_zod12.z.string().uuid(),
1005
- name: import_zod12.z.string(),
1006
- albumArtists: import_zod12.z.array(ArtistMinimumSchema).nullable().optional()
1007
- });
1008
-
1009
- // src/genre-tree/schemas/uuid-resource.ts
1010
- var import_zod13 = require("zod");
1011
- var UuidResourceSchema = import_zod13.z.object({
1012
- uuid: import_zod13.z.string().uuid()
1013
- });
1014
-
1015
- // src/genre-tree/schemas/track/base.ts
1016
- var TrackBaseSchema = UuidResourceSchema.extend({
1017
- title: import_zod14.z.string(),
1018
- artists: import_zod14.z.array(ArtistMinimumSchema).nullable().optional(),
1019
- album: AlbumMinimumSchema.nullable().optional(),
1020
- trackNumber: import_zod14.z.number().nullable().optional(),
1021
- // null for a song not yet linked to a genre.
1022
- genre: CriteriaMinimumSchema.nullable(),
1023
- rating: import_zod14.z.number().min(0).max(10).nullable().optional(),
1024
- language: import_zod14.z.string().nullable().optional(),
1025
- playCount: import_zod14.z.number().min(0),
1026
- createdOn: import_zod14.z.string().datetime(),
1027
- updatedOn: import_zod14.z.string().datetime().nullable().optional()
1028
- });
1029
-
1030
- // src/genre-tree/schemas/track/minimum.ts
1031
- var TrackMinimumSchema = TrackBaseSchema.pick({
1032
- uuid: true,
1033
- title: true,
1034
- artists: true
1035
- });
1036
-
1037
- // src/genre-tree/schemas/criteria/lineage-rel/without-ascendant.ts
1038
- var import_zod15 = require("zod");
1039
- var CriteriaLineageRelWithoutAscendantSchema = import_zod15.z.object({
1040
- descendant: CriteriaMinimumSchema,
1041
- degree: import_zod15.z.number()
1042
- });
1043
-
1044
- // src/genre-tree/schemas/criteria/lineage-rel/without-descendant.ts
1045
- var import_zod16 = require("zod");
1046
- var CriteriaLineageRelWithoutDescendantSchema = import_zod16.z.object({
1047
- ascendant: CriteriaMinimumSchema,
1048
- degree: import_zod16.z.number()
1049
- });
1050
-
1051
- // src/genre-tree/schemas/criteria/detailed.ts
1052
- var CriteriaDetailedSchema = import_zod17.z.object({
1053
- uuid: GenreUuidSchema,
1054
- name: import_zod17.z.string(),
1055
- summary: import_zod17.z.string().nullable(),
1056
- // Optional until every deployed API serves it.
1057
- wikidataId: import_zod17.z.string().nullable().optional(),
1058
- parent: CriteriaMinimumSchema.nullable(),
1059
- ascendants: import_zod17.z.array(CriteriaLineageRelWithoutDescendantSchema),
1060
- descendants: import_zod17.z.array(CriteriaLineageRelWithoutAscendantSchema),
1061
- root: CriteriaMinimumSchema,
1062
- children: import_zod17.z.array(CriteriaMinimumSchema),
1063
- criteriaPlaylist: CriteriaPlaylistMinimumSchema,
1064
- tracks: import_zod17.z.array(TrackMinimumSchema),
1065
- essentialSongs: import_zod17.z.array(TrackMinimumSchema),
1066
- tracksCount: import_zod17.z.number(),
1067
- updatedOn: import_zod17.z.string().datetime().nullable()
1068
- });
1069
-
1070
1152
  // src/genre-tree/schemas/criteria/overview.ts
1071
- var import_zod19 = require("zod");
1153
+ var import_zod20 = require("zod");
1072
1154
 
1073
1155
  // src/genre-tree/schemas/http-url.ts
1074
- var import_zod18 = require("zod");
1075
- var HttpUrlSchema = import_zod18.z.url({ protocol: /^https?$/ });
1156
+ var import_zod19 = require("zod");
1157
+ var HttpUrlSchema = import_zod19.z.url({ protocol: /^https?$/ });
1076
1158
 
1077
1159
  // src/genre-tree/schemas/criteria/overview.ts
1078
- var CriteriaOverviewSchema = import_zod19.z.object({
1160
+ var CriteriaOverviewSchema = import_zod20.z.object({
1079
1161
  uuid: GenreUuidSchema,
1080
- name: import_zod19.z.string(),
1081
- summary: import_zod19.z.string().nullable(),
1082
- description: import_zod19.z.string().nullable(),
1162
+ name: import_zod20.z.string(),
1163
+ summary: import_zod20.z.string().nullable(),
1164
+ description: import_zod20.z.string().nullable(),
1083
1165
  summarySourceUrl: HttpUrlSchema.nullable(),
1084
- essentialSongs: import_zod19.z.array(TrackMinimumSchema).optional()
1166
+ essentialSongs: import_zod20.z.array(TrackMinimumSchema).optional()
1085
1167
  });
1086
1168
 
1087
1169
  // src/genre-tree/schemas/criteria/simple.ts
1088
- var import_zod20 = require("zod");
1089
- var CriteriaSimpleSchema = import_zod20.z.object({
1170
+ var import_zod21 = require("zod");
1171
+ var CriteriaSimpleSchema = import_zod21.z.object({
1090
1172
  uuid: GenreUuidSchema,
1091
- name: import_zod20.z.string(),
1173
+ name: import_zod21.z.string(),
1092
1174
  parent: CriteriaMinimumSchema.nullable(),
1093
- createdOn: import_zod20.z.string().datetime(),
1094
- summary: import_zod20.z.string().nullable()
1175
+ createdOn: import_zod21.z.string().datetime(),
1176
+ summary: import_zod21.z.string().nullable()
1095
1177
  });
1096
1178
 
1097
1179
  // src/genre-tree/schemas/criteria/creation.ts
1098
- var import_zod21 = require("zod");
1099
- var CriteriaCreationSchema = import_zod21.z.object({
1100
- name: import_zod21.z.string().min(1, "Name is required"),
1180
+ var import_zod22 = require("zod");
1181
+ var CriteriaCreationSchema = import_zod22.z.object({
1182
+ name: import_zod22.z.string().min(1, "Name is required"),
1101
1183
  parent: GenreUuidSchema.optional(),
1102
- essentialSongs: import_zod21.z.array(import_zod21.z.string().uuid()).optional()
1184
+ essentialSongs: import_zod22.z.array(import_zod22.z.string().uuid()).optional()
1103
1185
  });
1104
1186
 
1105
1187
  // src/genre-tree/schemas/criteria/update.ts
1106
- var import_zod22 = require("zod");
1107
- var CriteriaUpdateSchema = import_zod22.z.object({
1108
- name: import_zod22.z.string().optional(),
1188
+ var import_zod23 = require("zod");
1189
+ var CriteriaUpdateSchema = import_zod23.z.object({
1190
+ name: import_zod23.z.string().optional(),
1109
1191
  parent: GenreUuidSchema.nullable().optional(),
1110
- essentialSongs: import_zod22.z.array(import_zod22.z.string().uuid()).optional(),
1111
- side: import_zod22.z.enum(["core", "pop"]).optional()
1192
+ essentialSongs: import_zod23.z.array(import_zod23.z.string().uuid()).optional(),
1193
+ side: import_zod23.z.enum(["core", "pop"]).optional()
1112
1194
  });
1113
1195
 
1114
1196
  // src/genre-tree/api/genres/queryKeys.ts
@@ -1169,18 +1251,18 @@ function useFetchGenre(scope, getBackendBaseUrl) {
1169
1251
  async (id) => {
1170
1252
  const endpoint = scope === "reference" ? genreEndpoints.reference.detail(id) : genreEndpoints.me.detail(id);
1171
1253
  const response = await fetch2(endpoint, true, scope === "me");
1172
- return parseWithLog(CriteriaDetailedSchema, response, "useFetchGenre");
1254
+ return parseWithLog(scope === "reference" ? ReferenceGenreDetailedSchema : CriteriaDetailedSchema, response, "useFetchGenre");
1173
1255
  },
1174
1256
  [fetch2, scope]
1175
1257
  );
1176
1258
  }
1177
- function useFetchGenreDetail(id, scope, getBackendBaseUrl, schema = CriteriaDetailedSchema) {
1259
+ function useFetchGenreDetail(id, scope, getBackendBaseUrl, schema = scope === "reference" ? ReferenceGenreDetailedSchema : CriteriaDetailedSchema) {
1178
1260
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1179
1261
  const queryKeys = scope === "reference" ? genreQueryKeys.reference : genreQueryKeys.me;
1180
1262
  const endpoints = scope === "reference" ? genreEndpoints.reference : genreEndpoints.me;
1181
1263
  const genreUuid = id ?? "";
1182
1264
  return useQueryWithParse({
1183
- queryKey: queryKeys.detail(genreUuid),
1265
+ queryKey: scope === "reference" ? [...queryKeys.detail(genreUuid), getBackendBaseUrl(), "genreMusicV1"] : queryKeys.detail(genreUuid),
1184
1266
  queryFn: () => fetch2(endpoints.detail(genreUuid), true, scope === "me"),
1185
1267
  schema,
1186
1268
  context: "useFetchGenreDetail",
@@ -1263,7 +1345,7 @@ function useUpdateGenre(scope, getBackendBaseUrl) {
1263
1345
  const refreshGenreTree = useRefreshGenreTree(scope);
1264
1346
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1265
1347
  const { mutate, mutateAsync, isPending, formErrors } = useValidatedMutation({
1266
- inputSchema: import_zod23.z.object({
1348
+ inputSchema: import_zod24.z.object({
1267
1349
  uuid: GenreUuidSchema,
1268
1350
  data: CriteriaUpdateSchema
1269
1351
  }),
@@ -1293,8 +1375,8 @@ function useDeleteGenre(scope, getBackendBaseUrl) {
1293
1375
  const refreshGenreTree = useRefreshGenreTree(scope);
1294
1376
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1295
1377
  return useValidatedMutation({
1296
- inputSchema: import_zod23.z.object({ uuid: GenreUuidSchema }),
1297
- outputSchema: import_zod23.z.null(),
1378
+ inputSchema: import_zod24.z.object({ uuid: GenreUuidSchema }),
1379
+ outputSchema: import_zod24.z.null(),
1298
1380
  mutationFn: async ({ uuid }) => {
1299
1381
  const endpoint = scope === "reference" ? genreEndpoints.reference.delete(uuid) : genreEndpoints.me.delete(uuid);
1300
1382
  return fetch2(endpoint, true, scope === "me", { method: "DELETE" }, void 0, false, true);
@@ -1304,16 +1386,16 @@ function useDeleteGenre(scope, getBackendBaseUrl) {
1304
1386
  }
1305
1387
 
1306
1388
  // src/genre-tree/useArtist.ts
1307
- var import_zod25 = require("zod");
1389
+ var import_zod26 = require("zod");
1308
1390
 
1309
1391
  // src/genre-tree/schemas/artist-detailed.ts
1310
- var import_zod24 = require("zod");
1311
- var ArtistMembershipSchema = import_zod24.z.object({
1392
+ var import_zod25 = require("zod");
1393
+ var ArtistMembershipSchema = import_zod25.z.object({
1312
1394
  artist: ArtistMinimumSchema,
1313
- beginYear: import_zod24.z.number().int().nullable(),
1314
- endYear: import_zod24.z.number().int().nullable(),
1315
- ended: import_zod24.z.boolean(),
1316
- roles: import_zod24.z.array(import_zod24.z.string())
1395
+ beginYear: import_zod25.z.number().int().nullable(),
1396
+ endYear: import_zod25.z.number().int().nullable(),
1397
+ ended: import_zod25.z.boolean(),
1398
+ roles: import_zod25.z.array(import_zod25.z.string())
1317
1399
  });
1318
1400
  var ARTIST_LINK_KINDS = [
1319
1401
  "official",
@@ -1326,35 +1408,35 @@ var ARTIST_LINK_KINDS = [
1326
1408
  "discogs",
1327
1409
  "social"
1328
1410
  ];
1329
- var ArtistImageSchema = import_zod24.z.object({
1411
+ var ArtistImageSchema = import_zod25.z.object({
1330
1412
  url: HttpUrlSchema,
1331
1413
  pageUrl: HttpUrlSchema,
1332
- author: import_zod24.z.string().nullable(),
1333
- license: import_zod24.z.string(),
1414
+ author: import_zod25.z.string().nullable(),
1415
+ license: import_zod25.z.string(),
1334
1416
  licenseUrl: HttpUrlSchema.nullable()
1335
1417
  });
1336
- var ArtistDetailedSchema = import_zod24.z.object({
1337
- uuid: import_zod24.z.string().uuid(),
1338
- name: import_zod24.z.string(),
1339
- musicbrainzArtistId: import_zod24.z.string().uuid().nullable(),
1340
- type: import_zod24.z.enum(["person", "group", "orchestra", "choir", "character", "other"]).nullable(),
1341
- country: import_zod24.z.string().nullable(),
1342
- beginYear: import_zod24.z.number().int().nullable(),
1343
- endYear: import_zod24.z.number().int().nullable(),
1344
- ended: import_zod24.z.boolean(),
1345
- links: import_zod24.z.array(import_zod24.z.object({ kind: import_zod24.z.enum(ARTIST_LINK_KINDS), url: HttpUrlSchema })),
1346
- members: import_zod24.z.array(ArtistMembershipSchema),
1347
- memberOf: import_zod24.z.array(ArtistMembershipSchema),
1348
- albums: import_zod24.z.array(
1349
- import_zod24.z.object({
1350
- uuid: import_zod24.z.string().uuid(),
1351
- name: import_zod24.z.string(),
1352
- year: import_zod24.z.string().nullable(),
1353
- primaryType: import_zod24.z.string().nullable(),
1354
- secondaryTypes: import_zod24.z.array(import_zod24.z.string())
1418
+ var ArtistDetailedSchema = import_zod25.z.object({
1419
+ uuid: import_zod25.z.string().uuid(),
1420
+ name: import_zod25.z.string(),
1421
+ musicbrainzArtistId: import_zod25.z.string().uuid().nullable(),
1422
+ type: import_zod25.z.enum(["person", "group", "orchestra", "choir", "character", "other"]).nullable(),
1423
+ country: import_zod25.z.string().nullable(),
1424
+ beginYear: import_zod25.z.number().int().nullable(),
1425
+ endYear: import_zod25.z.number().int().nullable(),
1426
+ ended: import_zod25.z.boolean(),
1427
+ links: import_zod25.z.array(import_zod25.z.object({ kind: import_zod25.z.enum(ARTIST_LINK_KINDS), url: HttpUrlSchema })),
1428
+ members: import_zod25.z.array(ArtistMembershipSchema),
1429
+ memberOf: import_zod25.z.array(ArtistMembershipSchema),
1430
+ albums: import_zod25.z.array(
1431
+ import_zod25.z.object({
1432
+ uuid: import_zod25.z.string().uuid(),
1433
+ name: import_zod25.z.string(),
1434
+ year: import_zod25.z.string().nullable(),
1435
+ primaryType: import_zod25.z.string().nullable(),
1436
+ secondaryTypes: import_zod25.z.array(import_zod25.z.string())
1355
1437
  })
1356
1438
  ),
1357
- tracksCount: import_zod24.z.number().int(),
1439
+ tracksCount: import_zod25.z.number().int(),
1358
1440
  image: ArtistImageSchema.nullable()
1359
1441
  });
1360
1442
 
@@ -1377,7 +1459,7 @@ var artistEndpoints = {
1377
1459
  var isNotFound = (error) => error instanceof AppError && error.code === "BAC4040" /* BACKEND_NOT_FOUND */;
1378
1460
  function useArtist(uuid, getBackendBaseUrl) {
1379
1461
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1380
- const isUuid = uuid !== null && import_zod25.z.string().uuid().safeParse(uuid).success;
1462
+ const isUuid = uuid !== null && import_zod26.z.string().uuid().safeParse(uuid).success;
1381
1463
  const { data, isPending, error } = useQueryWithParse({
1382
1464
  queryKey: artistQueryKeys.detail(uuid),
1383
1465
  // A missing artist is shown in the panel, not raised as an app-wide connectivity error.
@@ -1395,26 +1477,26 @@ function useArtist(uuid, getBackendBaseUrl) {
1395
1477
  }
1396
1478
 
1397
1479
  // src/genre-tree/schemas/artist-search.ts
1398
- var import_zod26 = require("zod");
1399
- var ArtistSearchResultSchema = import_zod26.z.object({
1400
- uuid: import_zod26.z.string().uuid(),
1401
- name: import_zod26.z.string(),
1402
- disambiguation: import_zod26.z.string().nullable(),
1403
- type: import_zod26.z.enum(["person", "group", "orchestra", "choir", "character", "other"]).nullable(),
1404
- country: import_zod26.z.string().nullable(),
1405
- beginYear: import_zod26.z.number().int().nullable(),
1406
- endYear: import_zod26.z.number().int().nullable(),
1407
- matchedAlias: import_zod26.z.string().nullable(),
1408
- recordingCount: import_zod26.z.number().int()
1480
+ var import_zod27 = require("zod");
1481
+ var ArtistSearchResultSchema = import_zod27.z.object({
1482
+ uuid: import_zod27.z.string().uuid(),
1483
+ name: import_zod27.z.string(),
1484
+ disambiguation: import_zod27.z.string().nullable(),
1485
+ type: import_zod27.z.enum(["person", "group", "orchestra", "choir", "character", "other"]).nullable(),
1486
+ country: import_zod27.z.string().nullable(),
1487
+ beginYear: import_zod27.z.number().int().nullable(),
1488
+ endYear: import_zod27.z.number().int().nullable(),
1489
+ matchedAlias: import_zod27.z.string().nullable(),
1490
+ recordingCount: import_zod27.z.number().int()
1409
1491
  });
1410
- var ArtistSearchResultsSchema = import_zod26.z.array(ArtistSearchResultSchema);
1492
+ var ArtistSearchResultsSchema = import_zod27.z.array(ArtistSearchResultSchema);
1411
1493
 
1412
1494
  // src/genre-tree/useRemoteSearch.ts
1413
1495
  var import_react_query6 = require("@tanstack/react-query");
1414
1496
  var import_react7 = require("react");
1415
1497
  var SEARCH_DEBOUNCE_MS = 250;
1416
1498
  var SEARCH_QUERY_MIN_LENGTH = 2;
1417
- function useRemoteSearch(getBackendBaseUrl, { queryKey, endpoint, params, schema, context, text, enabled: extraEnabled = true, keepPrevious = true }) {
1499
+ function useRemoteSearch(getBackendBaseUrl, { queryKey, endpoint, params, schema, context, text, enabled: extraEnabled = true, scope = "" }) {
1418
1500
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1419
1501
  const trimmed = text.trim();
1420
1502
  const [query, setQuery] = (0, import_react7.useState)("");
@@ -1422,15 +1504,19 @@ function useRemoteSearch(getBackendBaseUrl, { queryKey, endpoint, params, schema
1422
1504
  const timer = setTimeout(() => setQuery(trimmed), SEARCH_DEBOUNCE_MS);
1423
1505
  return () => clearTimeout(timer);
1424
1506
  }, [trimmed]);
1507
+ const dataScope = (0, import_react7.useRef)(null);
1425
1508
  const enabled = query.length >= SEARCH_QUERY_MIN_LENGTH && extraEnabled;
1426
- const { data, isFetching, isError } = useQueryWithParse({
1509
+ const { data, isFetching, isError, isPlaceholderData } = useQueryWithParse({
1427
1510
  queryKey: queryKey(query),
1428
1511
  queryFn: ({ signal }) => fetch2(endpoint, true, false, { signal }, params(query)),
1429
1512
  schema,
1430
1513
  context,
1431
1514
  enabled,
1432
- placeholderData: keepPrevious ? import_react_query6.keepPreviousData : void 0
1515
+ placeholderData: (previous) => dataScope.current === scope ? (0, import_react_query6.keepPreviousData)(previous) : void 0
1433
1516
  });
1517
+ (0, import_react7.useEffect)(() => {
1518
+ if (data !== void 0 && !isPlaceholderData) dataScope.current = scope;
1519
+ }, [data, isPlaceholderData, scope]);
1434
1520
  const settled = enabled && !isFetching && query === trimmed;
1435
1521
  const failed = enabled && isError;
1436
1522
  const long = trimmed.length >= SEARCH_QUERY_MIN_LENGTH;
@@ -1457,10 +1543,10 @@ function useArtistSearch(getBackendBaseUrl, text) {
1457
1543
  }
1458
1544
 
1459
1545
  // src/genre-tree/useSong.ts
1460
- var import_zod28 = require("zod");
1546
+ var import_zod29 = require("zod");
1461
1547
 
1462
1548
  // src/genre-tree/schemas/song/detailed.ts
1463
- var import_zod27 = require("zod");
1549
+ var import_zod28 = require("zod");
1464
1550
  var YOUTUBE_UNPLAYABLE_REASON_LABELS = {
1465
1551
  not_found: "Video unavailable",
1466
1552
  not_embeddable: "Embedding disabled",
@@ -1469,23 +1555,23 @@ var YOUTUBE_UNPLAYABLE_REASON_LABELS = {
1469
1555
  region_whitelisted: "Region restricted"
1470
1556
  };
1471
1557
  var YOUTUBE_UNPLAYABLE_REASONS = Object.keys(YOUTUBE_UNPLAYABLE_REASON_LABELS);
1472
- var YoutubeAvailabilitySchema = import_zod27.z.object({
1473
- status: import_zod27.z.enum(["eligible", "blocked", "unknown"]),
1474
- reason: import_zod27.z.string().nullable(),
1475
- country: import_zod27.z.string().nullable()
1558
+ var YoutubeAvailabilitySchema = import_zod28.z.object({
1559
+ status: import_zod28.z.enum(["eligible", "blocked", "unknown"]),
1560
+ reason: import_zod28.z.string().nullable(),
1561
+ country: import_zod28.z.string().nullable()
1476
1562
  });
1477
1563
  var SongDetailedSchema = TrackBaseSchema.extend({
1478
- youtubeVideo: import_zod27.z.object({
1479
- id: import_zod27.z.string(),
1564
+ youtubeVideo: import_zod28.z.object({
1565
+ id: import_zod28.z.string(),
1480
1566
  availability: YoutubeAvailabilitySchema.optional(),
1481
1567
  // null = playable
1482
- unplayableReason: import_zod27.z.enum(YOUTUBE_UNPLAYABLE_REASONS).nullable(),
1483
- viewCount: import_zod27.z.number().int().nullable().optional()
1568
+ unplayableReason: import_zod28.z.enum(YOUTUBE_UNPLAYABLE_REASONS).nullable(),
1569
+ viewCount: import_zod28.z.number().int().nullable().optional()
1484
1570
  }).nullable(),
1485
1571
  // null for hand-made/admin songs
1486
- musicbrainzRecordingId: import_zod27.z.string().uuid().nullable(),
1487
- firstReleaseYear: import_zod27.z.number().int().nullable().optional(),
1488
- essentialGenres: import_zod27.z.array(CriteriaMinimumSchema).optional()
1572
+ musicbrainzRecordingId: import_zod28.z.string().uuid().nullable(),
1573
+ firstReleaseYear: import_zod28.z.number().int().nullable().optional(),
1574
+ essentialGenres: import_zod28.z.array(CriteriaMinimumSchema).optional()
1489
1575
  });
1490
1576
  var NO_VIDEO_LABEL = "No video available";
1491
1577
  function isSong(track) {
@@ -1506,7 +1592,7 @@ var isNotFound2 = (error) => error instanceof AppError && error.code === "BAC404
1506
1592
  function useSong(uuid, getBackendBaseUrl) {
1507
1593
  const playback = usePlaybackContext();
1508
1594
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1509
- const isUuid = uuid !== null && import_zod28.z.string().uuid().safeParse(uuid).success;
1595
+ const isUuid = uuid !== null && import_zod29.z.string().uuid().safeParse(uuid).success;
1510
1596
  const { data, isPending, error } = useQueryWithParse({
1511
1597
  queryKey: [...libraryQueryKeys.reference.songs.detail(uuid), ...playback.key ? [playback.key] : []],
1512
1598
  // A missing song is shown in the panel, not raised as an app-wide connectivity error.
@@ -1524,16 +1610,16 @@ function useSong(uuid, getBackendBaseUrl) {
1524
1610
  }
1525
1611
 
1526
1612
  // src/genre-tree/schemas/song-history.ts
1527
- var import_zod29 = require("zod");
1528
- var SongHistoryEntrySchema = import_zod29.z.object({
1529
- uuid: import_zod29.z.string().uuid(),
1530
- action: import_zod29.z.string(),
1531
- actorPseudo: import_zod29.z.string().nullable(),
1532
- oldValue: import_zod29.z.string().nullable(),
1533
- newValue: import_zod29.z.string().nullable(),
1534
- createdOn: import_zod29.z.string()
1613
+ var import_zod30 = require("zod");
1614
+ var SongHistoryEntrySchema = import_zod30.z.object({
1615
+ uuid: import_zod30.z.string().uuid(),
1616
+ action: import_zod30.z.string(),
1617
+ actorPseudo: import_zod30.z.string().nullable(),
1618
+ oldValue: import_zod30.z.string().nullable(),
1619
+ newValue: import_zod30.z.string().nullable(),
1620
+ createdOn: import_zod30.z.string()
1535
1621
  });
1536
- var SongHistorySchema = import_zod29.z.array(SongHistoryEntrySchema);
1622
+ var SongHistorySchema = import_zod30.z.array(SongHistoryEntrySchema);
1537
1623
 
1538
1624
  // src/genre-tree/useSongHistory.ts
1539
1625
  function useSongHistory(uuid, getBackendBaseUrl, enabled) {
@@ -1553,20 +1639,20 @@ function useSongHistory(uuid, getBackendBaseUrl, enabled) {
1553
1639
  }
1554
1640
 
1555
1641
  // src/genre-tree/schemas/song-search.ts
1556
- var import_zod30 = require("zod");
1557
- var SongSearchResultSchema = import_zod30.z.object({
1558
- uuid: import_zod30.z.string().uuid(),
1559
- title: import_zod30.z.string(),
1560
- artists: import_zod30.z.array(ArtistMinimumSchema),
1642
+ var import_zod31 = require("zod");
1643
+ var SongSearchResultSchema = import_zod31.z.object({
1644
+ uuid: import_zod31.z.string().uuid(),
1645
+ title: import_zod31.z.string(),
1646
+ artists: import_zod31.z.array(ArtistMinimumSchema),
1561
1647
  // null for songs not yet linked to a genre.
1562
1648
  genre: CriteriaMinimumSchema.nullable(),
1563
- youtubeVideo: import_zod30.z.object({
1564
- id: import_zod30.z.string(),
1565
- unplayableReason: import_zod30.z.string().nullable()
1649
+ youtubeVideo: import_zod31.z.object({
1650
+ id: import_zod31.z.string(),
1651
+ unplayableReason: import_zod31.z.string().nullable()
1566
1652
  }).nullable(),
1567
- firstReleaseYear: import_zod30.z.number().int().nullable()
1653
+ firstReleaseYear: import_zod31.z.number().int().nullable()
1568
1654
  });
1569
- var SongSearchResultsSchema = import_zod30.z.array(SongSearchResultSchema);
1655
+ var SongSearchResultsSchema = import_zod31.z.array(SongSearchResultSchema);
1570
1656
  function isSongSearchResultPlayable(result) {
1571
1657
  return result.youtubeVideo !== null && result.youtubeVideo.unplayableReason === null;
1572
1658
  }
@@ -1585,23 +1671,32 @@ function useSongSearch(getBackendBaseUrl, text, options = {}) {
1585
1671
  context: "useSongSearch",
1586
1672
  text,
1587
1673
  enabled: playback.ready,
1588
- keepPrevious: playback.key === null
1674
+ scope: playback.key ?? ""
1589
1675
  });
1590
1676
  return { songs: results, isError, settled, pending };
1591
1677
  }
1592
1678
 
1593
1679
  // src/genre-tree/useArtistGenreCounts.ts
1594
1680
  var import_react_query7 = require("@tanstack/react-query");
1595
- var import_zod32 = require("zod");
1681
+ var import_zod33 = require("zod");
1596
1682
 
1597
1683
  // src/genre-tree/schemas/artist-genre-count.ts
1598
- var import_zod31 = require("zod");
1599
- var ArtistGenreCountSchema = import_zod31.z.object({
1684
+ var import_zod32 = require("zod");
1685
+ var ArtistGenreCountSchema = import_zod32.z.object({
1686
+ ...GenreCountsSchema.shape,
1687
+ catalogue: GenreCatalogueCountsSchema,
1600
1688
  genrePlaylist: GenrePlaylistUuidSchema,
1601
- /** All the artist's songs in the genre playlist's subtree; drives pruning. */
1602
- songsCount: import_zod31.z.number().int().nonnegative(),
1603
- /** The playable ones among them; drives node size and the play button. */
1604
- tracksCount: import_zod31.z.number().int().nonnegative()
1689
+ /** Legacy catalogue count for the default selection. */
1690
+ songsCount: import_zod32.z.number().int().nonnegative(),
1691
+ /** Legacy playlist count for the default selection. */
1692
+ tracksCount: import_zod32.z.number().int().nonnegative()
1693
+ }).superRefine((row, ctx) => {
1694
+ const counts = GenreCatalogueCountsSchema.safeParse(row);
1695
+ if (!counts.success) {
1696
+ for (const issue of counts.error.issues) {
1697
+ ctx.addIssue({ code: "custom", path: issue.path, message: issue.message });
1698
+ }
1699
+ }
1605
1700
  });
1606
1701
 
1607
1702
  // src/genre-tree/useArtistGenreCounts.ts
@@ -1609,10 +1704,10 @@ var isNotFound3 = (error) => error instanceof AppError && error.code === "BAC404
1609
1704
  function useArtistGenreCounts(artistUuid, getBackendBaseUrl) {
1610
1705
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1611
1706
  return useQueryWithParse({
1612
- queryKey: artistQueryKeys.genreCounts(getBackendBaseUrl(), artistUuid),
1707
+ queryKey: [...artistQueryKeys.genreCounts(getBackendBaseUrl(), artistUuid), "genreMusicV1"],
1613
1708
  // A missing artist is shown in the artist panel, not raised as an app-wide connectivity error.
1614
1709
  queryFn: () => fetch2(artistEndpoints.genreCounts(artistUuid), true, false, void 0, void 0, false, true),
1615
- schema: import_zod32.z.array(ArtistGenreCountSchema),
1710
+ schema: import_zod33.z.array(ArtistGenreCountSchema),
1616
1711
  enabled: artistUuid !== null,
1617
1712
  placeholderData: import_react_query7.keepPreviousData,
1618
1713
  retry: (failureCount, error) => !isNotFound3(error) && failureCount < 3,
@@ -1716,30 +1811,32 @@ function useGenreSearch({
1716
1811
  }
1717
1812
 
1718
1813
  // src/genre-tree/schemas/genre-search.ts
1719
- var import_zod33 = require("zod");
1720
- var GenreSearchTreeNameSchema = import_zod33.z.enum(["canonical", "regional"]);
1721
- var GenreSearchResultSchema = import_zod33.z.object({
1814
+ var import_zod34 = require("zod");
1815
+ var GenreSearchTreeNameSchema = import_zod34.z.enum(["canonical", "regional"]);
1816
+ var GenreSearchResultSchema = import_zod34.z.object({
1722
1817
  /** Criteria (genre) uuid. */
1723
1818
  uuid: GenreUuidSchema,
1724
- name: import_zod33.z.string(),
1725
- treeName: import_zod33.z.string(),
1819
+ name: import_zod34.z.string(),
1820
+ /** Null for app-created genres, which the Wikidata-keyed region index does not reference. */
1821
+ wikidataId: import_zod34.z.string().nullable(),
1822
+ treeName: import_zod34.z.string(),
1726
1823
  /** Null when the genre has no playlist in the tree, so it cannot be opened there. */
1727
1824
  genrePlaylistUuid: GenrePlaylistUuidSchema.nullable(),
1728
- root: import_zod33.z.object({ uuid: GenreUuidSchema, name: import_zod33.z.string() }),
1729
- isUmbrella: import_zod33.z.boolean(),
1730
- viewsCount: import_zod33.z.number().int()
1825
+ root: import_zod34.z.object({ uuid: GenreUuidSchema, name: import_zod34.z.string() }),
1826
+ isUmbrella: import_zod34.z.boolean(),
1827
+ viewsCount: import_zod34.z.number().int()
1731
1828
  });
1732
- var GenreSearchResultsSchema = import_zod33.z.array(GenreSearchResultSchema);
1733
- var RegionGenreLexiconEntrySchema = import_zod33.z.object({
1734
- wikidataId: import_zod33.z.string(),
1829
+ var GenreSearchResultsSchema = import_zod34.z.array(GenreSearchResultSchema);
1830
+ var RegionGenreLexiconEntrySchema = import_zod34.z.object({
1831
+ wikidataId: import_zod34.z.string(),
1735
1832
  uuid: GenreUuidSchema,
1736
- name: import_zod33.z.string(),
1737
- treeName: import_zod33.z.string(),
1833
+ name: import_zod34.z.string(),
1834
+ treeName: import_zod34.z.string(),
1738
1835
  genrePlaylistUuid: GenrePlaylistUuidSchema.nullable(),
1739
- isUmbrella: import_zod33.z.boolean(),
1740
- viewsCount: import_zod33.z.number().int()
1836
+ isUmbrella: import_zod34.z.boolean(),
1837
+ viewsCount: import_zod34.z.number().int()
1741
1838
  });
1742
- var RegionGenreLexiconSchema = import_zod33.z.array(RegionGenreLexiconEntrySchema);
1839
+ var RegionGenreLexiconSchema = import_zod34.z.array(RegionGenreLexiconEntrySchema);
1743
1840
 
1744
1841
  // src/genre-tree/useGenreRemoteSearch.ts
1745
1842
  var DEFAULT_RESULT_LIMIT2 = 8;
@@ -1786,7 +1883,7 @@ var pruneGenrePlaylistsForArtist = (playlists, counts) => {
1786
1883
  const kept = /* @__PURE__ */ new Set();
1787
1884
  for (const playlist of playlists) {
1788
1885
  const isPopRoot = playlist.parent === null && playlist.name === POP_ROOT_NAME;
1789
- if (isPopRoot || (countByPlaylist.get(playlist.uuid)?.songsCount ?? 0) > 0) kept.add(playlist.uuid);
1886
+ if (isPopRoot || (countByPlaylist.get(playlist.uuid)?.catalogue.genreAndSubgenresTracksCount.all ?? 0) > 0) kept.add(playlist.uuid);
1790
1887
  }
1791
1888
  const coreElectronicUuids = new Set(
1792
1889
  playlists.filter((playlist) => playlist.name === CORE_ELECTRONIC_NAME && kept.has(playlist.uuid)).map((p) => p.uuid)
@@ -1794,12 +1891,22 @@ var pruneGenrePlaylistsForArtist = (playlists, counts) => {
1794
1891
  for (const playlist of playlists) {
1795
1892
  if (playlist.parent && coreElectronicUuids.has(playlist.parent.uuid)) kept.add(playlist.uuid);
1796
1893
  }
1797
- return playlists.filter((playlist) => kept.has(playlist.uuid)).map((playlist) => ({
1798
- ...playlist,
1799
- tracksCount: countByPlaylist.get(playlist.uuid)?.tracksCount ?? 0,
1800
- // Per-artist view totals are not served, so the views metric is unavailable on a pruned tree.
1801
- viewsCount: 0
1802
- }));
1894
+ return playlists.filter((playlist) => kept.has(playlist.uuid)).map((playlist) => {
1895
+ const count = countByPlaylist.get(playlist.uuid);
1896
+ const catalogue = GenreCatalogueCountsSchema.parse(playlist.catalogue);
1897
+ const scopes = playlist.genreAndSubgenresTracksCount;
1898
+ if (!scopes) throw new Error("Artist projections require a reference genre summary");
1899
+ const zero = { genreOnlyTracksCount: 0, genreAndSubgenresTracksCount: "canonical" in scopes ? { canonical: 0, regional: 0, all: 0 } : { all: 0 } };
1900
+ return {
1901
+ ...playlist,
1902
+ genreOnlyTracksCount: count?.genreOnlyTracksCount ?? 0,
1903
+ genreAndSubgenresTracksCount: count?.genreAndSubgenresTracksCount ?? zero.genreAndSubgenresTracksCount,
1904
+ catalogue: count?.catalogue ?? { ...catalogue, ...zero },
1905
+ tracksCount: count ? genreMusicCount(count) : 0,
1906
+ // Artist view totals are not served.
1907
+ viewsCount: void 0
1908
+ };
1909
+ });
1803
1910
  };
1804
1911
 
1805
1912
  // src/genre-tree/useVisibleGenrePlaylists.ts
@@ -1937,10 +2044,10 @@ function useGenreTreeViewState({
1937
2044
  var import_react13 = require("react");
1938
2045
 
1939
2046
  // src/genre-tree/schemas/track-playlist-rel/without-playlist.ts
1940
- var import_zod34 = require("zod");
1941
- var makeTrackPlaylistRelSchema = (trackSchema) => import_zod34.z.object({
2047
+ var import_zod35 = require("zod");
2048
+ var makeTrackPlaylistRelSchema = (trackSchema) => import_zod35.z.object({
1942
2049
  track: trackSchema,
1943
- position: import_zod34.z.number().min(0)
2050
+ position: import_zod35.z.number().min(0)
1944
2051
  });
1945
2052
  var makeTrackPlaylistRelPageSchema = (trackSchema) => PaginatedResponseSchema(makeTrackPlaylistRelSchema(trackSchema));
1946
2053
 
@@ -1989,6 +2096,7 @@ var TrackListFromArtist = class extends TrackList {
1989
2096
  var TrackListOriginType = /* @__PURE__ */ ((TrackListOriginType2) => {
1990
2097
  TrackListOriginType2["TRACK"] = "TRACK";
1991
2098
  TrackListOriginType2["GENRE_PLAYLIST"] = "GENRE_PLAYLIST";
2099
+ TrackListOriginType2["GENRE_CATALOGUE"] = "GENRE_CATALOGUE";
1992
2100
  TrackListOriginType2["ARTIST"] = "ARTIST";
1993
2101
  return TrackListOriginType2;
1994
2102
  })(TrackListOriginType || {});
@@ -2020,27 +2128,48 @@ var TrackListOriginFromTrack = class extends TrackListOrigin {
2020
2128
  };
2021
2129
  var TrackListOriginFromCriteriaPlaylist = class extends TrackListOrigin {
2022
2130
  /** `from`: the track the list starts at (server-side `?from=`), kept so later pages use it too. */
2023
- constructor(criteriaPlaylist, scope, from) {
2131
+ constructor(criteriaPlaylist, scope, from, selection, artistUuid) {
2024
2132
  super("GENRE_PLAYLIST" /* GENRE_PLAYLIST */, criteriaPlaylist.name, criteriaPlaylist.uuid, scope);
2025
2133
  this.criteriaPlaylist = criteriaPlaylist;
2026
2134
  this.from = from;
2135
+ this.selection = selection;
2136
+ this.artistUuid = artistUuid;
2027
2137
  }
2028
2138
  criteriaPlaylist;
2029
2139
  from;
2140
+ selection;
2141
+ artistUuid;
2030
2142
  };
2031
2143
  var TrackListOriginFromArtist = class extends TrackListOrigin {
2032
2144
  /** `ordering`/`from`: kept so later pages use the same order and start track. */
2033
- constructor(artist, scope, ordering, from, genreUuid) {
2145
+ constructor(artist, scope, ordering, from, genreUuid, selection) {
2034
2146
  super("ARTIST" /* ARTIST */, artist.name, artist.uuid, scope);
2035
2147
  this.artist = artist;
2036
2148
  this.ordering = ordering;
2037
2149
  this.from = from;
2038
2150
  this.genreUuid = genreUuid;
2151
+ this.selection = selection;
2039
2152
  }
2040
2153
  artist;
2041
2154
  ordering;
2042
2155
  from;
2043
2156
  genreUuid;
2157
+ selection;
2158
+ };
2159
+ var TrackListOriginFromGenreCatalogue = class extends TrackListOrigin {
2160
+ constructor(genre, scope, from, selection) {
2161
+ super("GENRE_CATALOGUE" /* GENRE_CATALOGUE */, genre.name, genre.uuid, scope);
2162
+ this.genre = genre;
2163
+ this.from = from;
2164
+ this.selection = selection;
2165
+ }
2166
+ genre;
2167
+ from;
2168
+ selection;
2169
+ ordering = "title";
2170
+ get genreUuid() {
2171
+ return this.genre.uuid;
2172
+ }
2044
2173
  };
2045
2174
 
2046
2175
  // src/player/PlayerContext.tsx
@@ -2166,9 +2295,10 @@ function TrackListProvider({
2166
2295
  [clearDelayedTrackLoad, loadTrackForPlayer]
2167
2296
  );
2168
2297
  const fetchTracksPage = (0, import_react13.useCallback)(
2169
- async (uuid, scope, page, from) => {
2298
+ async (uuid, scope, page, from, selection, artistUuid) => {
2170
2299
  const endpoint = genrePlaylistEndpoints[scope].tracks(uuid);
2171
- const params = { page, pageSize: TRACKS_PAGE_SIZE, ...from && { from } };
2300
+ if (scope === "me" && (selection || artistUuid)) throw new Error("Genre selections require reference scope");
2301
+ const params = { page, pageSize: TRACKS_PAGE_SIZE, ...from && { from }, ...genreMusicQueryParams(selection), ...artistUuid && { artist: artistUuid } };
2172
2302
  const response = await fetch2(endpoint, true, scope === "me", {}, params, false, !!from, page === 1);
2173
2303
  const parsed = parseWithLog(pageSchema, response, "fetchGenrePlaylistTracksPage");
2174
2304
  return {
@@ -2179,17 +2309,18 @@ function TrackListProvider({
2179
2309
  },
2180
2310
  [fetch2, pageSchema]
2181
2311
  );
2182
- const artistPageSchema = (0, import_react13.useMemo)(() => PaginatedResponseSchema(schema), [schema]);
2183
- const fetchArtistTracksPage = (0, import_react13.useCallback)(
2312
+ const cataloguePageSchema = (0, import_react13.useMemo)(() => PaginatedResponseSchema(schema), [schema]);
2313
+ const fetchCatalogueTracksPage = (0, import_react13.useCallback)(
2184
2314
  async (origin, page) => {
2185
2315
  const params = {
2186
- artist: origin.uuid,
2316
+ ...origin instanceof TrackListOriginFromArtist && { artist: origin.uuid },
2187
2317
  playable: true,
2188
2318
  ordering: origin.ordering,
2189
2319
  page,
2190
2320
  pageSize: TRACKS_PAGE_SIZE,
2191
2321
  ...origin.from && { from: origin.from },
2192
- ...origin.genreUuid && { genre: origin.genreUuid }
2322
+ ...origin.genreUuid && { genre: origin.genreUuid },
2323
+ ...genreMusicQueryParams(origin.selection)
2193
2324
  };
2194
2325
  const response = await fetch2(
2195
2326
  libraryEndpoints.reference.songs.list(),
@@ -2202,10 +2333,10 @@ function TrackListProvider({
2202
2333
  page === 1 && !!origin.from,
2203
2334
  page === 1
2204
2335
  );
2205
- const parsed = parseWithLog(artistPageSchema, response, "fetchArtistTracksPage");
2336
+ const parsed = parseWithLog(cataloguePageSchema, response, "fetchCatalogueTracksPage");
2206
2337
  return { tracks: parsed.results, total: parsed.overallTotal, nextPage: parsed.next ? parsed.page + 1 : null };
2207
2338
  },
2208
- [fetch2, artistPageSchema]
2339
+ [fetch2, cataloguePageSchema]
2209
2340
  );
2210
2341
  const advanceAfterTrackEnd = (0, import_react13.useCallback)(
2211
2342
  (event) => {
@@ -2277,7 +2408,7 @@ function TrackListProvider({
2277
2408
  const from = options?.startSongUuid;
2278
2409
  let page;
2279
2410
  try {
2280
- page = await fetchTracksPage(genrePlaylist.uuid, scope, 1, from);
2411
+ page = await fetchTracksPage(genrePlaylist.uuid, scope, 1, from, options?.selection, options?.artistUuid);
2281
2412
  } catch (error) {
2282
2413
  if (request !== latestPlayRequestRef.current) return;
2283
2414
  startingPlaybackRef.current = false;
@@ -2294,7 +2425,7 @@ function TrackListProvider({
2294
2425
  console.warn("No playable tracks found in genre playlist");
2295
2426
  return;
2296
2427
  }
2297
- const origin = new TrackListOriginFromCriteriaPlaylist(genrePlaylist, scope, from);
2428
+ const origin = new TrackListOriginFromCriteriaPlaylist(genrePlaylist, scope, from, options?.selection, options?.artistUuid);
2298
2429
  setAutoAdvanceScrollRequest(null);
2299
2430
  setTrackList(new TrackListFromCriteriaPlaylist(page.tracks, origin, page.total, page.nextPage));
2300
2431
  setSelectedTrack(startTrack);
@@ -2303,17 +2434,15 @@ function TrackListProvider({
2303
2434
  },
2304
2435
  [clearDelayedTrackLoad, fetchTracksPage, showTrackListSidebar, loadTrackForPlayer]
2305
2436
  );
2306
- const playNewTrackListFromArtist = (0, import_react13.useCallback)(
2307
- async (artist, scope, options) => {
2308
- if (scope !== "reference") throw new Error("Artist track lists only support the reference scope");
2437
+ const playCatalogue = (0, import_react13.useCallback)(
2438
+ async (origin) => {
2309
2439
  clearDelayedTrackLoad();
2310
2440
  const request = ++latestPlayRequestRef.current;
2311
2441
  startingPlaybackRef.current = true;
2312
- const from = options.startSongUuid;
2313
- const origin = new TrackListOriginFromArtist(artist, scope, options.ordering, from, options.genreUuid);
2442
+ const from = origin.from;
2314
2443
  let page;
2315
2444
  try {
2316
- page = await fetchArtistTracksPage(origin, 1);
2445
+ page = await fetchCatalogueTracksPage(origin, 1);
2317
2446
  } catch (error) {
2318
2447
  if (request !== latestPlayRequestRef.current) return;
2319
2448
  startingPlaybackRef.current = false;
@@ -2324,19 +2453,34 @@ function TrackListProvider({
2324
2453
  loadedContextRef.current = playback.snapshot().key;
2325
2454
  const startTrack = page.tracks[0];
2326
2455
  if (from && startTrack?.uuid !== from) {
2327
- throw new Error(`Artist ${artist.uuid} did not start at song ${from}`);
2456
+ throw new Error(`${origin instanceof TrackListOriginFromArtist ? "Artist" : "Catalogue"} ${origin.uuid} did not start at song ${from}`);
2328
2457
  }
2329
2458
  if (!startTrack) {
2330
- console.warn("No playable songs found for artist");
2459
+ console.warn("No playable songs found in catalogue");
2331
2460
  return;
2332
2461
  }
2333
- setTrackList(new TrackListFromArtist(page.tracks, origin, page.total, page.nextPage));
2462
+ setTrackList(origin instanceof TrackListOriginFromArtist ? new TrackListFromArtist(page.tracks, origin, page.total, page.nextPage) : new TrackList(page.tracks, origin, page.total, page.nextPage));
2334
2463
  setAutoAdvanceScrollRequest(null);
2335
2464
  setSelectedTrack(startTrack);
2336
2465
  showTrackListSidebar();
2337
2466
  loadTrackForPlayer(startTrack.uuid);
2338
2467
  },
2339
- [clearDelayedTrackLoad, fetchArtistTracksPage, showTrackListSidebar, loadTrackForPlayer]
2468
+ [clearDelayedTrackLoad, fetchCatalogueTracksPage, showTrackListSidebar, loadTrackForPlayer]
2469
+ );
2470
+ const playNewTrackListFromArtist = (0, import_react13.useCallback)(
2471
+ async (artist, scope, options) => {
2472
+ if (scope !== "reference") throw new Error("Artist track lists only support the reference scope");
2473
+ if (options.selection && !options.genreUuid) throw new Error("A genre selection requires a genre");
2474
+ return playCatalogue(new TrackListOriginFromArtist(artist, scope, options.ordering, options.startSongUuid, options.genreUuid, options.selection));
2475
+ },
2476
+ [playCatalogue]
2477
+ );
2478
+ const playNewTrackListFromGenreCatalogue = (0, import_react13.useCallback)(
2479
+ async (genre, scope, options) => {
2480
+ if (scope !== "reference") throw new Error("Genre catalogues only support the reference scope");
2481
+ return playCatalogue(new TrackListOriginFromGenreCatalogue(genre, scope, options?.startSongUuid, options?.selection));
2482
+ },
2483
+ [playCatalogue]
2340
2484
  );
2341
2485
  const contextKeyRef = (0, import_react13.useRef)(playback.key);
2342
2486
  (0, import_react13.useEffect)(() => {
@@ -2358,20 +2502,28 @@ function TrackListProvider({
2358
2502
  setTrackList(null);
2359
2503
  setSelectedTrack(null);
2360
2504
  if (origin instanceof TrackListOriginFromCriteriaPlaylist) {
2361
- void playNewTrackListFromGenrePlaylist(origin.criteriaPlaylist, origin.scope, { startSongUuid: selected?.uuid }).catch((error) => {
2505
+ void playNewTrackListFromGenrePlaylist(origin.criteriaPlaylist, origin.scope, { startSongUuid: selected?.uuid, selection: origin.selection, artistUuid: origin.artistUuid }).catch((error) => {
2362
2506
  if (error instanceof BackendError && error.code === "BAC4040" /* BACKEND_NOT_FOUND */) {
2363
- return playNewTrackListFromGenrePlaylist(origin.criteriaPlaylist, origin.scope).catch(() => {
2507
+ return playNewTrackListFromGenrePlaylist(origin.criteriaPlaylist, origin.scope, { selection: origin.selection, artistUuid: origin.artistUuid }).catch(() => {
2364
2508
  });
2365
2509
  }
2366
2510
  });
2367
2511
  } else if (origin instanceof TrackListOriginFromArtist) {
2368
- const options = { ordering: origin.ordering, genreUuid: origin.genreUuid };
2512
+ const options = { ordering: origin.ordering, genreUuid: origin.genreUuid, selection: origin.selection };
2369
2513
  void playNewTrackListFromArtist(origin.artist, origin.scope, { ...options, startSongUuid: selected?.uuid }).catch((error) => {
2370
2514
  if (error instanceof BackendError && error.code === "BAC4040" /* BACKEND_NOT_FOUND */) {
2371
2515
  return playNewTrackListFromArtist(origin.artist, origin.scope, options).catch(() => {
2372
2516
  });
2373
2517
  }
2374
2518
  });
2519
+ } else if (origin instanceof TrackListOriginFromGenreCatalogue) {
2520
+ const options = { selection: origin.selection };
2521
+ void playNewTrackListFromGenreCatalogue(origin.genre, origin.scope, { ...options, startSongUuid: selected?.uuid }).catch((error) => {
2522
+ if (error instanceof BackendError && error.code === "BAC4040" /* BACKEND_NOT_FOUND */) {
2523
+ return playNewTrackListFromGenreCatalogue(origin.genre, origin.scope, options).catch(() => {
2524
+ });
2525
+ }
2526
+ });
2375
2527
  } else if (origin instanceof TrackListOriginFromTrack && selected) {
2376
2528
  const request = latestPlayRequestRef.current;
2377
2529
  void (async () => {
@@ -2382,7 +2534,7 @@ function TrackListProvider({
2382
2534
  })().catch(() => {
2383
2535
  });
2384
2536
  }
2385
- }, [playback.key, trackList, selectedTrack, clearDelayedTrackLoad, playNewTrackListFromGenrePlaylist, playNewTrackListFromArtist, schema, fetch2]);
2537
+ }, [playback.key, trackList, selectedTrack, clearDelayedTrackLoad, playNewTrackListFromGenrePlaylist, playNewTrackListFromArtist, playNewTrackListFromGenreCatalogue, schema, fetch2]);
2386
2538
  const updateTrack = (0, import_react13.useCallback)((track) => {
2387
2539
  setTrackList((prev) => {
2388
2540
  if (!prev || !prev.tracks.some((listed) => listed.uuid === track.uuid)) return prev;
@@ -2394,22 +2546,22 @@ function TrackListProvider({
2394
2546
  const loadMore = (0, import_react13.useCallback)(async () => {
2395
2547
  if (!trackList || trackList.nextPage === null) return;
2396
2548
  const origin = trackList.origin;
2397
- if (!(origin instanceof TrackListOriginFromCriteriaPlaylist || origin instanceof TrackListOriginFromArtist)) return;
2549
+ if (!(origin instanceof TrackListOriginFromCriteriaPlaylist || origin instanceof TrackListOriginFromArtist || origin instanceof TrackListOriginFromGenreCatalogue)) return;
2398
2550
  if (loadingOriginRef.current === origin) return;
2399
2551
  const requestedPage = trackList.nextPage;
2400
2552
  loadingOriginRef.current = origin;
2401
2553
  try {
2402
- const page = origin instanceof TrackListOriginFromArtist ? await fetchArtistTracksPage(origin, requestedPage) : await fetchTracksPage(origin.criteriaPlaylist.uuid, origin.scope, requestedPage, origin.from);
2554
+ const page = origin instanceof TrackListOriginFromArtist || origin instanceof TrackListOriginFromGenreCatalogue ? await fetchCatalogueTracksPage(origin, requestedPage) : await fetchTracksPage(origin.criteriaPlaylist.uuid, origin.scope, requestedPage, origin.from, origin.selection, origin.artistUuid);
2403
2555
  setTrackList((prev) => {
2404
2556
  if (prev?.origin !== origin || prev.nextPage !== requestedPage) return prev;
2405
2557
  const loaded = new Set(prev.tracks.map((track) => track.uuid));
2406
2558
  const tracks = [...prev.tracks, ...page.tracks.filter((track) => !loaded.has(track.uuid))];
2407
- return origin instanceof TrackListOriginFromArtist ? new TrackListFromArtist(tracks, origin, page.total, page.nextPage) : new TrackListFromCriteriaPlaylist(tracks, origin, page.total, page.nextPage);
2559
+ return origin instanceof TrackListOriginFromArtist ? new TrackListFromArtist(tracks, origin, page.total, page.nextPage) : origin instanceof TrackListOriginFromGenreCatalogue ? new TrackList(tracks, origin, page.total, page.nextPage) : new TrackListFromCriteriaPlaylist(tracks, origin, page.total, page.nextPage);
2408
2560
  });
2409
2561
  } finally {
2410
2562
  if (loadingOriginRef.current === origin) loadingOriginRef.current = null;
2411
2563
  }
2412
- }, [trackList, fetchTracksPage, fetchArtistTracksPage]);
2564
+ }, [trackList, fetchTracksPage, fetchCatalogueTracksPage]);
2413
2565
  const selectedTrackIndex = trackList?.tracks.findIndex((track) => track.uuid === selectedTrack?.uuid) ?? -1;
2414
2566
  const nextTrack = trackList && selectedTrackIndex >= 0 ? trackList.tracks.slice(selectedTrackIndex + 1).find((track) => isTrackPlayable(track, runtimeUnplayableTrackIds, hasPlaybackFailure)) ?? null : null;
2415
2567
  const previousTrack = trackList && selectedTrackIndex > 0 ? trackList.tracks.slice(0, selectedTrackIndex).reverse().find((track) => isTrackPlayable(track, runtimeUnplayableTrackIds, hasPlaybackFailure)) ?? null : null;
@@ -2497,6 +2649,7 @@ function TrackListProvider({
2497
2649
  playNewTrackListFromTrackUuid,
2498
2650
  playNewTrackListFromGenrePlaylist,
2499
2651
  playNewTrackListFromArtist,
2652
+ playNewTrackListFromGenreCatalogue,
2500
2653
  fetchGenrePlaylistTracksPage: fetchTracksPage,
2501
2654
  loadMore,
2502
2655
  updateTrack
@@ -2514,6 +2667,7 @@ function TrackListProvider({
2514
2667
  playNewTrackListFromTrackUuid,
2515
2668
  playNewTrackListFromGenrePlaylist,
2516
2669
  playNewTrackListFromArtist,
2670
+ playNewTrackListFromGenreCatalogue,
2517
2671
  fetchTracksPage,
2518
2672
  loadMore,
2519
2673
  updateTrack
@@ -2544,24 +2698,24 @@ function ArtistNames({
2544
2698
  }
2545
2699
 
2546
2700
  // src/genre-tree/schemas/mb-artist.ts
2547
- var import_zod35 = require("zod");
2548
- var MbArtistDetailedSchema = import_zod35.z.object({
2549
- musicbrainzId: import_zod35.z.string().uuid(),
2550
- name: import_zod35.z.string(),
2701
+ var import_zod36 = require("zod");
2702
+ var MbArtistDetailedSchema = import_zod36.z.object({
2703
+ musicbrainzId: import_zod36.z.string().uuid(),
2704
+ name: import_zod36.z.string(),
2551
2705
  musicbrainzLink: HttpUrlSchema
2552
2706
  });
2553
2707
 
2554
2708
  // src/genre-tree/schemas/mb-recording.ts
2555
- var import_zod36 = require("zod");
2556
- var MbRecordingDetailedSchema = import_zod36.z.object({
2557
- musicbrainzId: import_zod36.z.string().uuid(),
2558
- title: import_zod36.z.string(),
2559
- score: import_zod36.z.number(),
2560
- musicbrainzArtists: import_zod36.z.array(MbArtistDetailedSchema),
2709
+ var import_zod37 = require("zod");
2710
+ var MbRecordingDetailedSchema = import_zod37.z.object({
2711
+ musicbrainzId: import_zod37.z.string().uuid(),
2712
+ title: import_zod37.z.string(),
2713
+ score: import_zod37.z.number(),
2714
+ musicbrainzArtists: import_zod37.z.array(MbArtistDetailedSchema),
2561
2715
  musicbrainzLink: HttpUrlSchema,
2562
- durationInSec: import_zod36.z.number().min(0).nullable().optional(),
2563
- durationStrInHourMinSec: import_zod36.z.string().nullable().optional(),
2564
- releaseDate: import_zod36.z.union([import_zod36.z.string().datetime(), import_zod36.z.string()]).transform((val) => {
2716
+ durationInSec: import_zod37.z.number().min(0).nullable().optional(),
2717
+ durationStrInHourMinSec: import_zod37.z.string().nullable().optional(),
2718
+ releaseDate: import_zod37.z.union([import_zod37.z.string().datetime(), import_zod37.z.string()]).transform((val) => {
2565
2719
  try {
2566
2720
  const date = new Date(val);
2567
2721
  if (isNaN(date.getTime())) {
@@ -2649,6 +2803,10 @@ function editGenreSongPages(data, edit) {
2649
2803
  CriteriaUpdateSchema,
2650
2804
  FORM_RATING_NULL_VALUE,
2651
2805
  FUZZY_MIN_SIMILARITY,
2806
+ GenreCatalogueCountsSchema,
2807
+ GenreCountsSchema,
2808
+ GenreCoverageSchema,
2809
+ GenrePlaylistSummarySchema,
2652
2810
  GenrePlaylistUuidSchema,
2653
2811
  GenreSearchResultSchema,
2654
2812
  GenreSearchResultsSchema,
@@ -2657,6 +2815,8 @@ function editGenreSongPages(data, edit) {
2657
2815
  MbArtistDetailedSchema,
2658
2816
  MbRecordingDetailedSchema,
2659
2817
  NO_VIDEO_LABEL,
2818
+ ReferenceGenreDetailedSchema,
2819
+ ReferenceGenrePlaylistSchema,
2660
2820
  RegionGenreLexiconEntrySchema,
2661
2821
  RegionGenreLexiconSchema,
2662
2822
  SEARCH_DEBOUNCE_MS,
@@ -2666,6 +2826,8 @@ function editGenreSongPages(data, edit) {
2666
2826
  SongHistorySchema,
2667
2827
  SongSearchResultSchema,
2668
2828
  SongSearchResultsSchema,
2829
+ SubgenreCountsSchema,
2830
+ SubgenreScopeSchema,
2669
2831
  TrackBaseSchema,
2670
2832
  TrackList,
2671
2833
  TrackListFromArtist,
@@ -2674,6 +2836,7 @@ function editGenreSongPages(data, edit) {
2674
2836
  TrackListOrigin,
2675
2837
  TrackListOriginFromArtist,
2676
2838
  TrackListOriginFromCriteriaPlaylist,
2839
+ TrackListOriginFromGenreCatalogue,
2677
2840
  TrackListOriginFromTrack,
2678
2841
  TrackListOriginType,
2679
2842
  TrackListProvider,
@@ -2685,12 +2848,17 @@ function editGenreSongPages(data, edit) {
2685
2848
  artistEndpoints,
2686
2849
  artistQueryKeys,
2687
2850
  capitalizeFirstLetter,
2851
+ defaultGenreMusicSelection,
2688
2852
  editGenreSongPages,
2689
2853
  foldSearchText,
2690
2854
  formatTime,
2691
2855
  genreEndpoints,
2856
+ genreMusicCount,
2857
+ genreMusicQueryParams,
2858
+ genreMusicSelectionKey,
2692
2859
  genrePlaylistEndpoints,
2693
2860
  genrePlaylistQueryKeys,
2861
+ genrePlaylistTrackCount,
2694
2862
  genreQueryKeys,
2695
2863
  genreSearchQueryKeys,
2696
2864
  genreUpdateMutationKey,