@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,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flip past-freshness-window catalog rows from `synced` to `stale` for a kind.
|
|
3
|
+
* The freshness window scales by popularity (volatile-popular rows go stale
|
|
4
|
+
* sooner). Returns how many were newly marked. The auto-import sweep re-syncs
|
|
5
|
+
* stale rows; this is the detection half. Idempotent + bounded; mount-safe.
|
|
6
|
+
*/
|
|
7
|
+
export declare const markStale: import("convex/server").RegisteredMutation<"public", {
|
|
8
|
+
kind: "artist" | "track";
|
|
9
|
+
limit?: number | undefined;
|
|
10
|
+
now?: number | undefined;
|
|
11
|
+
}, Promise<number>>;
|
|
12
|
+
/**
|
|
13
|
+
* Atomically claim the next `stale` catalog row of a kind for re-sync: find one
|
|
14
|
+
* stale row via the index and flip it to `running` in the SAME transaction. The
|
|
15
|
+
* find + claim are one mutation, so two concurrent refresh sweeps can never both
|
|
16
|
+
* take the same row — Convex serializes the conflicting patch and the loser
|
|
17
|
+
* re-reads (the row is now `running`, no longer `stale`) and moves on. Returns
|
|
18
|
+
* the claimed row (so the caller has its `providers`), or `null` when none are
|
|
19
|
+
* stale. The re-import's upsert returns it to `synced`; `recoverStuckSyncs`
|
|
20
|
+
* salvages a lease whose holder crashed. Replaces a blind patch-by-id, which had
|
|
21
|
+
* no compare-and-set and could double-claim across action/mutation boundaries.
|
|
22
|
+
*/
|
|
23
|
+
export declare const claimNextStale: import("convex/server").RegisteredMutation<"public", {
|
|
24
|
+
kind: "artist" | "track";
|
|
25
|
+
}, Promise<{
|
|
26
|
+
_creationTime: number;
|
|
27
|
+
_id: import("convex/values").GenericId<"artists">;
|
|
28
|
+
country?: string | undefined;
|
|
29
|
+
debutYear?: number | undefined;
|
|
30
|
+
gender?: string | undefined;
|
|
31
|
+
genres: string[];
|
|
32
|
+
imageUrl?: string | undefined;
|
|
33
|
+
lastRepairAt?: number | undefined;
|
|
34
|
+
lastSyncError?: string | undefined;
|
|
35
|
+
lastSyncedAt?: number | undefined;
|
|
36
|
+
members?: "group" | "solo" | undefined;
|
|
37
|
+
name: string;
|
|
38
|
+
nameKey: string;
|
|
39
|
+
nextSyncAt?: number | undefined;
|
|
40
|
+
popularity?: number | undefined;
|
|
41
|
+
providers: {
|
|
42
|
+
genres?: string[] | undefined;
|
|
43
|
+
imageUrl?: string | undefined;
|
|
44
|
+
popularity?: number | undefined;
|
|
45
|
+
provider: "apple" | "deezer" | "musicbrainz" | "spotify" | "wikidata";
|
|
46
|
+
providerId: string;
|
|
47
|
+
url?: string | undefined;
|
|
48
|
+
}[];
|
|
49
|
+
repairAttempts?: number | undefined;
|
|
50
|
+
repairError?: string | undefined;
|
|
51
|
+
repairStartedAt?: number | undefined;
|
|
52
|
+
repairStatus?: "clean" | "failed_repair" | "needs_repair" | "repairing" | undefined;
|
|
53
|
+
syncRetryCount?: number | undefined;
|
|
54
|
+
syncStatus?: "failed" | "pending" | "running" | "stale" | "synced" | undefined;
|
|
55
|
+
updatedAt: number;
|
|
56
|
+
} | {
|
|
57
|
+
_creationTime: number;
|
|
58
|
+
_id: import("convex/values").GenericId<"tracks">;
|
|
59
|
+
artistIds: import("convex/values").GenericId<"artists">[];
|
|
60
|
+
durationMs?: number | undefined;
|
|
61
|
+
genres: string[];
|
|
62
|
+
isrc: string;
|
|
63
|
+
lastRepairAt?: number | undefined;
|
|
64
|
+
lastSyncError?: string | undefined;
|
|
65
|
+
lastSyncedAt?: number | undefined;
|
|
66
|
+
nextSyncAt?: number | undefined;
|
|
67
|
+
popularity?: number | undefined;
|
|
68
|
+
providers: {
|
|
69
|
+
coverUrl?: string | undefined;
|
|
70
|
+
previewUrl?: string | undefined;
|
|
71
|
+
provider: "apple" | "deezer" | "musicbrainz" | "spotify" | "wikidata";
|
|
72
|
+
providerId: string;
|
|
73
|
+
url?: string | undefined;
|
|
74
|
+
}[];
|
|
75
|
+
repairAttempts?: number | undefined;
|
|
76
|
+
repairError?: string | undefined;
|
|
77
|
+
repairStartedAt?: number | undefined;
|
|
78
|
+
repairStatus?: "clean" | "failed_repair" | "needs_repair" | "repairing" | undefined;
|
|
79
|
+
syncRetryCount?: number | undefined;
|
|
80
|
+
syncStatus?: "failed" | "pending" | "running" | "stale" | "synced" | undefined;
|
|
81
|
+
title: string;
|
|
82
|
+
updatedAt: number;
|
|
83
|
+
} | null>>;
|
|
84
|
+
/**
|
|
85
|
+
* Recover rows stuck in `running` past the lease (a re-sync that crashed before
|
|
86
|
+
* completing) by salvaging them back to `stale` for re-pickup. Bounded +
|
|
87
|
+
* idempotent; returns how many were recovered.
|
|
88
|
+
*
|
|
89
|
+
* Stuck = `updatedAt` older than `leaseMs` (default 10 min). A refresh re-syncs a
|
|
90
|
+
* single row (one provider fetch + a few upserts) in seconds, so the lease is far
|
|
91
|
+
* longer than a healthy run; only a genuinely crashed run is reclaimed. If a
|
|
92
|
+
* deployment runs much slower single-row refreshes, raise `leaseMs` above that
|
|
93
|
+
* duration so a still-running sync is never false-positive reclaimed.
|
|
94
|
+
*/
|
|
95
|
+
export declare const recoverStuckSyncs: import("convex/server").RegisteredMutation<"public", {
|
|
96
|
+
kind: "artist" | "track";
|
|
97
|
+
leaseMs?: number | undefined;
|
|
98
|
+
limit?: number | undefined;
|
|
99
|
+
now?: number | undefined;
|
|
100
|
+
}, Promise<number>>;
|
|
101
|
+
//# sourceMappingURL=mutations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../../src/component/sync/mutations.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,eAAO,MAAM,SAAS;;;;mBA6CpB,CAAC;AAKH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAsBzB,CAAC;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB;;;;;mBA2C5B,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { mutation } from "../_generated/server.js";
|
|
3
|
+
import { artistDoc, trackDoc } from "../validators.js";
|
|
4
|
+
import { isStale } from "./lifecycle.js";
|
|
5
|
+
/** Default rows scanned per markStale run. */
|
|
6
|
+
const DEFAULT_LIMIT = 200;
|
|
7
|
+
/**
|
|
8
|
+
* Flip past-freshness-window catalog rows from `synced` to `stale` for a kind.
|
|
9
|
+
* The freshness window scales by popularity (volatile-popular rows go stale
|
|
10
|
+
* sooner). Returns how many were newly marked. The auto-import sweep re-syncs
|
|
11
|
+
* stale rows; this is the detection half. Idempotent + bounded; mount-safe.
|
|
12
|
+
*/
|
|
13
|
+
export const markStale = mutation({
|
|
14
|
+
args: {
|
|
15
|
+
kind: v.union(v.literal("artist"), v.literal("track")),
|
|
16
|
+
limit: v.optional(v.number()),
|
|
17
|
+
now: v.optional(v.number()),
|
|
18
|
+
},
|
|
19
|
+
returns: v.number(),
|
|
20
|
+
handler: async (ctx, args) => {
|
|
21
|
+
const at = args.now ?? Date.now();
|
|
22
|
+
const take = args.limit ?? DEFAULT_LIMIT;
|
|
23
|
+
if (args.kind === "artist") {
|
|
24
|
+
const rows = await ctx.db
|
|
25
|
+
.query("artists")
|
|
26
|
+
.withIndex("by_sync", (q) => q.eq("syncStatus", "synced"))
|
|
27
|
+
.take(take);
|
|
28
|
+
const stale = rows.filter((row) => isStale(row.lastSyncedAt, row.popularity, at));
|
|
29
|
+
await Promise.all(stale.map((row) => ctx.db.patch("artists", row._id, {
|
|
30
|
+
syncStatus: "stale",
|
|
31
|
+
updatedAt: at,
|
|
32
|
+
})));
|
|
33
|
+
return stale.length;
|
|
34
|
+
}
|
|
35
|
+
const rows = await ctx.db
|
|
36
|
+
.query("tracks")
|
|
37
|
+
.withIndex("by_sync", (q) => q.eq("syncStatus", "synced"))
|
|
38
|
+
.take(take);
|
|
39
|
+
const stale = rows.filter((row) => isStale(row.lastSyncedAt, row.popularity, at));
|
|
40
|
+
await Promise.all(stale.map((row) => ctx.db.patch("tracks", row._id, {
|
|
41
|
+
syncStatus: "stale",
|
|
42
|
+
updatedAt: at,
|
|
43
|
+
})));
|
|
44
|
+
return stale.length;
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
/** Default lease before a `running` row is considered stuck (10 min). */
|
|
48
|
+
const DEFAULT_SYNC_LEASE_MS = 10 * 60 * 1000;
|
|
49
|
+
/**
|
|
50
|
+
* Atomically claim the next `stale` catalog row of a kind for re-sync: find one
|
|
51
|
+
* stale row via the index and flip it to `running` in the SAME transaction. The
|
|
52
|
+
* find + claim are one mutation, so two concurrent refresh sweeps can never both
|
|
53
|
+
* take the same row — Convex serializes the conflicting patch and the loser
|
|
54
|
+
* re-reads (the row is now `running`, no longer `stale`) and moves on. Returns
|
|
55
|
+
* the claimed row (so the caller has its `providers`), or `null` when none are
|
|
56
|
+
* stale. The re-import's upsert returns it to `synced`; `recoverStuckSyncs`
|
|
57
|
+
* salvages a lease whose holder crashed. Replaces a blind patch-by-id, which had
|
|
58
|
+
* no compare-and-set and could double-claim across action/mutation boundaries.
|
|
59
|
+
*/
|
|
60
|
+
export const claimNextStale = mutation({
|
|
61
|
+
args: { kind: v.union(v.literal("artist"), v.literal("track")) },
|
|
62
|
+
returns: v.union(v.null(), artistDoc, trackDoc),
|
|
63
|
+
handler: async (ctx, args) => {
|
|
64
|
+
const now = Date.now();
|
|
65
|
+
if (args.kind === "artist") {
|
|
66
|
+
const row = await ctx.db
|
|
67
|
+
.query("artists")
|
|
68
|
+
.withIndex("by_sync", (q) => q.eq("syncStatus", "stale"))
|
|
69
|
+
.first();
|
|
70
|
+
if (row === null)
|
|
71
|
+
return null;
|
|
72
|
+
await ctx.db.patch("artists", row._id, { syncStatus: "running", updatedAt: now });
|
|
73
|
+
return row;
|
|
74
|
+
}
|
|
75
|
+
const row = await ctx.db
|
|
76
|
+
.query("tracks")
|
|
77
|
+
.withIndex("by_sync", (q) => q.eq("syncStatus", "stale"))
|
|
78
|
+
.first();
|
|
79
|
+
if (row === null)
|
|
80
|
+
return null;
|
|
81
|
+
await ctx.db.patch("tracks", row._id, { syncStatus: "running", updatedAt: now });
|
|
82
|
+
return row;
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* Recover rows stuck in `running` past the lease (a re-sync that crashed before
|
|
87
|
+
* completing) by salvaging them back to `stale` for re-pickup. Bounded +
|
|
88
|
+
* idempotent; returns how many were recovered.
|
|
89
|
+
*
|
|
90
|
+
* Stuck = `updatedAt` older than `leaseMs` (default 10 min). A refresh re-syncs a
|
|
91
|
+
* single row (one provider fetch + a few upserts) in seconds, so the lease is far
|
|
92
|
+
* longer than a healthy run; only a genuinely crashed run is reclaimed. If a
|
|
93
|
+
* deployment runs much slower single-row refreshes, raise `leaseMs` above that
|
|
94
|
+
* duration so a still-running sync is never false-positive reclaimed.
|
|
95
|
+
*/
|
|
96
|
+
export const recoverStuckSyncs = mutation({
|
|
97
|
+
args: {
|
|
98
|
+
kind: v.union(v.literal("artist"), v.literal("track")),
|
|
99
|
+
leaseMs: v.optional(v.number()),
|
|
100
|
+
now: v.optional(v.number()),
|
|
101
|
+
limit: v.optional(v.number()),
|
|
102
|
+
},
|
|
103
|
+
returns: v.number(),
|
|
104
|
+
handler: async (ctx, args) => {
|
|
105
|
+
const at = args.now ?? Date.now();
|
|
106
|
+
const cutoff = at - (args.leaseMs ?? DEFAULT_SYNC_LEASE_MS);
|
|
107
|
+
const take = args.limit ?? DEFAULT_LIMIT;
|
|
108
|
+
if (args.kind === "artist") {
|
|
109
|
+
const rows = await ctx.db
|
|
110
|
+
.query("artists")
|
|
111
|
+
.withIndex("by_sync", (q) => q.eq("syncStatus", "running"))
|
|
112
|
+
.take(take);
|
|
113
|
+
const stuck = rows.filter((row) => row.updatedAt < cutoff);
|
|
114
|
+
await Promise.all(stuck.map((row) => ctx.db.patch("artists", row._id, {
|
|
115
|
+
syncStatus: "stale",
|
|
116
|
+
updatedAt: at,
|
|
117
|
+
})));
|
|
118
|
+
return stuck.length;
|
|
119
|
+
}
|
|
120
|
+
const rows = await ctx.db
|
|
121
|
+
.query("tracks")
|
|
122
|
+
.withIndex("by_sync", (q) => q.eq("syncStatus", "running"))
|
|
123
|
+
.take(take);
|
|
124
|
+
const stuck = rows.filter((row) => row.updatedAt < cutoff);
|
|
125
|
+
await Promise.all(stuck.map((row) => ctx.db.patch("tracks", row._id, {
|
|
126
|
+
syncStatus: "stale",
|
|
127
|
+
updatedAt: at,
|
|
128
|
+
})));
|
|
129
|
+
return stuck.length;
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
//# sourceMappingURL=mutations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutations.js","sourceRoot":"","sources":["../../../src/component/sync/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAoB,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,8CAA8C;AAC9C,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,QAAQ,CAAC;IAChC,IAAI,EAAE;QACJ,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACtD,K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CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;aAC1D,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,GAAG,MAAM,CAAC,CAAC;QAC3D,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAChB,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,GAAG,EAAE;YAC9B,UAAU,EAAE,OAAO;YACnB,SAAS,EAAE,EAAE;SACd,CAAC,CACH,CACF,CAAC;QACF,OAAO,KAAK,CAAC,MAAM,CAAC;IACtB,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List catalog rows currently marked `stale` for a kind (bounded). The
|
|
3
|
+
* auto-import refresh sweep consumes this to re-sync them; also useful for
|
|
4
|
+
* "what's stale" observability. Rows come from a query (always existing), so
|
|
5
|
+
* the refresh runner needs no load-by-id.
|
|
6
|
+
*/
|
|
7
|
+
export declare const listStale: import("convex/server").RegisteredQuery<"public", {
|
|
8
|
+
kind: "artist" | "track";
|
|
9
|
+
limit?: number | undefined;
|
|
10
|
+
}, Promise<{
|
|
11
|
+
_creationTime: number;
|
|
12
|
+
_id: import("convex/values").GenericId<"artists">;
|
|
13
|
+
country?: string | undefined;
|
|
14
|
+
debutYear?: number | undefined;
|
|
15
|
+
gender?: string | undefined;
|
|
16
|
+
genres: string[];
|
|
17
|
+
imageUrl?: string | undefined;
|
|
18
|
+
lastRepairAt?: number | undefined;
|
|
19
|
+
lastSyncError?: string | undefined;
|
|
20
|
+
lastSyncedAt?: number | undefined;
|
|
21
|
+
members?: "group" | "solo" | undefined;
|
|
22
|
+
name: string;
|
|
23
|
+
nameKey: string;
|
|
24
|
+
nextSyncAt?: number | undefined;
|
|
25
|
+
popularity?: number | undefined;
|
|
26
|
+
providers: {
|
|
27
|
+
genres?: string[] | undefined;
|
|
28
|
+
imageUrl?: string | undefined;
|
|
29
|
+
popularity?: number | undefined;
|
|
30
|
+
provider: "apple" | "deezer" | "musicbrainz" | "spotify" | "wikidata";
|
|
31
|
+
providerId: string;
|
|
32
|
+
url?: string | undefined;
|
|
33
|
+
}[];
|
|
34
|
+
repairAttempts?: number | undefined;
|
|
35
|
+
repairError?: string | undefined;
|
|
36
|
+
repairStartedAt?: number | undefined;
|
|
37
|
+
repairStatus?: "clean" | "failed_repair" | "needs_repair" | "repairing" | undefined;
|
|
38
|
+
syncRetryCount?: number | undefined;
|
|
39
|
+
syncStatus?: "failed" | "pending" | "running" | "stale" | "synced" | undefined;
|
|
40
|
+
updatedAt: number;
|
|
41
|
+
}[] | {
|
|
42
|
+
_creationTime: number;
|
|
43
|
+
_id: import("convex/values").GenericId<"tracks">;
|
|
44
|
+
artistIds: import("convex/values").GenericId<"artists">[];
|
|
45
|
+
durationMs?: number | undefined;
|
|
46
|
+
genres: string[];
|
|
47
|
+
isrc: string;
|
|
48
|
+
lastRepairAt?: number | undefined;
|
|
49
|
+
lastSyncError?: string | undefined;
|
|
50
|
+
lastSyncedAt?: number | undefined;
|
|
51
|
+
nextSyncAt?: number | undefined;
|
|
52
|
+
popularity?: number | undefined;
|
|
53
|
+
providers: {
|
|
54
|
+
coverUrl?: string | undefined;
|
|
55
|
+
previewUrl?: string | undefined;
|
|
56
|
+
provider: "apple" | "deezer" | "musicbrainz" | "spotify" | "wikidata";
|
|
57
|
+
providerId: string;
|
|
58
|
+
url?: string | undefined;
|
|
59
|
+
}[];
|
|
60
|
+
repairAttempts?: number | undefined;
|
|
61
|
+
repairError?: string | undefined;
|
|
62
|
+
repairStartedAt?: number | undefined;
|
|
63
|
+
repairStatus?: "clean" | "failed_repair" | "needs_repair" | "repairing" | undefined;
|
|
64
|
+
syncRetryCount?: number | undefined;
|
|
65
|
+
syncStatus?: "failed" | "pending" | "running" | "stale" | "synced" | undefined;
|
|
66
|
+
title: string;
|
|
67
|
+
updatedAt: number;
|
|
68
|
+
}[]>>;
|
|
69
|
+
//# sourceMappingURL=queries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../../src/component/sync/queries.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmBpB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { query } from "../_generated/server.js";
|
|
3
|
+
import { artistDoc, trackDoc } from "../validators.js";
|
|
4
|
+
/** Default rows returned per listStale call. */
|
|
5
|
+
const DEFAULT_LIMIT = 100;
|
|
6
|
+
/**
|
|
7
|
+
* List catalog rows currently marked `stale` for a kind (bounded). The
|
|
8
|
+
* auto-import refresh sweep consumes this to re-sync them; also useful for
|
|
9
|
+
* "what's stale" observability. Rows come from a query (always existing), so
|
|
10
|
+
* the refresh runner needs no load-by-id.
|
|
11
|
+
*/
|
|
12
|
+
export const listStale = query({
|
|
13
|
+
args: {
|
|
14
|
+
kind: v.union(v.literal("artist"), v.literal("track")),
|
|
15
|
+
limit: v.optional(v.number()),
|
|
16
|
+
},
|
|
17
|
+
returns: v.union(v.array(artistDoc), v.array(trackDoc)),
|
|
18
|
+
handler: async (ctx, args) => {
|
|
19
|
+
const take = args.limit ?? DEFAULT_LIMIT;
|
|
20
|
+
if (args.kind === "artist") {
|
|
21
|
+
return await ctx.db
|
|
22
|
+
.query("artists")
|
|
23
|
+
.withIndex("by_sync", (q) => q.eq("syncStatus", "stale"))
|
|
24
|
+
.take(take);
|
|
25
|
+
}
|
|
26
|
+
return await ctx.db
|
|
27
|
+
.query("tracks")
|
|
28
|
+
.withIndex("by_sync", (q) => q.eq("syncStatus", "stale"))
|
|
29
|
+
.take(take);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/component/sync/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,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEvD,gDAAgD;AAChD,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,CAAC;IAC7B,IAAI,EAAE;QACJ,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACtD,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;KAC9B;IACD,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACvD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,IAAI,aAAa,CAAC;QACzC,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3B,OAAO,MAAM,GAAG,CAAC,EAAE;iBAChB,KAAK,CAAC,SAAS,CAAC;iBAChB,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;iBACxD,IAAI,CAAC,IAAI,CAAC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