👁️
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

migration that adds the typeline

+81 -5
+81 -5
src/routes/dev/migrate.tsx
··· 17 17 tags?: string[]; 18 18 } 19 19 20 + interface NewDeckCard { 21 + ref: CardRef; 22 + quantity: number; 23 + section: string; 24 + tags?: string[]; 25 + } 26 + 27 + type DeckCard = OldDeckCard | NewDeckCard; 28 + 20 29 interface OldCollectionCardItem { 21 30 $type: "com.deckbelcher.collection.list#cardItem"; 22 31 scryfallId: string; 23 32 addedAt: string; 24 33 } 25 34 35 + interface NewCollectionCardItem { 36 + $type: "com.deckbelcher.collection.list#cardItem"; 37 + ref: CardRef; 38 + addedAt: string; 39 + } 40 + 26 41 interface OldCollectionDeckItem { 27 42 $type: "com.deckbelcher.collection.list#deckItem"; 28 43 deckUri: string; 29 44 addedAt: string; 30 45 } 31 46 32 - type OldCollectionItem = OldCollectionCardItem | OldCollectionDeckItem; 47 + interface NewCollectionDeckItem { 48 + $type: "com.deckbelcher.collection.list#deckItem"; 49 + ref: { uri: string; cid: string }; 50 + addedAt: string; 51 + } 52 + 53 + type CollectionItem = 54 + | OldCollectionCardItem 55 + | NewCollectionCardItem 56 + | OldCollectionDeckItem 57 + | NewCollectionDeckItem; 33 58 34 59 interface OldDeckList { 35 60 $type: "com.deckbelcher.deck.list"; 36 61 name: string; 37 62 format?: string; 38 63 primer?: unknown; 39 - cards: OldDeckCard[]; 64 + cards: DeckCard[]; 40 65 createdAt: string; 41 66 updatedAt?: string; 42 67 } ··· 45 70 $type: "com.deckbelcher.collection.list"; 46 71 name: string; 47 72 description?: unknown; 48 - items: OldCollectionItem[]; 73 + items: CollectionItem[]; 49 74 createdAt: string; 50 75 updatedAt?: string; 51 76 } ··· 74 99 } 75 100 76 101 interface OldDocument { 102 + $type?: string; 77 103 content: OldBlock[]; 78 104 } 79 105 106 + interface PrimerUri { 107 + $type: "com.deckbelcher.deck.list#primerUri"; 108 + uri: string; 109 + } 110 + 111 + interface PrimerRef { 112 + $type: "com.deckbelcher.deck.list#primerRef"; 113 + ref: { uri: string; cid: string }; 114 + } 115 + 116 + type Primer = OldDocument | PrimerUri | PrimerRef; 117 + 80 118 interface MigrationResult { 81 119 success: boolean; 82 120 output?: unknown; ··· 132 170 }), 133 171 ); 134 172 135 - return { content: newContent }; 173 + return { $type: "com.deckbelcher.richtext#document", content: newContent }; 174 + } 175 + 176 + async function migratePrimer( 177 + primer: Primer | undefined, 178 + ): Promise<Primer | undefined> { 179 + if (!primer) return undefined; 180 + 181 + // uri and ref primers pass through unchanged 182 + if ( 183 + "uri" in primer && 184 + primer.$type === "com.deckbelcher.deck.list#primerUri" 185 + ) { 186 + return primer; 187 + } 188 + if ( 189 + "ref" in primer && 190 + primer.$type === "com.deckbelcher.deck.list#primerRef" 191 + ) { 192 + return primer; 193 + } 194 + 195 + // embedded document - migrate and add $type 196 + if ("content" in primer) { 197 + return migrateDocument(primer); 198 + } 199 + 200 + return undefined; 136 201 } 137 202 138 203 if (record.$type === "com.deckbelcher.deck.list") { 139 204 const newCards = await Promise.all( 140 205 record.cards.map(async (card) => { 206 + // Already migrated - pass through 207 + if ("ref" in card) { 208 + return card; 209 + } 210 + // Old format - migrate 141 211 const ref = await buildCardRef(card.scryfallId); 142 212 if (!ref) return null; 143 213 return { ··· 153 223 return { success: false, errors }; 154 224 } 155 225 156 - const newPrimer = await migrateDocument(record.primer as OldDocument); 226 + const newPrimer = await migratePrimer(record.primer as Primer); 157 227 158 228 return { 159 229 success: true, ··· 173 243 if (record.$type === "com.deckbelcher.collection.list") { 174 244 const newItems = await Promise.all( 175 245 record.items.map(async (item) => { 246 + // Deck items pass through (already have ref or old deckUri) 176 247 if (item.$type === "com.deckbelcher.collection.list#deckItem") { 177 248 return item; 178 249 } 250 + // Already migrated card item - pass through 251 + if ("ref" in item) { 252 + return item; 253 + } 254 + // Old format card item - migrate 179 255 const ref = await buildCardRef(item.scryfallId); 180 256 if (!ref) return null; 181 257 return {