@vllnt/convex-music 0.1.0-canary.09eea4e

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 (301) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +169 -0
  3. package/dist/client/index.d.ts +284 -0
  4. package/dist/client/index.d.ts.map +1 -0
  5. package/dist/client/index.js +166 -0
  6. package/dist/client/index.js.map +1 -0
  7. package/dist/client/types.d.ts +100 -0
  8. package/dist/client/types.d.ts.map +1 -0
  9. package/dist/client/types.js +2 -0
  10. package/dist/client/types.js.map +1 -0
  11. package/dist/component/_generated/api.d.ts +125 -0
  12. package/dist/component/_generated/api.d.ts.map +1 -0
  13. package/dist/component/_generated/api.js +31 -0
  14. package/dist/component/_generated/api.js.map +1 -0
  15. package/dist/component/_generated/component.d.ts +1143 -0
  16. package/dist/component/_generated/component.d.ts.map +1 -0
  17. package/dist/component/_generated/component.js +11 -0
  18. package/dist/component/_generated/component.js.map +1 -0
  19. package/dist/component/_generated/dataModel.d.ts +46 -0
  20. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  21. package/dist/component/_generated/dataModel.js +11 -0
  22. package/dist/component/_generated/dataModel.js.map +1 -0
  23. package/dist/component/_generated/server.d.ts +133 -0
  24. package/dist/component/_generated/server.d.ts.map +1 -0
  25. package/dist/component/_generated/server.js +80 -0
  26. package/dist/component/_generated/server.js.map +1 -0
  27. package/dist/component/actions.d.ts +144 -0
  28. package/dist/component/actions.d.ts.map +1 -0
  29. package/dist/component/actions.js +125 -0
  30. package/dist/component/actions.js.map +1 -0
  31. package/dist/component/catalog/browse_order.d.ts +22 -0
  32. package/dist/component/catalog/browse_order.d.ts.map +1 -0
  33. package/dist/component/catalog/browse_order.js +37 -0
  34. package/dist/component/catalog/browse_order.js.map +1 -0
  35. package/dist/component/catalog/field_source_policy.d.ts +30 -0
  36. package/dist/component/catalog/field_source_policy.d.ts.map +1 -0
  37. package/dist/component/catalog/field_source_policy.js +36 -0
  38. package/dist/component/catalog/field_source_policy.js.map +1 -0
  39. package/dist/component/catalog/merge.d.ts +58 -0
  40. package/dist/component/catalog/merge.d.ts.map +1 -0
  41. package/dist/component/catalog/merge.js +74 -0
  42. package/dist/component/catalog/merge.js.map +1 -0
  43. package/dist/component/catalog/mutations.d.ts +78 -0
  44. package/dist/component/catalog/mutations.d.ts.map +1 -0
  45. package/dist/component/catalog/mutations.js +259 -0
  46. package/dist/component/catalog/mutations.js.map +1 -0
  47. package/dist/component/catalog/promote.d.ts +21 -0
  48. package/dist/component/catalog/promote.d.ts.map +1 -0
  49. package/dist/component/catalog/promote.js +25 -0
  50. package/dist/component/catalog/promote.js.map +1 -0
  51. package/dist/component/catalog/queries.d.ts +421 -0
  52. package/dist/component/catalog/queries.d.ts.map +1 -0
  53. package/dist/component/catalog/queries.js +168 -0
  54. package/dist/component/catalog/queries.js.map +1 -0
  55. package/dist/component/config/mutations.d.ts +11 -0
  56. package/dist/component/config/mutations.d.ts.map +1 -0
  57. package/dist/component/config/mutations.js +30 -0
  58. package/dist/component/config/mutations.js.map +1 -0
  59. package/dist/component/config/queries.d.ts +9 -0
  60. package/dist/component/config/queries.d.ts.map +1 -0
  61. package/dist/component/config/queries.js +20 -0
  62. package/dist/component/config/queries.js.map +1 -0
  63. package/dist/component/convex.config.d.ts +3 -0
  64. package/dist/component/convex.config.d.ts.map +1 -0
  65. package/dist/component/convex.config.js +30 -0
  66. package/dist/component/convex.config.js.map +1 -0
  67. package/dist/component/crons.d.ts +11 -0
  68. package/dist/component/crons.d.ts.map +1 -0
  69. package/dist/component/crons.js +41 -0
  70. package/dist/component/crons.js.map +1 -0
  71. package/dist/component/imports/actions.d.ts +119 -0
  72. package/dist/component/imports/actions.d.ts.map +1 -0
  73. package/dist/component/imports/actions.js +442 -0
  74. package/dist/component/imports/actions.js.map +1 -0
  75. package/dist/component/imports/dedupe.d.ts +29 -0
  76. package/dist/component/imports/dedupe.d.ts.map +1 -0
  77. package/dist/component/imports/dedupe.js +33 -0
  78. package/dist/component/imports/dedupe.js.map +1 -0
  79. package/dist/component/imports/mutations.d.ts +59 -0
  80. package/dist/component/imports/mutations.d.ts.map +1 -0
  81. package/dist/component/imports/mutations.js +151 -0
  82. package/dist/component/imports/mutations.js.map +1 -0
  83. package/dist/component/imports/queries.d.ts +68 -0
  84. package/dist/component/imports/queries.d.ts.map +1 -0
  85. package/dist/component/imports/queries.js +22 -0
  86. package/dist/component/imports/queries.js.map +1 -0
  87. package/dist/component/imports/state.d.ts +36 -0
  88. package/dist/component/imports/state.d.ts.map +1 -0
  89. package/dist/component/imports/state.js +62 -0
  90. package/dist/component/imports/state.js.map +1 -0
  91. package/dist/component/mutations.d.ts +55 -0
  92. package/dist/component/mutations.d.ts.map +1 -0
  93. package/dist/component/mutations.js +74 -0
  94. package/dist/component/mutations.js.map +1 -0
  95. package/dist/component/providers/actions.d.ts +26 -0
  96. package/dist/component/providers/actions.d.ts.map +1 -0
  97. package/dist/component/providers/actions.js +92 -0
  98. package/dist/component/providers/actions.js.map +1 -0
  99. package/dist/component/providers/apple/impl.d.ts +52 -0
  100. package/dist/component/providers/apple/impl.d.ts.map +1 -0
  101. package/dist/component/providers/apple/impl.js +127 -0
  102. package/dist/component/providers/apple/impl.js.map +1 -0
  103. package/dist/component/providers/apple/jwt.d.ts +32 -0
  104. package/dist/component/providers/apple/jwt.d.ts.map +1 -0
  105. package/dist/component/providers/apple/jwt.js +68 -0
  106. package/dist/component/providers/apple/jwt.js.map +1 -0
  107. package/dist/component/providers/apple/mappers.d.ts +20 -0
  108. package/dist/component/providers/apple/mappers.d.ts.map +1 -0
  109. package/dist/component/providers/apple/mappers.js +68 -0
  110. package/dist/component/providers/apple/mappers.js.map +1 -0
  111. package/dist/component/providers/apple/types.d.ts +80 -0
  112. package/dist/component/providers/apple/types.d.ts.map +1 -0
  113. package/dist/component/providers/apple/types.js +7 -0
  114. package/dist/component/providers/apple/types.js.map +1 -0
  115. package/dist/component/providers/deezer/impl.d.ts +37 -0
  116. package/dist/component/providers/deezer/impl.d.ts.map +1 -0
  117. package/dist/component/providers/deezer/impl.js +99 -0
  118. package/dist/component/providers/deezer/impl.js.map +1 -0
  119. package/dist/component/providers/deezer/mappers.d.ts +18 -0
  120. package/dist/component/providers/deezer/mappers.d.ts.map +1 -0
  121. package/dist/component/providers/deezer/mappers.js +53 -0
  122. package/dist/component/providers/deezer/mappers.js.map +1 -0
  123. package/dist/component/providers/deezer/types.d.ts +59 -0
  124. package/dist/component/providers/deezer/types.d.ts.map +1 -0
  125. package/dist/component/providers/deezer/types.js +7 -0
  126. package/dist/component/providers/deezer/types.js.map +1 -0
  127. package/dist/component/providers/fetch.d.ts +69 -0
  128. package/dist/component/providers/fetch.d.ts.map +1 -0
  129. package/dist/component/providers/fetch.js +145 -0
  130. package/dist/component/providers/fetch.js.map +1 -0
  131. package/dist/component/providers/musicbrainz/impl.d.ts +36 -0
  132. package/dist/component/providers/musicbrainz/impl.d.ts.map +1 -0
  133. package/dist/component/providers/musicbrainz/impl.js +74 -0
  134. package/dist/component/providers/musicbrainz/impl.js.map +1 -0
  135. package/dist/component/providers/musicbrainz/mappers.d.ts +10 -0
  136. package/dist/component/providers/musicbrainz/mappers.d.ts.map +1 -0
  137. package/dist/component/providers/musicbrainz/mappers.js +32 -0
  138. package/dist/component/providers/musicbrainz/mappers.js.map +1 -0
  139. package/dist/component/providers/musicbrainz/types.d.ts +24 -0
  140. package/dist/component/providers/musicbrainz/types.d.ts.map +1 -0
  141. package/dist/component/providers/musicbrainz/types.js +7 -0
  142. package/dist/component/providers/musicbrainz/types.js.map +1 -0
  143. package/dist/component/providers/registry.d.ts +22 -0
  144. package/dist/component/providers/registry.d.ts.map +1 -0
  145. package/dist/component/providers/registry.js +33 -0
  146. package/dist/component/providers/registry.js.map +1 -0
  147. package/dist/component/providers/spotify/client.d.ts +25 -0
  148. package/dist/component/providers/spotify/client.d.ts.map +1 -0
  149. package/dist/component/providers/spotify/client.js +30 -0
  150. package/dist/component/providers/spotify/client.js.map +1 -0
  151. package/dist/component/providers/spotify/impl.d.ts +51 -0
  152. package/dist/component/providers/spotify/impl.d.ts.map +1 -0
  153. package/dist/component/providers/spotify/impl.js +131 -0
  154. package/dist/component/providers/spotify/impl.js.map +1 -0
  155. package/dist/component/providers/spotify/mappers.d.ts +18 -0
  156. package/dist/component/providers/spotify/mappers.d.ts.map +1 -0
  157. package/dist/component/providers/spotify/mappers.js +60 -0
  158. package/dist/component/providers/spotify/mappers.js.map +1 -0
  159. package/dist/component/providers/spotify/types.d.ts +97 -0
  160. package/dist/component/providers/spotify/types.d.ts.map +1 -0
  161. package/dist/component/providers/spotify/types.js +7 -0
  162. package/dist/component/providers/spotify/types.js.map +1 -0
  163. package/dist/component/providers/types.d.ts +84 -0
  164. package/dist/component/providers/types.d.ts.map +1 -0
  165. package/dist/component/providers/types.js +10 -0
  166. package/dist/component/providers/types.js.map +1 -0
  167. package/dist/component/providers/wikidata/impl.d.ts +34 -0
  168. package/dist/component/providers/wikidata/impl.d.ts.map +1 -0
  169. package/dist/component/providers/wikidata/impl.js +88 -0
  170. package/dist/component/providers/wikidata/impl.js.map +1 -0
  171. package/dist/component/providers/wikidata/mappers.d.ts +11 -0
  172. package/dist/component/providers/wikidata/mappers.d.ts.map +1 -0
  173. package/dist/component/providers/wikidata/mappers.js +53 -0
  174. package/dist/component/providers/wikidata/mappers.js.map +1 -0
  175. package/dist/component/providers/wikidata/types.d.ts +35 -0
  176. package/dist/component/providers/wikidata/types.d.ts.map +1 -0
  177. package/dist/component/providers/wikidata/types.js +8 -0
  178. package/dist/component/providers/wikidata/types.js.map +1 -0
  179. package/dist/component/queries.d.ts +103 -0
  180. package/dist/component/queries.d.ts.map +1 -0
  181. package/dist/component/queries.js +45 -0
  182. package/dist/component/queries.js.map +1 -0
  183. package/dist/component/schema.d.ts +566 -0
  184. package/dist/component/schema.d.ts.map +1 -0
  185. package/dist/component/schema.js +59 -0
  186. package/dist/component/schema.js.map +1 -0
  187. package/dist/component/sources/actions.d.ts +51 -0
  188. package/dist/component/sources/actions.d.ts.map +1 -0
  189. package/dist/component/sources/actions.js +164 -0
  190. package/dist/component/sources/actions.js.map +1 -0
  191. package/dist/component/sources/mutations.d.ts +25 -0
  192. package/dist/component/sources/mutations.d.ts.map +1 -0
  193. package/dist/component/sources/mutations.js +64 -0
  194. package/dist/component/sources/mutations.js.map +1 -0
  195. package/dist/component/sources/queries.d.ts +19 -0
  196. package/dist/component/sources/queries.d.ts.map +1 -0
  197. package/dist/component/sources/queries.js +20 -0
  198. package/dist/component/sources/queries.js.map +1 -0
  199. package/dist/component/sync/lifecycle.d.ts +46 -0
  200. package/dist/component/sync/lifecycle.d.ts.map +1 -0
  201. package/dist/component/sync/lifecycle.js +87 -0
  202. package/dist/component/sync/lifecycle.js.map +1 -0
  203. package/dist/component/sync/mutations.d.ts +101 -0
  204. package/dist/component/sync/mutations.d.ts.map +1 -0
  205. package/dist/component/sync/mutations.js +132 -0
  206. package/dist/component/sync/mutations.js.map +1 -0
  207. package/dist/component/sync/queries.d.ts +69 -0
  208. package/dist/component/sync/queries.d.ts.map +1 -0
  209. package/dist/component/sync/queries.js +32 -0
  210. package/dist/component/sync/queries.js.map +1 -0
  211. package/dist/component/validators.d.ts +1112 -0
  212. package/dist/component/validators.d.ts.map +1 -0
  213. package/dist/component/validators.js +317 -0
  214. package/dist/component/validators.js.map +1 -0
  215. package/dist/react/index.d.ts +42 -0
  216. package/dist/react/index.d.ts.map +1 -0
  217. package/dist/react/index.js +43 -0
  218. package/dist/react/index.js.map +1 -0
  219. package/dist/shared.d.ts +28 -0
  220. package/dist/shared.d.ts.map +1 -0
  221. package/dist/shared.js +24 -0
  222. package/dist/shared.js.map +1 -0
  223. package/package.json +126 -0
  224. package/src/client/index.ts +558 -0
  225. package/src/client/types.ts +117 -0
  226. package/src/component/_generated/api.ts +141 -0
  227. package/src/component/_generated/component.ts +1814 -0
  228. package/src/component/_generated/dataModel.ts +60 -0
  229. package/src/component/_generated/server.ts +169 -0
  230. package/src/component/actions.ts +156 -0
  231. package/src/component/catalog/browse_order.test.ts +55 -0
  232. package/src/component/catalog/browse_order.ts +43 -0
  233. package/src/component/catalog/field_source_policy.test.ts +47 -0
  234. package/src/component/catalog/field_source_policy.ts +44 -0
  235. package/src/component/catalog/merge.test.ts +187 -0
  236. package/src/component/catalog/merge.ts +134 -0
  237. package/src/component/catalog/mutations.ts +328 -0
  238. package/src/component/catalog/promote.ts +40 -0
  239. package/src/component/catalog/queries.ts +220 -0
  240. package/src/component/config/mutations.ts +29 -0
  241. package/src/component/config/queries.ts +20 -0
  242. package/src/component/convex.config.ts +32 -0
  243. package/src/component/crons.test.ts +8 -0
  244. package/src/component/crons.ts +52 -0
  245. package/src/component/imports/actions.ts +553 -0
  246. package/src/component/imports/dedupe.test.ts +66 -0
  247. package/src/component/imports/dedupe.ts +54 -0
  248. package/src/component/imports/mutations.ts +203 -0
  249. package/src/component/imports/queries.ts +25 -0
  250. package/src/component/imports/state.test.ts +60 -0
  251. package/src/component/imports/state.ts +74 -0
  252. package/src/component/mutations.ts +96 -0
  253. package/src/component/providers/actions.ts +127 -0
  254. package/src/component/providers/apple/impl.test.ts +267 -0
  255. package/src/component/providers/apple/impl.ts +224 -0
  256. package/src/component/providers/apple/jwt.test.ts +153 -0
  257. package/src/component/providers/apple/jwt.ts +99 -0
  258. package/src/component/providers/apple/mappers.test.ts +190 -0
  259. package/src/component/providers/apple/mappers.ts +100 -0
  260. package/src/component/providers/apple/types.ts +77 -0
  261. package/src/component/providers/deezer/impl.test.ts +109 -0
  262. package/src/component/providers/deezer/impl.ts +179 -0
  263. package/src/component/providers/deezer/mappers.test.ts +78 -0
  264. package/src/component/providers/deezer/mappers.ts +72 -0
  265. package/src/component/providers/deezer/types.ts +59 -0
  266. package/src/component/providers/fetch.test.ts +282 -0
  267. package/src/component/providers/fetch.ts +190 -0
  268. package/src/component/providers/musicbrainz/impl.test.ts +79 -0
  269. package/src/component/providers/musicbrainz/impl.ts +132 -0
  270. package/src/component/providers/musicbrainz/mappers.test.ts +75 -0
  271. package/src/component/providers/musicbrainz/mappers.ts +34 -0
  272. package/src/component/providers/musicbrainz/types.ts +20 -0
  273. package/src/component/providers/registry.test.ts +14 -0
  274. package/src/component/providers/registry.ts +48 -0
  275. package/src/component/providers/spotify/client.test.ts +80 -0
  276. package/src/component/providers/spotify/client.ts +57 -0
  277. package/src/component/providers/spotify/impl.test.ts +311 -0
  278. package/src/component/providers/spotify/impl.ts +230 -0
  279. package/src/component/providers/spotify/mappers.test.ts +182 -0
  280. package/src/component/providers/spotify/mappers.ts +81 -0
  281. package/src/component/providers/spotify/types.ts +101 -0
  282. package/src/component/providers/types.ts +95 -0
  283. package/src/component/providers/wikidata/impl.test.ts +81 -0
  284. package/src/component/providers/wikidata/impl.ts +139 -0
  285. package/src/component/providers/wikidata/mappers.test.ts +62 -0
  286. package/src/component/providers/wikidata/mappers.ts +66 -0
  287. package/src/component/providers/wikidata/types.ts +28 -0
  288. package/src/component/queries.ts +51 -0
  289. package/src/component/schema.ts +81 -0
  290. package/src/component/sources/actions.ts +177 -0
  291. package/src/component/sources/mutations.ts +67 -0
  292. package/src/component/sources/queries.ts +21 -0
  293. package/src/component/sync/lifecycle.test.ts +72 -0
  294. package/src/component/sync/lifecycle.ts +121 -0
  295. package/src/component/sync/mutations.ts +154 -0
  296. package/src/component/sync/queries.ts +33 -0
  297. package/src/component/validators.ts +411 -0
  298. package/src/react/index.test.ts +78 -0
  299. package/src/react/index.ts +112 -0
  300. package/src/shared.ts +32 -0
  301. package/src/test.ts +22 -0
