@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.
- package/LICENSE +21 -0
- package/README.md +169 -0
- package/dist/client/index.d.ts +284 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +166 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +100 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +2 -0
- package/dist/client/types.js.map +1 -0
- package/dist/component/_generated/api.d.ts +125 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +1143 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +133 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +80 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/actions.d.ts +144 -0
- package/dist/component/actions.d.ts.map +1 -0
- package/dist/component/actions.js +125 -0
- package/dist/component/actions.js.map +1 -0
- package/dist/component/catalog/browse_order.d.ts +22 -0
- package/dist/component/catalog/browse_order.d.ts.map +1 -0
- package/dist/component/catalog/browse_order.js +37 -0
- package/dist/component/catalog/browse_order.js.map +1 -0
- package/dist/component/catalog/field_source_policy.d.ts +30 -0
- package/dist/component/catalog/field_source_policy.d.ts.map +1 -0
- package/dist/component/catalog/field_source_policy.js +36 -0
- package/dist/component/catalog/field_source_policy.js.map +1 -0
- package/dist/component/catalog/merge.d.ts +58 -0
- package/dist/component/catalog/merge.d.ts.map +1 -0
- package/dist/component/catalog/merge.js +74 -0
- package/dist/component/catalog/merge.js.map +1 -0
- package/dist/component/catalog/mutations.d.ts +78 -0
- package/dist/component/catalog/mutations.d.ts.map +1 -0
- package/dist/component/catalog/mutations.js +259 -0
- package/dist/component/catalog/mutations.js.map +1 -0
- package/dist/component/catalog/promote.d.ts +21 -0
- package/dist/component/catalog/promote.d.ts.map +1 -0
- package/dist/component/catalog/promote.js +25 -0
- package/dist/component/catalog/promote.js.map +1 -0
- package/dist/component/catalog/queries.d.ts +421 -0
- package/dist/component/catalog/queries.d.ts.map +1 -0
- package/dist/component/catalog/queries.js +168 -0
- package/dist/component/catalog/queries.js.map +1 -0
- package/dist/component/config/mutations.d.ts +11 -0
- package/dist/component/config/mutations.d.ts.map +1 -0
- package/dist/component/config/mutations.js +30 -0
- package/dist/component/config/mutations.js.map +1 -0
- package/dist/component/config/queries.d.ts +9 -0
- package/dist/component/config/queries.d.ts.map +1 -0
- package/dist/component/config/queries.js +20 -0
- package/dist/component/config/queries.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +30 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/crons.d.ts +11 -0
- package/dist/component/crons.d.ts.map +1 -0
- package/dist/component/crons.js +41 -0
- package/dist/component/crons.js.map +1 -0
- package/dist/component/imports/actions.d.ts +119 -0
- package/dist/component/imports/actions.d.ts.map +1 -0
- package/dist/component/imports/actions.js +442 -0
- package/dist/component/imports/actions.js.map +1 -0
- package/dist/component/imports/dedupe.d.ts +29 -0
- package/dist/component/imports/dedupe.d.ts.map +1 -0
- package/dist/component/imports/dedupe.js +33 -0
- package/dist/component/imports/dedupe.js.map +1 -0
- package/dist/component/imports/mutations.d.ts +59 -0
- package/dist/component/imports/mutations.d.ts.map +1 -0
- package/dist/component/imports/mutations.js +151 -0
- package/dist/component/imports/mutations.js.map +1 -0
- package/dist/component/imports/queries.d.ts +68 -0
- package/dist/component/imports/queries.d.ts.map +1 -0
- package/dist/component/imports/queries.js +22 -0
- package/dist/component/imports/queries.js.map +1 -0
- package/dist/component/imports/state.d.ts +36 -0
- package/dist/component/imports/state.d.ts.map +1 -0
- package/dist/component/imports/state.js +62 -0
- package/dist/component/imports/state.js.map +1 -0
- package/dist/component/mutations.d.ts +55 -0
- package/dist/component/mutations.d.ts.map +1 -0
- package/dist/component/mutations.js +74 -0
- package/dist/component/mutations.js.map +1 -0
- package/dist/component/providers/actions.d.ts +26 -0
- package/dist/component/providers/actions.d.ts.map +1 -0
- package/dist/component/providers/actions.js +92 -0
- package/dist/component/providers/actions.js.map +1 -0
- package/dist/component/providers/apple/impl.d.ts +52 -0
- package/dist/component/providers/apple/impl.d.ts.map +1 -0
- package/dist/component/providers/apple/impl.js +127 -0
- package/dist/component/providers/apple/impl.js.map +1 -0
- package/dist/component/providers/apple/jwt.d.ts +32 -0
- package/dist/component/providers/apple/jwt.d.ts.map +1 -0
- package/dist/component/providers/apple/jwt.js +68 -0
- package/dist/component/providers/apple/jwt.js.map +1 -0
- package/dist/component/providers/apple/mappers.d.ts +20 -0
- package/dist/component/providers/apple/mappers.d.ts.map +1 -0
- package/dist/component/providers/apple/mappers.js +68 -0
- package/dist/component/providers/apple/mappers.js.map +1 -0
- package/dist/component/providers/apple/types.d.ts +80 -0
- package/dist/component/providers/apple/types.d.ts.map +1 -0
- package/dist/component/providers/apple/types.js +7 -0
- package/dist/component/providers/apple/types.js.map +1 -0
- package/dist/component/providers/deezer/impl.d.ts +37 -0
- package/dist/component/providers/deezer/impl.d.ts.map +1 -0
- package/dist/component/providers/deezer/impl.js +99 -0
- package/dist/component/providers/deezer/impl.js.map +1 -0
- package/dist/component/providers/deezer/mappers.d.ts +18 -0
- package/dist/component/providers/deezer/mappers.d.ts.map +1 -0
- package/dist/component/providers/deezer/mappers.js +53 -0
- package/dist/component/providers/deezer/mappers.js.map +1 -0
- package/dist/component/providers/deezer/types.d.ts +59 -0
- package/dist/component/providers/deezer/types.d.ts.map +1 -0
- package/dist/component/providers/deezer/types.js +7 -0
- package/dist/component/providers/deezer/types.js.map +1 -0
- package/dist/component/providers/fetch.d.ts +69 -0
- package/dist/component/providers/fetch.d.ts.map +1 -0
- package/dist/component/providers/fetch.js +145 -0
- package/dist/component/providers/fetch.js.map +1 -0
- package/dist/component/providers/musicbrainz/impl.d.ts +36 -0
- package/dist/component/providers/musicbrainz/impl.d.ts.map +1 -0
- package/dist/component/providers/musicbrainz/impl.js +74 -0
- package/dist/component/providers/musicbrainz/impl.js.map +1 -0
- package/dist/component/providers/musicbrainz/mappers.d.ts +10 -0
- package/dist/component/providers/musicbrainz/mappers.d.ts.map +1 -0
- package/dist/component/providers/musicbrainz/mappers.js +32 -0
- package/dist/component/providers/musicbrainz/mappers.js.map +1 -0
- package/dist/component/providers/musicbrainz/types.d.ts +24 -0
- package/dist/component/providers/musicbrainz/types.d.ts.map +1 -0
- package/dist/component/providers/musicbrainz/types.js +7 -0
- package/dist/component/providers/musicbrainz/types.js.map +1 -0
- package/dist/component/providers/registry.d.ts +22 -0
- package/dist/component/providers/registry.d.ts.map +1 -0
- package/dist/component/providers/registry.js +33 -0
- package/dist/component/providers/registry.js.map +1 -0
- package/dist/component/providers/spotify/client.d.ts +25 -0
- package/dist/component/providers/spotify/client.d.ts.map +1 -0
- package/dist/component/providers/spotify/client.js +30 -0
- package/dist/component/providers/spotify/client.js.map +1 -0
- package/dist/component/providers/spotify/impl.d.ts +51 -0
- package/dist/component/providers/spotify/impl.d.ts.map +1 -0
- package/dist/component/providers/spotify/impl.js +131 -0
- package/dist/component/providers/spotify/impl.js.map +1 -0
- package/dist/component/providers/spotify/mappers.d.ts +18 -0
- package/dist/component/providers/spotify/mappers.d.ts.map +1 -0
- package/dist/component/providers/spotify/mappers.js +60 -0
- package/dist/component/providers/spotify/mappers.js.map +1 -0
- package/dist/component/providers/spotify/types.d.ts +97 -0
- package/dist/component/providers/spotify/types.d.ts.map +1 -0
- package/dist/component/providers/spotify/types.js +7 -0
- package/dist/component/providers/spotify/types.js.map +1 -0
- package/dist/component/providers/types.d.ts +84 -0
- package/dist/component/providers/types.d.ts.map +1 -0
- package/dist/component/providers/types.js +10 -0
- package/dist/component/providers/types.js.map +1 -0
- package/dist/component/providers/wikidata/impl.d.ts +34 -0
- package/dist/component/providers/wikidata/impl.d.ts.map +1 -0
- package/dist/component/providers/wikidata/impl.js +88 -0
- package/dist/component/providers/wikidata/impl.js.map +1 -0
- package/dist/component/providers/wikidata/mappers.d.ts +11 -0
- package/dist/component/providers/wikidata/mappers.d.ts.map +1 -0
- package/dist/component/providers/wikidata/mappers.js +53 -0
- package/dist/component/providers/wikidata/mappers.js.map +1 -0
- package/dist/component/providers/wikidata/types.d.ts +35 -0
- package/dist/component/providers/wikidata/types.d.ts.map +1 -0
- package/dist/component/providers/wikidata/types.js +8 -0
- package/dist/component/providers/wikidata/types.js.map +1 -0
- package/dist/component/queries.d.ts +103 -0
- package/dist/component/queries.d.ts.map +1 -0
- package/dist/component/queries.js +45 -0
- package/dist/component/queries.js.map +1 -0
- package/dist/component/schema.d.ts +566 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +59 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/component/sources/actions.d.ts +51 -0
- package/dist/component/sources/actions.d.ts.map +1 -0
- package/dist/component/sources/actions.js +164 -0
- package/dist/component/sources/actions.js.map +1 -0
- package/dist/component/sources/mutations.d.ts +25 -0
- package/dist/component/sources/mutations.d.ts.map +1 -0
- package/dist/component/sources/mutations.js +64 -0
- package/dist/component/sources/mutations.js.map +1 -0
- package/dist/component/sources/queries.d.ts +19 -0
- package/dist/component/sources/queries.d.ts.map +1 -0
- package/dist/component/sources/queries.js +20 -0
- package/dist/component/sources/queries.js.map +1 -0
- package/dist/component/sync/lifecycle.d.ts +46 -0
- package/dist/component/sync/lifecycle.d.ts.map +1 -0
- package/dist/component/sync/lifecycle.js +87 -0
- package/dist/component/sync/lifecycle.js.map +1 -0
- package/dist/component/sync/mutations.d.ts +101 -0
- package/dist/component/sync/mutations.d.ts.map +1 -0
- package/dist/component/sync/mutations.js +132 -0
- package/dist/component/sync/mutations.js.map +1 -0
- package/dist/component/sync/queries.d.ts +69 -0
- package/dist/component/sync/queries.d.ts.map +1 -0
- package/dist/component/sync/queries.js +32 -0
- package/dist/component/sync/queries.js.map +1 -0
- package/dist/component/validators.d.ts +1112 -0
- package/dist/component/validators.d.ts.map +1 -0
- package/dist/component/validators.js +317 -0
- package/dist/component/validators.js.map +1 -0
- package/dist/react/index.d.ts +42 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +43 -0
- package/dist/react/index.js.map +1 -0
- package/dist/shared.d.ts +28 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +24 -0
- package/dist/shared.js.map +1 -0
- package/package.json +126 -0
- package/src/client/index.ts +558 -0
- package/src/client/types.ts +117 -0
- package/src/component/_generated/api.ts +141 -0
- package/src/component/_generated/component.ts +1814 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +169 -0
- package/src/component/actions.ts +156 -0
- package/src/component/catalog/browse_order.test.ts +55 -0
- package/src/component/catalog/browse_order.ts +43 -0
- package/src/component/catalog/field_source_policy.test.ts +47 -0
- package/src/component/catalog/field_source_policy.ts +44 -0
- package/src/component/catalog/merge.test.ts +187 -0
- package/src/component/catalog/merge.ts +134 -0
- package/src/component/catalog/mutations.ts +328 -0
- package/src/component/catalog/promote.ts +40 -0
- package/src/component/catalog/queries.ts +220 -0
- package/src/component/config/mutations.ts +29 -0
- package/src/component/config/queries.ts +20 -0
- package/src/component/convex.config.ts +32 -0
- package/src/component/crons.test.ts +8 -0
- package/src/component/crons.ts +52 -0
- package/src/component/imports/actions.ts +553 -0
- package/src/component/imports/dedupe.test.ts +66 -0
- package/src/component/imports/dedupe.ts +54 -0
- package/src/component/imports/mutations.ts +203 -0
- package/src/component/imports/queries.ts +25 -0
- package/src/component/imports/state.test.ts +60 -0
- package/src/component/imports/state.ts +74 -0
- package/src/component/mutations.ts +96 -0
- package/src/component/providers/actions.ts +127 -0
- package/src/component/providers/apple/impl.test.ts +267 -0
- package/src/component/providers/apple/impl.ts +224 -0
- package/src/component/providers/apple/jwt.test.ts +153 -0
- package/src/component/providers/apple/jwt.ts +99 -0
- package/src/component/providers/apple/mappers.test.ts +190 -0
- package/src/component/providers/apple/mappers.ts +100 -0
- package/src/component/providers/apple/types.ts +77 -0
- package/src/component/providers/deezer/impl.test.ts +109 -0
- package/src/component/providers/deezer/impl.ts +179 -0
- package/src/component/providers/deezer/mappers.test.ts +78 -0
- package/src/component/providers/deezer/mappers.ts +72 -0
- package/src/component/providers/deezer/types.ts +59 -0
- package/src/component/providers/fetch.test.ts +282 -0
- package/src/component/providers/fetch.ts +190 -0
- package/src/component/providers/musicbrainz/impl.test.ts +79 -0
- package/src/component/providers/musicbrainz/impl.ts +132 -0
- package/src/component/providers/musicbrainz/mappers.test.ts +75 -0
- package/src/component/providers/musicbrainz/mappers.ts +34 -0
- package/src/component/providers/musicbrainz/types.ts +20 -0
- package/src/component/providers/registry.test.ts +14 -0
- package/src/component/providers/registry.ts +48 -0
- package/src/component/providers/spotify/client.test.ts +80 -0
- package/src/component/providers/spotify/client.ts +57 -0
- package/src/component/providers/spotify/impl.test.ts +311 -0
- package/src/component/providers/spotify/impl.ts +230 -0
- package/src/component/providers/spotify/mappers.test.ts +182 -0
- package/src/component/providers/spotify/mappers.ts +81 -0
- package/src/component/providers/spotify/types.ts +101 -0
- package/src/component/providers/types.ts +95 -0
- package/src/component/providers/wikidata/impl.test.ts +81 -0
- package/src/component/providers/wikidata/impl.ts +139 -0
- package/src/component/providers/wikidata/mappers.test.ts +62 -0
- package/src/component/providers/wikidata/mappers.ts +66 -0
- package/src/component/providers/wikidata/types.ts +28 -0
- package/src/component/queries.ts +51 -0
- package/src/component/schema.ts +81 -0
- package/src/component/sources/actions.ts +177 -0
- package/src/component/sources/mutations.ts +67 -0
- package/src/component/sources/queries.ts +21 -0
- package/src/component/sync/lifecycle.test.ts +72 -0
- package/src/component/sync/lifecycle.ts +121 -0
- package/src/component/sync/mutations.ts +154 -0
- package/src/component/sync/queries.ts +33 -0
- package/src/component/validators.ts +411 -0
- package/src/react/index.test.ts +78 -0
- package/src/react/index.ts +112 -0
- package/src/shared.ts +32 -0
- package/src/test.ts +22 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { defineSchema, defineTable } from "convex/server";
|
|
2
|
+
import { albumFields, artistFields, artistProviderLinkFields, cacheEntryFields, importRequestFields, playlistFields, providerConfigFields, sourceFields, trackClaimFields, trackFields, trackProviderLinkFields, } from "./validators.js";
|
|
3
|
+
/**
|
|
4
|
+
* Sandboxed tables — the component's own concern only. Two layers:
|
|
5
|
+
* - `cacheEntries`: the raw provider-fetch cache (one provider's normalized facts
|
|
6
|
+
* per entity, TTL'd, keyed by provider id + ISRC for tracks).
|
|
7
|
+
* - `artists` / `tracks` / `playlists` / `albums`: the durable catalog — one
|
|
8
|
+
* unified canonical entity per identity (track by ISRC, artist by name,
|
|
9
|
+
* playlist + album by source-provider id) with per-provider `providers[]`
|
|
10
|
+
* provenance (artists/tracks) + sync/repair lifecycle columns. `*Providers` are
|
|
11
|
+
* reverse indexes (`(provider, providerId)` → row) since Convex can't index
|
|
12
|
+
* inside arrays. `trackClaims` guards concurrent track syncs.
|
|
13
|
+
*
|
|
14
|
+
* The component never reaches the host's tables; the host keeps gameplay +
|
|
15
|
+
* editorial, referencing catalog rows by id / ISRC.
|
|
16
|
+
*/
|
|
17
|
+
export default defineSchema({
|
|
18
|
+
cacheEntries: defineTable(cacheEntryFields)
|
|
19
|
+
.index("by_lookup", ["kind", "provider", "externalId"])
|
|
20
|
+
.index("by_isrc", ["kind", "isrc"])
|
|
21
|
+
.index("by_expiry", ["expiresAt"]),
|
|
22
|
+
artists: defineTable(artistFields)
|
|
23
|
+
.index("by_name_key", ["nameKey"])
|
|
24
|
+
.index("by_sync", ["syncStatus", "nextSyncAt"])
|
|
25
|
+
.index("by_next_sync", ["nextSyncAt"])
|
|
26
|
+
.index("by_repair", ["repairStatus"])
|
|
27
|
+
.searchIndex("search_name", { searchField: "name" }),
|
|
28
|
+
tracks: defineTable(trackFields)
|
|
29
|
+
.index("by_isrc", ["isrc"])
|
|
30
|
+
.index("by_sync", ["syncStatus", "nextSyncAt"])
|
|
31
|
+
.index("by_next_sync", ["nextSyncAt"])
|
|
32
|
+
.index("by_repair", ["repairStatus"])
|
|
33
|
+
.searchIndex("search_title", { searchField: "title" }),
|
|
34
|
+
playlists: defineTable(playlistFields)
|
|
35
|
+
.index("by_provider", ["provider", "providerId"])
|
|
36
|
+
.index("by_sync", ["syncStatus", "nextSyncAt"]),
|
|
37
|
+
albums: defineTable(albumFields)
|
|
38
|
+
.index("by_provider", ["provider", "providerId"])
|
|
39
|
+
.index("by_sync", ["syncStatus", "nextSyncAt"]),
|
|
40
|
+
artistProviders: defineTable(artistProviderLinkFields)
|
|
41
|
+
.index("by_provider_id", ["provider", "providerId"])
|
|
42
|
+
.index("by_artist", ["artistId"]),
|
|
43
|
+
trackProviders: defineTable(trackProviderLinkFields)
|
|
44
|
+
.index("by_provider_id", ["provider", "providerId"])
|
|
45
|
+
.index("by_track", ["trackId"]),
|
|
46
|
+
trackClaims: defineTable(trackClaimFields)
|
|
47
|
+
.index("by_isrc", ["isrc"])
|
|
48
|
+
.index("by_lease", ["leaseUntil"]),
|
|
49
|
+
providerConfig: defineTable(providerConfigFields).index("by_provider", [
|
|
50
|
+
"provider",
|
|
51
|
+
]),
|
|
52
|
+
importRequests: defineTable(importRequestFields)
|
|
53
|
+
.index("by_status", ["status", "requestedAt"])
|
|
54
|
+
.index("by_dedupe_status", ["dedupeKey", "status"]),
|
|
55
|
+
sources: defineTable(sourceFields)
|
|
56
|
+
.index("by_enabled", ["enabled", "lastImportedAt"])
|
|
57
|
+
.index("by_kind", ["kind"]),
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=schema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AE,WAAW,CAAC,YAAY,CAAC;SAC/B,KAAK,CAAC,YAAY,EAAE,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;SAClD,KAAK,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,CAAC;CAC9B,CAAC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-import sweep. Imports the **due** enabled sources (never imported, or past
|
|
3
|
+
* their cadence) via the matching import entry point, bounded per run, stamping
|
|
4
|
+
* each source's `lastImportedAt`. Opt-in by construction: no enabled sources →
|
|
5
|
+
* no-op. (The rate-limiter throughput budget + stale-row refresh are follow-ups;
|
|
6
|
+
* this is the new-source pull.)
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Auto-import throughput budgets — token buckets decoupled from cron frequency,
|
|
10
|
+
* separate for new-source import vs stale-row refresh. Default 60/hour each.
|
|
11
|
+
*/
|
|
12
|
+
export declare const AUTO_IMPORT_RATE_PER_HOUR = 60;
|
|
13
|
+
/**
|
|
14
|
+
* Run the refresh sweep: re-import up to `limit` stale catalog rows of a kind
|
|
15
|
+
* from each provider already on their record (mode `refresh`), bringing them
|
|
16
|
+
* back to `synced`. The freshness mechanism `markStale` flips rows to `stale`;
|
|
17
|
+
* this re-syncs them. Opt-in by construction (no stale rows → no-op).
|
|
18
|
+
*
|
|
19
|
+
* `refreshed` counts rows claimed + dispatched, not necessarily re-synced: a row
|
|
20
|
+
* whose providers all fail stays `running` (the imports record their own failure
|
|
21
|
+
* but don't throw) until `recoverStuckSyncs` salvages it back to `stale` after the
|
|
22
|
+
* lease — the lease doubles as the retry backoff. A persistently-failing row thus
|
|
23
|
+
* retries slowly (lease-paced, rate-limited), never hot-loops.
|
|
24
|
+
*/
|
|
25
|
+
export declare const runRefresh: import("convex/server").RegisteredAction<"public", {
|
|
26
|
+
kind: "artist" | "track";
|
|
27
|
+
limit?: number | undefined;
|
|
28
|
+
}, Promise<{
|
|
29
|
+
refreshed: number;
|
|
30
|
+
}>>;
|
|
31
|
+
/**
|
|
32
|
+
* Run the auto-import sweep: import up to `limit` due enabled sources, stamping
|
|
33
|
+
* each. Sources with no provider are skipped. Returns `{ imported, skipped }`.
|
|
34
|
+
*/
|
|
35
|
+
export declare const runAutoImport: import("convex/server").RegisteredAction<"public", {
|
|
36
|
+
limit?: number | undefined;
|
|
37
|
+
now?: number | undefined;
|
|
38
|
+
}, Promise<{
|
|
39
|
+
imported: number;
|
|
40
|
+
skipped: number;
|
|
41
|
+
}>>;
|
|
42
|
+
/**
|
|
43
|
+
* Consume `count` tokens from a named throughput budget (`autoImport` or
|
|
44
|
+
* `refresh`) — for host-side pacing (reserve budget before a manual burst).
|
|
45
|
+
* Returns whether the budget allowed it.
|
|
46
|
+
*/
|
|
47
|
+
export declare const consumeBudget: import("convex/server").RegisteredAction<"public", {
|
|
48
|
+
budget: "autoImport" | "refresh";
|
|
49
|
+
count: number;
|
|
50
|
+
}, Promise<boolean>>;
|
|
51
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/component/sources/actions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AASH;;;GAGG;AACH,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAwC5C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU;;;;eAM4B,MAAM;GA2CvD,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,aAAa;;;;cAGwB,MAAM;aAAW,MAAM;GA4BvE,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;oBAYxB,CAAC"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-import sweep. Imports the **due** enabled sources (never imported, or past
|
|
3
|
+
* their cadence) via the matching import entry point, bounded per run, stamping
|
|
4
|
+
* each source's `lastImportedAt`. Opt-in by construction: no enabled sources →
|
|
5
|
+
* no-op. (The rate-limiter throughput budget + stale-row refresh are follow-ups;
|
|
6
|
+
* this is the new-source pull.)
|
|
7
|
+
*/
|
|
8
|
+
import { HOUR, RateLimiter } from "@convex-dev/rate-limiter";
|
|
9
|
+
import { v } from "convex/values";
|
|
10
|
+
import { api, components } from "../_generated/api.js";
|
|
11
|
+
import { action } from "../_generated/server.js";
|
|
12
|
+
/**
|
|
13
|
+
* Auto-import throughput budgets — token buckets decoupled from cron frequency,
|
|
14
|
+
* separate for new-source import vs stale-row refresh. Default 60/hour each.
|
|
15
|
+
*/
|
|
16
|
+
export const AUTO_IMPORT_RATE_PER_HOUR = 60;
|
|
17
|
+
const rateLimiter = new RateLimiter(components.rateLimiter, {
|
|
18
|
+
autoImport: { kind: "token bucket", rate: AUTO_IMPORT_RATE_PER_HOUR, period: HOUR },
|
|
19
|
+
refresh: { kind: "token bucket", rate: AUTO_IMPORT_RATE_PER_HOUR, period: HOUR },
|
|
20
|
+
});
|
|
21
|
+
/** Whether a source is due: never imported, or past its cadence (one-shot if no cadence). */
|
|
22
|
+
function isDue(source, now) {
|
|
23
|
+
if (source.lastImportedAt === undefined)
|
|
24
|
+
return true;
|
|
25
|
+
if (source.cadenceMs === undefined)
|
|
26
|
+
return false;
|
|
27
|
+
return now - source.lastImportedAt > source.cadenceMs;
|
|
28
|
+
}
|
|
29
|
+
/** Dispatch a source to its import entry point. */
|
|
30
|
+
async function importSource(ctx, source, prov) {
|
|
31
|
+
if (source.kind === "artist") {
|
|
32
|
+
await ctx.runAction(api.imports.actions.importArtist, {
|
|
33
|
+
provider: prov,
|
|
34
|
+
targetMode: source.by === "name" ? "name" : "providerId",
|
|
35
|
+
name: source.by === "name" ? source.value : undefined,
|
|
36
|
+
providerId: source.by === "name" ? undefined : source.value,
|
|
37
|
+
withTracks: source.withTracks,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
else if (source.kind === "track") {
|
|
41
|
+
await ctx.runAction(api.imports.actions.importTrack, {
|
|
42
|
+
provider: prov,
|
|
43
|
+
providerId: source.value,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
await ctx.runAction(api.imports.actions.importPlaylist, {
|
|
48
|
+
provider: prov,
|
|
49
|
+
providerId: source.value,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Run the refresh sweep: re-import up to `limit` stale catalog rows of a kind
|
|
55
|
+
* from each provider already on their record (mode `refresh`), bringing them
|
|
56
|
+
* back to `synced`. The freshness mechanism `markStale` flips rows to `stale`;
|
|
57
|
+
* this re-syncs them. Opt-in by construction (no stale rows → no-op).
|
|
58
|
+
*
|
|
59
|
+
* `refreshed` counts rows claimed + dispatched, not necessarily re-synced: a row
|
|
60
|
+
* whose providers all fail stays `running` (the imports record their own failure
|
|
61
|
+
* but don't throw) until `recoverStuckSyncs` salvages it back to `stale` after the
|
|
62
|
+
* lease — the lease doubles as the retry backoff. A persistently-failing row thus
|
|
63
|
+
* retries slowly (lease-paced, rate-limited), never hot-loops.
|
|
64
|
+
*/
|
|
65
|
+
export const runRefresh = action({
|
|
66
|
+
args: {
|
|
67
|
+
kind: v.union(v.literal("artist"), v.literal("track")),
|
|
68
|
+
limit: v.optional(v.number()),
|
|
69
|
+
},
|
|
70
|
+
returns: v.object({ refreshed: v.number() }),
|
|
71
|
+
handler: async (ctx, args) => {
|
|
72
|
+
const limit = args.limit ?? 10;
|
|
73
|
+
let refreshed = 0;
|
|
74
|
+
for (let i = 0; i < limit; i++) {
|
|
75
|
+
// Separate refresh budget (distinct from the new-source import budget).
|
|
76
|
+
const { ok } = await rateLimiter.limit(ctx, "refresh");
|
|
77
|
+
if (!ok)
|
|
78
|
+
break;
|
|
79
|
+
// Atomically claim the next stale row as `running` in one mutation, so two
|
|
80
|
+
// overlapping sweeps can't both refresh it. `null` => nothing left stale.
|
|
81
|
+
// The re-import's upsert returns it to `synced`; `recoverStuckSyncs`
|
|
82
|
+
// salvages a lease whose holder crashed.
|
|
83
|
+
const row = await ctx.runMutation(api.sync.mutations.claimNextStale, {
|
|
84
|
+
kind: args.kind,
|
|
85
|
+
});
|
|
86
|
+
if (row === null)
|
|
87
|
+
break;
|
|
88
|
+
const providers = row.providers;
|
|
89
|
+
if (args.kind === "artist") {
|
|
90
|
+
await Promise.all(providers.map((prov) => ctx.runAction(api.imports.actions.importArtist, {
|
|
91
|
+
provider: prov.provider,
|
|
92
|
+
targetMode: "providerId",
|
|
93
|
+
providerId: prov.providerId,
|
|
94
|
+
mode: "refresh",
|
|
95
|
+
})));
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
await Promise.all(providers.map((prov) => ctx.runAction(api.imports.actions.importTrack, {
|
|
99
|
+
provider: prov.provider,
|
|
100
|
+
providerId: prov.providerId,
|
|
101
|
+
mode: "refresh",
|
|
102
|
+
})));
|
|
103
|
+
}
|
|
104
|
+
refreshed += 1;
|
|
105
|
+
}
|
|
106
|
+
return { refreshed };
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
/**
|
|
110
|
+
* Run the auto-import sweep: import up to `limit` due enabled sources, stamping
|
|
111
|
+
* each. Sources with no provider are skipped. Returns `{ imported, skipped }`.
|
|
112
|
+
*/
|
|
113
|
+
export const runAutoImport = action({
|
|
114
|
+
args: { limit: v.optional(v.number()), now: v.optional(v.number()) },
|
|
115
|
+
returns: v.object({ imported: v.number(), skipped: v.number() }),
|
|
116
|
+
handler: async (ctx, args) => {
|
|
117
|
+
const now = args.now ?? Date.now();
|
|
118
|
+
const limit = args.limit ?? 10;
|
|
119
|
+
const sources = await ctx.runQuery(api.sources.queries.listSources, {
|
|
120
|
+
enabledOnly: true,
|
|
121
|
+
limit: 100,
|
|
122
|
+
});
|
|
123
|
+
const due = sources.filter((source) => isDue(source, now)).slice(0, limit);
|
|
124
|
+
let imported = 0;
|
|
125
|
+
let skipped = 0;
|
|
126
|
+
for (const source of due) {
|
|
127
|
+
if (source.provider === undefined) {
|
|
128
|
+
skipped += 1;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
// Throughput budget: stop the sweep when the token bucket is drained
|
|
132
|
+
// (decoupled from how often the cron fires).
|
|
133
|
+
const { ok } = await rateLimiter.limit(ctx, "autoImport");
|
|
134
|
+
if (!ok)
|
|
135
|
+
break;
|
|
136
|
+
await importSource(ctx, source, source.provider);
|
|
137
|
+
await ctx.runMutation(api.sources.mutations.touchSource, {
|
|
138
|
+
sourceId: source._id,
|
|
139
|
+
now,
|
|
140
|
+
});
|
|
141
|
+
imported += 1;
|
|
142
|
+
}
|
|
143
|
+
return { imported, skipped };
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
/**
|
|
147
|
+
* Consume `count` tokens from a named throughput budget (`autoImport` or
|
|
148
|
+
* `refresh`) — for host-side pacing (reserve budget before a manual burst).
|
|
149
|
+
* Returns whether the budget allowed it.
|
|
150
|
+
*/
|
|
151
|
+
export const consumeBudget = action({
|
|
152
|
+
args: {
|
|
153
|
+
budget: v.union(v.literal("autoImport"), v.literal("refresh")),
|
|
154
|
+
count: v.number(),
|
|
155
|
+
},
|
|
156
|
+
returns: v.boolean(),
|
|
157
|
+
handler: async (ctx, args) => {
|
|
158
|
+
const { ok } = await rateLimiter.limit(ctx, args.budget, {
|
|
159
|
+
count: args.count,
|
|
160
|
+
});
|
|
161
|
+
return ok;
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../../src/component/sources/actions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAkB,MAAM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CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;YACjD,MAAM,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE;gBACvD,QAAQ,EAAE,MAAM,CAAC,GAAG;gBACpB,GAAG;aACJ,CAAC,CAAC;YACH,QAAQ,IAAI,CAAC,CAAC;QAChB,CAAC;QACD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;IAC/B,CAAC;CACF,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC;IAClC,IAAI,EAAE;QACJ,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC9D,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;KAClB;IACD,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE;IACpB,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAoB,EAAE;QAC7C,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE;YACvD,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAC,CAAC;QACH,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Register an import source the engine keeps synced. Enabled by default. */
|
|
2
|
+
export declare const addSource: import("convex/server").RegisteredMutation<"public", {
|
|
3
|
+
by: "entityId" | "isrc" | "name" | "providerId" | "url";
|
|
4
|
+
cadenceMs?: number | undefined;
|
|
5
|
+
enabled?: boolean | undefined;
|
|
6
|
+
kind: "album" | "artist" | "playlist" | "track";
|
|
7
|
+
provider?: "apple" | "deezer" | "musicbrainz" | "spotify" | "wikidata" | undefined;
|
|
8
|
+
value: string;
|
|
9
|
+
withTracks?: boolean | undefined;
|
|
10
|
+
}, Promise<import("convex/values").GenericId<"sources">>>;
|
|
11
|
+
/** Remove a registered source. */
|
|
12
|
+
export declare const removeSource: import("convex/server").RegisteredMutation<"public", {
|
|
13
|
+
sourceId: import("convex/values").GenericId<"sources">;
|
|
14
|
+
}, Promise<null>>;
|
|
15
|
+
/** Enable or disable a source (disabled sources are skipped by the sweep). */
|
|
16
|
+
export declare const setSourceEnabled: import("convex/server").RegisteredMutation<"public", {
|
|
17
|
+
enabled: boolean;
|
|
18
|
+
sourceId: import("convex/values").GenericId<"sources">;
|
|
19
|
+
}, Promise<null>>;
|
|
20
|
+
/** Stamp a source's `lastImportedAt` after the sweep imports it. */
|
|
21
|
+
export declare const touchSource: import("convex/server").RegisteredMutation<"public", {
|
|
22
|
+
now: number;
|
|
23
|
+
sourceId: import("convex/values").GenericId<"sources">;
|
|
24
|
+
}, Promise<null>>;
|
|
25
|
+
//# sourceMappingURL=mutations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../../src/component/sources/mutations.ts"],"names":[],"mappings":"AAIA,6EAA6E;AAC7E,eAAO,MAAM,SAAS;;;;;;;;yDAyBpB,CAAC;AAEH,kCAAkC;AAClC,eAAO,MAAM,YAAY;;iBAOvB,CAAC;AAEH,8EAA8E;AAC9E,eAAO,MAAM,gBAAgB;;;iBAU3B,CAAC;AAEH,oEAAoE;AACpE,eAAO,MAAM,WAAW;;;iBAUtB,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { mutation } from "../_generated/server.js";
|
|
3
|
+
import { importEntityType, importTargetMode, provider } from "../validators.js";
|
|
4
|
+
/** Register an import source the engine keeps synced. Enabled by default. */
|
|
5
|
+
export const addSource = mutation({
|
|
6
|
+
args: {
|
|
7
|
+
kind: importEntityType,
|
|
8
|
+
by: importTargetMode,
|
|
9
|
+
value: v.string(),
|
|
10
|
+
provider: v.optional(provider),
|
|
11
|
+
withTracks: v.optional(v.boolean()),
|
|
12
|
+
cadenceMs: v.optional(v.number()),
|
|
13
|
+
enabled: v.optional(v.boolean()),
|
|
14
|
+
},
|
|
15
|
+
returns: v.id("sources"),
|
|
16
|
+
handler: async (ctx, args) => {
|
|
17
|
+
const now = Date.now();
|
|
18
|
+
return await ctx.db.insert("sources", {
|
|
19
|
+
kind: args.kind,
|
|
20
|
+
by: args.by,
|
|
21
|
+
value: args.value,
|
|
22
|
+
provider: args.provider,
|
|
23
|
+
withTracks: args.withTracks,
|
|
24
|
+
cadenceMs: args.cadenceMs,
|
|
25
|
+
enabled: args.enabled ?? true,
|
|
26
|
+
createdAt: now,
|
|
27
|
+
updatedAt: now,
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
/** Remove a registered source. */
|
|
32
|
+
export const removeSource = mutation({
|
|
33
|
+
args: { sourceId: v.id("sources") },
|
|
34
|
+
returns: v.null(),
|
|
35
|
+
handler: async (ctx, args) => {
|
|
36
|
+
await ctx.db.delete("sources", args.sourceId);
|
|
37
|
+
return null;
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
/** Enable or disable a source (disabled sources are skipped by the sweep). */
|
|
41
|
+
export const setSourceEnabled = mutation({
|
|
42
|
+
args: { sourceId: v.id("sources"), enabled: v.boolean() },
|
|
43
|
+
returns: v.null(),
|
|
44
|
+
handler: async (ctx, args) => {
|
|
45
|
+
await ctx.db.patch("sources", args.sourceId, {
|
|
46
|
+
enabled: args.enabled,
|
|
47
|
+
updatedAt: Date.now(),
|
|
48
|
+
});
|
|
49
|
+
return null;
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
/** Stamp a source's `lastImportedAt` after the sweep imports it. */
|
|
53
|
+
export const touchSource = mutation({
|
|
54
|
+
args: { sourceId: v.id("sources"), now: v.number() },
|
|
55
|
+
returns: v.null(),
|
|
56
|
+
handler: async (ctx, args) => {
|
|
57
|
+
await ctx.db.patch("sources", args.sourceId, {
|
|
58
|
+
lastImportedAt: args.now,
|
|
59
|
+
updatedAt: args.now,
|
|
60
|
+
});
|
|
61
|
+
return null;
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
//# sourceMappingURL=mutations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutations.js","sourceRoot":"","sources":["../../../src/component/sources/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEhF,6EAA6E;AAC7E,MAAM,CAAC,MAAM,SAAS,GAAG,QAAQ,CAAC;IAChC,IAAI,EAAE;QACJ,IAAI,EAAE,gBAAgB;QACtB,EAAE,EAAE,gBAAgB;QACpB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;QACjB,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC9B,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACnC,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QACjC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;KACjC;IACD,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC;IACxB,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,OAAO,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE;YACpC,IAAI,EAAE,IAAI,CAAC,IAAI;YAC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AAC;AAEH,oEAAoE;AACpE,MAAM,CAAC,MAAM,WAAW,GAAG,QAAQ,CAAC;IAClC,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE;IACpD,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE;IACjB,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC3B,MAAM,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE;YAC3C,cAAc,EAAE,IAAI,CAAC,GAAG;YACxB,SAAS,EAAE,IAAI,CAAC,GAAG;SACpB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** List registered sources — all, or only enabled ones. */
|
|
2
|
+
export declare const listSources: import("convex/server").RegisteredQuery<"public", {
|
|
3
|
+
enabledOnly?: boolean | undefined;
|
|
4
|
+
limit?: number | undefined;
|
|
5
|
+
}, Promise<{
|
|
6
|
+
_creationTime: number;
|
|
7
|
+
_id: import("convex/values").GenericId<"sources">;
|
|
8
|
+
by: "entityId" | "isrc" | "name" | "providerId" | "url";
|
|
9
|
+
cadenceMs?: number | undefined;
|
|
10
|
+
createdAt: number;
|
|
11
|
+
enabled: boolean;
|
|
12
|
+
kind: "album" | "artist" | "playlist" | "track";
|
|
13
|
+
lastImportedAt?: number | undefined;
|
|
14
|
+
provider?: "apple" | "deezer" | "musicbrainz" | "spotify" | "wikidata" | undefined;
|
|
15
|
+
updatedAt: number;
|
|
16
|
+
value: string;
|
|
17
|
+
withTracks?: boolean | undefined;
|
|
18
|
+
}[]>>;
|
|
19
|
+
//# sourceMappingURL=queries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../../src/component/sources/queries.ts"],"names":[],"mappings":"AAOA,2DAA2D;AAC3D,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;KAYtB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { query } from "../_generated/server.js";
|
|
3
|
+
import { sourceDoc } from "../validators.js";
|
|
4
|
+
/** Default page size for a source listing. */
|
|
5
|
+
const DEFAULT_LIMIT = 100;
|
|
6
|
+
/** List registered sources — all, or only enabled ones. */
|
|
7
|
+
export const listSources = query({
|
|
8
|
+
args: { enabledOnly: v.optional(v.boolean()), limit: v.optional(v.number()) },
|
|
9
|
+
returns: v.array(sourceDoc),
|
|
10
|
+
handler: async (ctx, args) => {
|
|
11
|
+
if (args.enabledOnly === true) {
|
|
12
|
+
return await ctx.db
|
|
13
|
+
.query("sources")
|
|
14
|
+
.withIndex("by_enabled", (q) => q.eq("enabled", true))
|
|
15
|
+
.take(args.limit ?? DEFAULT_LIMIT);
|
|
16
|
+
}
|
|
17
|
+
return await ctx.db.query("sources").take(args.limit ?? DEFAULT_LIMIT);
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/component/sources/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,8CAA8C;AAC9C,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B,2DAA2D;AAC3D,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC;IAC/B,IAAI,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE;IAC7E,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC;IAC3B,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC3B,IAAI,IAAI,CAAC,WAAW,KAAK,IAAI,EAAE,CAAC;YAC9B,OAAO,MAAM,GAAG,CAAC,EAAE;iBAChB,KAAK,CAAC,SAAS,CAAC;iBAChB,SAAS,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;iBACrD,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,aAAa,CAAC,CAAC;QACvC,CAAC;QACD,OAAO,MAAM,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,aAAa,CAAC,CAAC;IACzE,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sync + repair lifecycle logic for catalog rows (songtrivia's sync-status /
|
|
3
|
+
* repair machines, generalized). Pure transition + scheduling logic; the
|
|
4
|
+
* mutations + crons enforce it on the rows. Two machines:
|
|
5
|
+
* - sync-status: `pending → running → synced | failed → stale` (freshness).
|
|
6
|
+
* - repair-status: `clean → needs_repair → repairing → clean | failed_repair`.
|
|
7
|
+
*/
|
|
8
|
+
/** Freshness-sync states of a catalog row. */
|
|
9
|
+
export type SyncStatus = "pending" | "running" | "synced" | "failed" | "stale";
|
|
10
|
+
/** Data-quality repair states of a catalog row. */
|
|
11
|
+
export type RepairStatus = "clean" | "needs_repair" | "repairing" | "failed_repair";
|
|
12
|
+
/** Whether `from → to` is a legal sync transition. */
|
|
13
|
+
export declare function canSyncTransition(from: SyncStatus, to: SyncStatus): boolean;
|
|
14
|
+
/** Assert a legal sync transition. */
|
|
15
|
+
export declare function assertSyncTransition(from: SyncStatus, to: SyncStatus): void;
|
|
16
|
+
/** Whether `from → to` is a legal repair transition. */
|
|
17
|
+
export declare function canRepairTransition(from: RepairStatus, to: RepairStatus): boolean;
|
|
18
|
+
/** Assert a legal repair transition. */
|
|
19
|
+
export declare function assertRepairTransition(from: RepairStatus, to: RepairStatus): void;
|
|
20
|
+
/** Entity sync retry backoff: `[1h, 6h, 24h]` then `stale`. */
|
|
21
|
+
export declare const SYNC_RETRY_DELAYS_MS: readonly number[];
|
|
22
|
+
/** Max entity sync retries before `stale`. */
|
|
23
|
+
export declare const MAX_SYNC_RETRIES = 3;
|
|
24
|
+
/** Max repair attempts before `failed_repair`. */
|
|
25
|
+
export declare const MAX_REPAIR_ATTEMPTS = 3;
|
|
26
|
+
/** Backoff before the next sync retry (last value past the end). */
|
|
27
|
+
export declare function syncRetryDelayMs(retryCount: number): number;
|
|
28
|
+
/** Whether another sync retry is within budget. */
|
|
29
|
+
export declare function shouldSyncRetry(retryCount: number): boolean;
|
|
30
|
+
/** Staleness windows by popularity tier (songtrivia defaults). */
|
|
31
|
+
export declare const STALENESS_MS: {
|
|
32
|
+
readonly high: number;
|
|
33
|
+
readonly medium: number;
|
|
34
|
+
readonly low: number;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The freshness window for an entity by popularity: HIGH (≥70) = 7d, MEDIUM
|
|
38
|
+
* (≥40) = 30d, LOW (or unknown) = 90d. Volatile-popular rows refresh faster.
|
|
39
|
+
*/
|
|
40
|
+
export declare function stalenessWindowMs(popularity: number | undefined): number;
|
|
41
|
+
/**
|
|
42
|
+
* Whether a row is past its freshness window. A row never synced (no
|
|
43
|
+
* `lastSyncedAt`) is stale.
|
|
44
|
+
*/
|
|
45
|
+
export declare function isStale(lastSyncedAt: number | undefined, popularity: number | undefined, now: number): boolean;
|
|
46
|
+
//# sourceMappingURL=lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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,OAAO,CACrB,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,GAAG,EAAE,MAAM,GACV,OAAO,CAGT"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sync + repair lifecycle logic for catalog rows (songtrivia's sync-status /
|
|
3
|
+
* repair machines, generalized). Pure transition + scheduling logic; the
|
|
4
|
+
* mutations + crons enforce it on the rows. Two machines:
|
|
5
|
+
* - sync-status: `pending → running → synced | failed → stale` (freshness).
|
|
6
|
+
* - repair-status: `clean → needs_repair → repairing → clean | failed_repair`.
|
|
7
|
+
*/
|
|
8
|
+
const SYNC_TRANSITIONS = {
|
|
9
|
+
pending: ["running", "synced", "failed"],
|
|
10
|
+
running: ["synced", "failed", "stale"],
|
|
11
|
+
synced: ["stale"],
|
|
12
|
+
failed: ["running", "synced", "failed", "stale"],
|
|
13
|
+
stale: ["running", "synced"],
|
|
14
|
+
};
|
|
15
|
+
const REPAIR_TRANSITIONS = {
|
|
16
|
+
clean: ["needs_repair"],
|
|
17
|
+
needs_repair: ["repairing"],
|
|
18
|
+
repairing: ["clean", "needs_repair", "failed_repair"],
|
|
19
|
+
failed_repair: [],
|
|
20
|
+
};
|
|
21
|
+
/** Whether `from → to` is a legal sync transition. */
|
|
22
|
+
export function canSyncTransition(from, to) {
|
|
23
|
+
return SYNC_TRANSITIONS[from].includes(to);
|
|
24
|
+
}
|
|
25
|
+
/** Assert a legal sync transition. */
|
|
26
|
+
export function assertSyncTransition(from, to) {
|
|
27
|
+
if (!canSyncTransition(from, to)) {
|
|
28
|
+
throw new Error(`Invalid sync transition: ${from} -> ${to}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Whether `from → to` is a legal repair transition. */
|
|
32
|
+
export function canRepairTransition(from, to) {
|
|
33
|
+
return REPAIR_TRANSITIONS[from].includes(to);
|
|
34
|
+
}
|
|
35
|
+
/** Assert a legal repair transition. */
|
|
36
|
+
export function assertRepairTransition(from, to) {
|
|
37
|
+
if (!canRepairTransition(from, to)) {
|
|
38
|
+
throw new Error(`Invalid repair transition: ${from} -> ${to}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Entity sync retry backoff: `[1h, 6h, 24h]` then `stale`. */
|
|
42
|
+
export const SYNC_RETRY_DELAYS_MS = [
|
|
43
|
+
60 * 60 * 1000,
|
|
44
|
+
6 * 60 * 60 * 1000,
|
|
45
|
+
24 * 60 * 60 * 1000,
|
|
46
|
+
];
|
|
47
|
+
/** Max entity sync retries before `stale`. */
|
|
48
|
+
export const MAX_SYNC_RETRIES = 3;
|
|
49
|
+
/** Max repair attempts before `failed_repair`. */
|
|
50
|
+
export const MAX_REPAIR_ATTEMPTS = 3;
|
|
51
|
+
/** Backoff before the next sync retry (last value past the end). */
|
|
52
|
+
export function syncRetryDelayMs(retryCount) {
|
|
53
|
+
return SYNC_RETRY_DELAYS_MS[retryCount] ?? 24 * 60 * 60 * 1000;
|
|
54
|
+
}
|
|
55
|
+
/** Whether another sync retry is within budget. */
|
|
56
|
+
export function shouldSyncRetry(retryCount) {
|
|
57
|
+
return retryCount < MAX_SYNC_RETRIES;
|
|
58
|
+
}
|
|
59
|
+
/** Staleness windows by popularity tier (songtrivia defaults). */
|
|
60
|
+
export const STALENESS_MS = {
|
|
61
|
+
high: 7 * 24 * 60 * 60 * 1000,
|
|
62
|
+
medium: 30 * 24 * 60 * 60 * 1000,
|
|
63
|
+
low: 90 * 24 * 60 * 60 * 1000,
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* The freshness window for an entity by popularity: HIGH (≥70) = 7d, MEDIUM
|
|
67
|
+
* (≥40) = 30d, LOW (or unknown) = 90d. Volatile-popular rows refresh faster.
|
|
68
|
+
*/
|
|
69
|
+
export function stalenessWindowMs(popularity) {
|
|
70
|
+
if (popularity === undefined)
|
|
71
|
+
return STALENESS_MS.low;
|
|
72
|
+
if (popularity >= 70)
|
|
73
|
+
return STALENESS_MS.high;
|
|
74
|
+
if (popularity >= 40)
|
|
75
|
+
return STALENESS_MS.medium;
|
|
76
|
+
return STALENESS_MS.low;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Whether a row is past its freshness window. A row never synced (no
|
|
80
|
+
* `lastSyncedAt`) is stale.
|
|
81
|
+
*/
|
|
82
|
+
export function isStale(lastSyncedAt, popularity, now) {
|
|
83
|
+
if (lastSyncedAt === undefined)
|
|
84
|
+
return true;
|
|
85
|
+
return now - lastSyncedAt > stalenessWindowMs(popularity);
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../../src/component/sync/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAiBH,MAAM,gBAAgB,GAA8C;IAClE,OAAO,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC;IACxC,OAAO,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC;IACtC,MAAM,EAAE,CAAC,OAAO,CAAC;IACjB,MAAM,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC;IAChD,KAAK,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC;CAC7B,CAAC;AAEF,MAAM,kBAAkB,GAAkD;IACxE,KAAK,EAAE,CAAC,cAAc,CAAC;IACvB,YAAY,EAAE,CAAC,WAAW,CAAC;IAC3B,SAAS,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,eAAe,CAAC;IACrD,aAAa,EAAE,EAAE;CAClB,CAAC;AAEF,sDAAsD;AACtD,MAAM,UAAU,iBAAiB,CAAC,IAAgB,EAAE,EAAc;IAChE,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAC7C,CAAC;AAED,sCAAsC;AACtC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