@@ -0,0 +1,60 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated data model types.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type {
12
+ DataModelFromSchemaDefinition,
13
+ DocumentByName,
14
+ TableNamesInDataModel,
15
+ SystemTableNames,
16
+ } from "convex/server";
17
+ import type { GenericId } from "convex/values";
18
+ import schema from "../schema.js";
19
+
20
+ /**
21
+ * The names of all of your Convex tables.
22
+ */
23
+ export type TableNames = TableNamesInDataModel<DataModel>;
24
+
25
+ /**
26
+ * The type of a document stored in Convex.
27
+ *
28
+ * @typeParam TableName - A string literal type of the table name (like "users").
29
+ */
30
+ export type Doc<TableName extends TableNames> = DocumentByName<
31
+ DataModel,
32
+ TableName
33
+ >;
34
+
35
+ /**
36
+ * An identifier for a document in Convex.
37
+ *
38
+ * Convex documents are uniquely identified by their `Id`, which is accessible
39
+ * on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/using/document-ids).
40
+ *
41
+ * Documents can be loaded using `db.get(tableName, id)` in query and mutation functions.
42
+ *
43
+ * IDs are just strings at runtime, but this type can be used to distinguish them from other
44
+ * strings when type checking.
45
+ *
46
+ * @typeParam TableName - A string literal type of the table name (like "users").
47
+ */
48
+ export type Id<TableName extends TableNames | SystemTableNames> =
49
+ GenericId<TableName>;
50
+
51
+ /**
52
+ * A type describing your Convex data model.
53
+ *
54
+ * This type includes information about what tables you have, the type of
55
+ * documents stored in those tables, and the indexes defined on them.
56
+ *
57
+ * This type is used to parameterize methods like `queryGeneric` and
58
+ * `mutationGeneric` to make them type-safe.
59
+ */
60
+ export type DataModel = DataModelFromSchemaDefinition<typeof schema>;
@@ -0,0 +1,169 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated utilities for implementing server-side Convex query and mutation functions.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type {
12
+ ActionBuilder,
13
+ HttpActionBuilder,
14
+ MutationBuilder,
15
+ QueryBuilder,
16
+ GenericActionCtx,
17
+ GenericMutationCtx,
18
+ GenericQueryCtx,
19
+ GenericDatabaseReader,
20
+ GenericDatabaseWriter,
21
+ } from "convex/server";
22
+ import {
23
+ actionGeneric,
24
+ httpActionGeneric,
25
+ queryGeneric,
26
+ mutationGeneric,
27
+ internalActionGeneric,
28
+ internalMutationGeneric,
29
+ internalQueryGeneric,
30
+ } from "convex/server";
31
+ import type { DataModel } from "./dataModel.js";
32
+
33
+ /**
34
+ * Typesafe environment variables.
35
+ *
36
+ * This includes platform-provided env vars and any variables declared in
37
+ * `convex.config.ts`.
38
+ */
39
+ type Env = {
40
+ readonly CONVEX_CLOUD_URL: string;
41
+ readonly CONVEX_SITE_URL: string;
42
+ };
43
+
44
+ /**
45
+ * Define a query in this Convex app's public API.
46
+ *
47
+ * This function will be allowed to read your Convex database and will be accessible from the client.
48
+ *
49
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
50
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
51
+ */
52
+ export const query: QueryBuilder<DataModel, "public"> = queryGeneric;
53
+
54
+ /**
55
+ * Define a query that is only accessible from other Convex functions (but not from the client).
56
+ *
57
+ * This function will be allowed to read from your Convex database. It will not be accessible from the client.
58
+ *
59
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
60
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
61
+ */
62
+ export const internalQuery: QueryBuilder<DataModel, "internal"> =
63
+ internalQueryGeneric;
64
+
65
+ /**
66
+ * Define a mutation in this Convex app's public API.
67
+ *
68
+ * This function will be allowed to modify your Convex database and will be accessible from the client.
69
+ *
70
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
71
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
72
+ */
73
+ export const mutation: MutationBuilder<DataModel, "public"> = mutationGeneric;
74
+
75
+ /**
76
+ * Define a mutation that is only accessible from other Convex functions (but not from the client).
77
+ *
78
+ * This function will be allowed to modify your Convex database. It will not be accessible from the client.
79
+ *
80
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
81
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
82
+ */
83
+ export const internalMutation: MutationBuilder<DataModel, "internal"> =
84
+ internalMutationGeneric;
85
+
86
+ /**
87
+ * Define an action in this Convex app's public API.
88
+ *
89
+ * An action is a function which can execute any JavaScript code, including non-deterministic
90
+ * code and code with side-effects, like calling third-party services.
91
+ * They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
92
+ * They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
93
+ *
94
+ * @param func - The action. It receives an {@link ActionCtx} as its first argument.
95
+ * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
96
+ */
97
+ export const action: ActionBuilder<DataModel, "public"> = actionGeneric;
98
+
99
+ /**
100
+ * Define an action that is only accessible from other Convex functions (but not from the client).
101
+ *
102
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument.
103
+ * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
104
+ */
105
+ export const internalAction: ActionBuilder<DataModel, "internal"> =
106
+ internalActionGeneric;
107
+
108
+ /**
109
+ * Define an HTTP action.
110
+ *
111
+ * The wrapped function will be used to respond to HTTP requests received
112
+ * by a Convex deployment if the requests matches the path and method where
113
+ * this action is routed. Be sure to route your httpAction in `convex/http.js`.
114
+ *
115
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument
116
+ * and a Fetch API `Request` object as its second.
117
+ * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
118
+ */
119
+ export const httpAction: HttpActionBuilder = httpActionGeneric;
120
+ export const env: Env = (globalThis as unknown as { process: { env: Env } })
121
+ .process.env;
122
+
123
+ /**
124
+ * A set of services for use within Convex query functions.
125
+ *
126
+ * The query context is passed as the first argument to any Convex query
127
+ * function run on the server.
128
+ *
129
+ * If you're using code generation, use the `QueryCtx` type in `convex/_generated/server.d.ts` instead.
130
+ */
131
+ export type QueryCtx = GenericQueryCtx<DataModel>;
132
+
133
+ /**
134
+ * A set of services for use within Convex mutation functions.
135
+ *
136
+ * The mutation context is passed as the first argument to any Convex mutation
137
+ * function run on the server.
138
+ *
139
+ * If you're using code generation, use the `MutationCtx` type in `convex/_generated/server.d.ts` instead.
140
+ */
141
+ export type MutationCtx = GenericMutationCtx<DataModel>;
142
+
143
+ /**
144
+ * A set of services for use within Convex action functions.
145
+ *
146
+ * The action context is passed as the first argument to any Convex action
147
+ * function run on the server.
148
+ */
149
+ export type ActionCtx = GenericActionCtx<DataModel>;
150
+
151
+ /**
152
+ * An interface to read from the database within Convex query functions.
153
+ *
154
+ * The two entry points are {@link DatabaseReader.get}, which fetches a single
155
+ * document by its {@link Id}, or {@link DatabaseReader.query}, which starts
156
+ * building a query.
157
+ */
158
+ export type DatabaseReader = GenericDatabaseReader<DataModel>;
159
+
160
+ /**
161
+ * An interface to read from and write to the database within Convex mutation
162
+ * functions.
163
+ *
164
+ * Convex guarantees that all writes within a single mutation are
165
+ * executed atomically, so you never have to worry about partial writes leaving
166
+ * your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
167
+ * for the guarantees Convex provides your functions.
168
+ */
169
+ export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Read-through fetch actions. Resolve a cached provider token, build the adapter,
3
+ * fetch on miss, promote the normalized facts into the durable catalog, and
4
+ * return the typed catalog row. Cache-through: an entity already in the catalog
5
+ * is returned without re-fetching unless `force` is set. `search` is discovery —
6
+ * it returns normalized provider hits without promoting them.
7
+ */
8
+
9
+ import { v } from "convex/values";
10
+ import { api } from "./_generated/api.js";
11
+ import type { Doc } from "./_generated/dataModel.js";
12
+ import { action } from "./_generated/server.js";
13
+ import type { NormalizedArtist, NormalizedTrack } from "../client/types.js";
14
+ import { upsertCreditedArtists } from "./catalog/promote.js";
15
+ import { adapterFor } from "./providers/actions.js";
16
+ import { artistDoc, artistValue, provider, trackDoc, trackValue } from "./validators.js";
17
+
18
+ /** A normalized search hit (provider id + value), discriminated by kind. */
19
+ type SearchHit =
20
+ | { type: "artist"; externalId: string; value: NormalizedArtist }
21
+ | { type: "track"; externalId: string; value: NormalizedTrack };
22
+
23
+ const searchType = v.union(v.literal("artist"), v.literal("track"));
24
+
25
+ const searchResult = v.union(
26
+ v.object({
27
+ type: v.literal("artist"),
28
+ externalId: v.string(),
29
+ value: artistValue,
30
+ }),
31
+ v.object({
32
+ type: v.literal("track"),
33
+ externalId: v.string(),
34
+ value: trackValue,
35
+ }),
36
+ );
37
+
38
+ /**
39
+ * Fetch an artist by provider id, promoting it into the catalog. Returns the
40
+ * unified artist row (cache-through unless `force`).
41
+ */
42
+ export const fetchArtist = action({
43
+ args: { provider, externalId: v.string(), force: v.optional(v.boolean()) },
44
+ returns: v.union(v.null(), artistDoc),
45
+ handler: async (ctx, args): Promise<Doc<"artists"> | null> => {
46
+ if (args.force !== true) {
47
+ const existing = await ctx.runQuery(
48
+ api.catalog.queries.getArtistByProvider,
49
+ { provider: args.provider, providerId: args.externalId },
50
+ );
51
+ if (existing !== null) return existing;
52
+ }
53
+ const adapter = await adapterFor(ctx, args.provider);
54
+ const result = await adapter.getArtist(args.externalId);
55
+ const artistId = await ctx.runMutation(
56
+ api.catalog.mutations.upsertArtist,
57
+ { provider: args.provider, externalId: result.externalId, value: result.value },
58
+ );
59
+ return await ctx.runQuery(api.catalog.queries.getArtist, { id: artistId });
60
+ },
61
+ });
62
+
63
+ /**
64
+ * Fetch a track by provider id, resolving + promoting its credited artists and
65
+ * the track into the catalog. Returns the unified track row (cache-through
66
+ * unless `force`).
67
+ */
68
+ export const fetchTrack = action({
69
+ args: { provider, externalId: v.string(), force: v.optional(v.boolean()) },
70
+ returns: v.union(v.null(), trackDoc),
71
+ handler: async (ctx, args): Promise<Doc<"tracks"> | null> => {
72
+ if (args.force !== true) {
73
+ const existing = await ctx.runQuery(
74
+ api.catalog.queries.getTrackByProvider,
75
+ { provider: args.provider, providerId: args.externalId },
76
+ );
77
+ if (existing !== null) return existing;
78
+ }
79
+ const adapter = await adapterFor(ctx, args.provider);
80
+ const result = await adapter.getTrack(args.externalId);
81
+ const artistIds = await upsertCreditedArtists(
82
+ ctx,
83
+ args.provider,
84
+ result.value.artists,
85
+ );
86
+ const trackId = await ctx.runMutation(api.catalog.mutations.upsertTrack, {
87
+ provider: args.provider,
88
+ externalId: result.externalId,
89
+ value: result.value,
90
+ artistIds,
91
+ });
92
+ return await ctx.runQuery(api.catalog.queries.getTrack, { id: trackId });
93
+ },
94
+ });
95
+
96
+ /**
97
+ * Search a provider for artists or tracks. Returns normalized hits (provider id +
98
+ * value); does not promote — promotion happens on an explicit fetch/import.
99
+ */
100
+ export const search = action({
101
+ args: { provider, query: v.string(), type: searchType },
102
+ returns: v.array(searchResult),
103
+ handler: async (ctx, args): Promise<SearchHit[]> => {
104
+ const adapter = await adapterFor(ctx, args.provider);
105
+ const results = await adapter.search(args.query, args.type);
106
+ return results.map((hit) =>
107
+ hit.type === "artist"
108
+ ? {
109
+ type: hit.type,
110
+ externalId: hit.data.externalId,
111
+ value: hit.data.value,
112
+ }
113
+ : {
114
+ type: hit.type,
115
+ externalId: hit.data.externalId,
116
+ value: hit.data.value,
117
+ },
118
+ );
119
+ },
120
+ });
121
+
122
+ /**
123
+ * Resolve a track by ISRC, cross-provider: return the unified catalog track if
124
+ * present, else search the given provider by ISRC and promote the first hit.
125
+ * Powers "playlist from provider A, track data from provider B" — the host
126
+ * imports a playlist's membership, then resolves each ISRC against its preferred
127
+ * provider. `null` if no provider has the ISRC.
128
+ */
129
+ export const resolveByIsrc = action({
130
+ args: { isrc: v.string(), provider },
131
+ returns: v.union(v.null(), trackDoc),
132
+ handler: async (ctx, args): Promise<Doc<"tracks"> | null> => {
133
+ const existing = await ctx.runQuery(api.catalog.queries.getTrackByIsrc, {
134
+ isrc: args.isrc,
135
+ });
136
+ if (existing !== null) return existing;
137
+ const adapter = await adapterFor(ctx, args.provider);
138
+ const hits = await adapter.searchByIsrc(args.isrc);
139
+ const first = hits[0];
140
+ if (first === undefined) return null;
141
+ const artistIds = await upsertCreditedArtists(
142
+ ctx,
143
+ args.provider,
144
+ first.value.artists,
145
+ );
146
+ await ctx.runMutation(api.catalog.mutations.upsertTrack, {
147
+ provider: args.provider,
148
+ externalId: first.externalId,
149
+ value: first.value,
150
+ artistIds,
151
+ });
152
+ return await ctx.runQuery(api.catalog.queries.getTrackByIsrc, {
153
+ isrc: args.isrc,
154
+ });
155
+ },
156
+ });
@@ -0,0 +1,55 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ dailyRotationHash,
4
+ orderByDailyRotation,
5
+ utcDateBucket,
6
+ } from "./browse_order.js";
7
+
8
+ describe("utcDateBucket", () => {
9
+ it("returns the UTC YYYY-MM-DD", () => {
10
+ expect(utcDateBucket(Date.parse("2026-06-17T13:45:00Z"))).toBe("2026-06-17");
11
+ });
12
+ });
13
+
14
+ describe("dailyRotationHash", () => {
15
+ it("is deterministic per (bucket, id)", () => {
16
+ expect(dailyRotationHash("2026-06-17", "x")).toBe(
17
+ dailyRotationHash("2026-06-17", "x"),
18
+ );
19
+ });
20
+
21
+ it("rotates across day buckets", () => {
22
+ expect(dailyRotationHash("2026-06-17", "x")).not.toBe(
23
+ dailyRotationHash("2026-06-18", "x"),
24
+ );
25
+ });
26
+
27
+ it("is an unsigned 32-bit int", () => {
28
+ const h = dailyRotationHash("2026-06-17", "anything");
29
+ expect(h).toBeGreaterThanOrEqual(0);
30
+ expect(h).toBeLessThanOrEqual(0xffffffff);
31
+ });
32
+ });
33
+
34
+ describe("orderByDailyRotation", () => {
35
+ const items = [{ _id: "a" }, { _id: "b" }, { _id: "c" }, { _id: "d" }];
36
+
37
+ it("sorts by ascending rotation hash, all items preserved", () => {
38
+ const ordered = orderByDailyRotation(items, "2026-06-17");
39
+ expect(new Set(ordered.map((i) => i._id))).toEqual(
40
+ new Set(["a", "b", "c", "d"]),
41
+ );
42
+ const hashes = ordered.map((i) => dailyRotationHash("2026-06-17", i._id));
43
+ expect(hashes).toEqual([...hashes].sort((x, y) => x - y));
44
+ });
45
+
46
+ it("is stable within a UTC day", () => {
47
+ expect(orderByDailyRotation(items, "2026-06-17")).toEqual(
48
+ orderByDailyRotation(items, "2026-06-17"),
49
+ );
50
+ });
51
+
52
+ it("handles an empty list", () => {
53
+ expect(orderByDailyRotation([], "2026-06-17")).toEqual([]);
54
+ });
55
+ });
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Deterministic daily-rotation ordering (songtrivia's `browse_order`). An FNV-1a
3
+ * hash over `dateBucket:id` gives a stable-within-a-UTC-day, rotates-at-midnight
4
+ * order — stable-but-rotating browse with zero host state. Used by the
5
+ * `selectEligible` daily-rotation mode.
6
+ */
7
+
8
+ const FNV_32_OFFSET = 0x811c9dc5;
9
+ const FNV_32_PRIME = 0x01000193;
10
+
11
+ /** The UTC day bucket (`YYYY-MM-DD`) for a timestamp. */
12
+ export function utcDateBucket(nowMs: number): string {
13
+ return new Date(nowMs).toISOString().slice(0, 10);
14
+ }
15
+
16
+ /** FNV-1a hash of `dateBucket:id` as an unsigned 32-bit int. */
17
+ export function dailyRotationHash(dateBucket: string, id: string): number {
18
+ let hash = FNV_32_OFFSET;
19
+ const input = `${dateBucket}:${id}`;
20
+ for (let index = 0; index < input.length; index += 1) {
21
+ hash ^= input.charCodeAt(index);
22
+ hash = Math.imul(hash, FNV_32_PRIME);
23
+ }
24
+ return hash >>> 0;
25
+ }
26
+
27
+ /**
28
+ * Order items by their daily-rotation hash (ascending). Stable within a UTC day,
29
+ * rotates daily. Equal hashes (astronomically rare for distinct ids) keep input
30
+ * order via the stable sort.
31
+ *
32
+ * @param items - rows carrying a string `_id`.
33
+ * @param dateBucket - the UTC day bucket (see {@link utcDateBucket}).
34
+ */
35
+ export function orderByDailyRotation<T extends { _id: string }>(
36
+ items: readonly T[],
37
+ dateBucket: string,
38
+ ): T[] {
39
+ return items
40
+ .map((item) => ({ item, key: dailyRotationHash(dateBucket, item._id) }))
41
+ .sort((a, b) => a.key - b.key)
42
+ .map((entry) => entry.item);
43
+ }
@@ -0,0 +1,47 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { projectField } from "./field_source_policy.js";
3
+
4
+ interface Entry {
5
+ provider: "spotify" | "apple" | "wikidata";
6
+ imageUrl?: string;
7
+ }
8
+
9
+ const entries: Entry[] = [
10
+ { provider: "spotify", imageUrl: "https://sp/img" },
11
+ { provider: "apple", imageUrl: "https://ap/img" },
12
+ { provider: "wikidata" }, // no image
13
+ ];
14
+
15
+ const image = (e: Entry) => e.imageUrl;
16
+
17
+ describe("projectField", () => {
18
+ it("returns the fallback when no spec is given", () => {
19
+ expect(projectField(entries, undefined, image, "fb")).toBe("fb");
20
+ });
21
+
22
+ it("{from}: uses the named provider's value", () => {
23
+ expect(projectField(entries, { from: "apple" }, image, "fb")).toBe(
24
+ "https://ap/img",
25
+ );
26
+ });
27
+
28
+ it("{from}: falls back when the named provider has no value", () => {
29
+ expect(projectField(entries, { from: "wikidata" }, image, "fb")).toBe("fb");
30
+ });
31
+
32
+ it("{from}: falls back when the named provider is absent", () => {
33
+ expect(projectField(entries, { from: "deezer" }, image, "fb")).toBe("fb");
34
+ });
35
+
36
+ it("{prefer}: takes the first available, skipping providers without a value", () => {
37
+ expect(
38
+ projectField(entries, { prefer: ["wikidata", "spotify"] }, image, "fb"),
39
+ ).toBe("https://sp/img");
40
+ });
41
+
42
+ it("{prefer}: falls back when none have a value", () => {
43
+ expect(
44
+ projectField(entries, { prefer: ["wikidata", "deezer"] }, image, "fb"),
45
+ ).toBe("fb");
46
+ });
47
+ });
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Field-source projection (scalar mode). Given an entity's per-provider
3
+ * `providers[]` provenance and a per-field {@link SourceSpec}, resolve which
4
+ * provider supplies a field's value: `{ from }` (one provider) or `{ prefer }`
5
+ * (ordered, first-available). Falls back to the entity's canonical field when the
6
+ * chosen provider has no value. The subset / `from: "all"` map mode is deferred
7
+ * (no consumer yet); this is the `{from}` + `{prefer}` scalar path. The artist
8
+ * image policy is this applied to `imageUrl`.
9
+ */
10
+
11
+ import type { Provider } from "../../shared.js";
12
+
13
+ /** How a single field's source provider(s) are chosen. */
14
+ export type SourceSpec = { from: Provider } | { prefer: Provider[] };
15
+
16
+ /**
17
+ * Resolve a field from the policy-chosen provider's provenance entry, or the
18
+ * fallback. Keyed by the open `Provider` union, so adding a provider only widens
19
+ * the policy — never changes a field's resolved type (the N-proof principle).
20
+ *
21
+ * @param entries - the entity's per-provider provenance.
22
+ * @param spec - the field's source policy (undefined → fallback).
23
+ * @param getValue - extracts the field from a provenance entry.
24
+ * @param fallback - the entity's canonical value when the source has none.
25
+ */
26
+ export function projectField<E extends { provider: Provider }, V>(
27
+ entries: readonly E[],
28
+ spec: SourceSpec | undefined,
29
+ getValue: (entry: E) => V | undefined,
30
+ fallback: V | undefined,
31
+ ): V | undefined {
32
+ if (spec === undefined) return fallback;
33
+ if ("from" in spec) {
34
+ const entry = entries.find((e) => e.provider === spec.from);
35
+ const value = entry === undefined ? undefined : getValue(entry);
36
+ return value ?? fallback;
37
+ }
38
+ for (const prov of spec.prefer) {
39
+ const entry = entries.find((e) => e.provider === prov);
40
+ const value = entry === undefined ? undefined : getValue(entry);
41
+ if (value !== undefined) return value;
42
+ }
43
+ return fallback;
44
+ }