-
Notifications
You must be signed in to change notification settings - Fork 0
fix(types): tipa records do bridge em products.ts (-36 erros TS) — F1-1.x Onda C #3 #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| import { type ExternalProduct } from "@/types/external-db"; | ||
| /** | ||
| * Fetch products with full enrichment (colors, images, variants, suppliers). | ||
| */ | ||
|
|
@@ -12,6 +11,24 @@ import { | |
| shouldFallbackSelect, | ||
| } from './product-types'; | ||
|
|
||
| // Row shapes for external_db_bridge results (untyped at runtime; assertions below). | ||
| type VariantRow = { | ||
| id: string; product_id: string; sku?: string | null; | ||
| color_id?: string | null; color_name?: string | null; color_code?: string | null; | ||
| color_hex?: string | null; stock_quantity?: number | null; | ||
| selected_thumbnail?: string | null; images?: string[] | null; | ||
| }; | ||
| type ImageRow = { | ||
|
Comment on lines
+16
to
+21
|
||
| product_id: string; variant_id: string | null; | ||
| url_cdn: string; url_original: string | null; filename: string | null; | ||
| image_type: string; is_primary: boolean; is_og_image: boolean | null; | ||
| applies_to_color: boolean | null; display_order: number; | ||
| supplier_code: string | null; alt_text: string | null; title_text: string | null; | ||
| }; | ||
| type SupplierRow = { id: string; name: string; code: string }; | ||
|
|
||
| type ColorVariationRow = { id: string; name: string; slug: string; group_id: string }; | ||
| type ColorGroupRow = { id: string; name: string; slug: string }; | ||
|
Comment on lines
+29
to
+30
|
||
|
|
||
| export async function fetchPromobrindProducts(options?: { | ||
| search?: string; | ||
| limit?: number; | ||
|
|
@@ -231,31 +248,31 @@ async function enrichProducts( | |
| } | ||
|
|
||
| // Extract results | ||
| const variantsRecords: Record<string, unknown>[] = []; | ||
| const variantsRecords: VariantRow[] = []; | ||
| for (const idx of queryMap.variants) { | ||
| const r = batchResults[idx]; | ||
| if (r?.success && r.data?.records) variantsRecords.push(...r.data.records); | ||
| if (r?.success && r.data?.records) variantsRecords.push(...(r.data.records as VariantRow[])); | ||
| } | ||
| const imagesRecords: Record<string, unknown>[] = []; | ||
| const imagesRecords: ImageRow[] = []; | ||
| for (const idx of queryMap.images) { | ||
| const r = batchResults[idx]; | ||
| if (r?.success && r.data?.records) imagesRecords.push(...r.data.records); | ||
| if (r?.success && r.data?.records) imagesRecords.push(...(r.data.records as ImageRow[])); | ||
| } | ||
| const suppliersRecords: { id: string; name: string; code: string }[] = []; | ||
| const suppliersRecords: SupplierRow[] = []; | ||
| for (const idx of queryMap.suppliers) { | ||
| const r = batchResults[idx]; | ||
| if (r?.success && r.data?.records) suppliersRecords.push(...(r.data.records as ExternalProduct[])); | ||
| if (r?.success && r.data?.records) suppliersRecords.push(...(r.data.records as SupplierRow[])); | ||
| } | ||
|
|
||
| let colorVariationsRecords: Record<string, unknown>[] = []; | ||
| let colorVariationsRecords: ColorVariationRow[] = []; | ||
| for (const idx of queryMap.colorVariations) { | ||
| const r = batchResults[idx]; | ||
| if (r?.success && r.data?.records) colorVariationsRecords = r.data.records as unknown[]; | ||
| if (r?.success && r.data?.records) colorVariationsRecords = r.data.records as ColorVariationRow[]; | ||
| } | ||
| let colorGroupsRecords: Record<string, unknown>[] = []; | ||
| let colorGroupsRecords: ColorGroupRow[] = []; | ||
| for (const idx of queryMap.colorGroups) { | ||
| const r = batchResults[idx]; | ||
| if (r?.success && r.data?.records) colorGroupsRecords = r.data.records as unknown[]; | ||
| if (r?.success && r.data?.records) colorGroupsRecords = r.data.records as ColorGroupRow[]; | ||
|
Comment on lines
+252
to
+276
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verifica pontos com cast direto de records sem narrowing e o tipo de BatchResult no bridge.
rg -n -C2 'r\.data\.records as [A-Za-z]+Row\[\]' src/lib/external-db/products.ts
fd -i 'bridge.ts' src/lib/external-db --exec sed -n '1,260p' {}Repository: adm01-debug/Promo_Gifts Length of output: 9157 🏁 Script executed: # Verify the Row type definitions exist to understand what narrowing should check
rg -n 'type.*Row\s*=|interface.*Row\s*{' src/lib/external-db/products.ts | head -20Repository: adm01-debug/Promo_Gifts Length of output: 195 🏁 Script executed: # Check Row type definitions
rg -n 'type.*Row' src/lib/external-db/products.ts | head -20Repository: adm01-debug/Promo_Gifts Length of output: 335 🏁 Script executed: # Get the full Row type definitions
sed -n '16,31p' src/lib/external-db/products.tsRepository: adm01-debug/Promo_Gifts Length of output: 927 Casts de Essas linhas fazem cast direto de Implemente narrowing mínimo antes de usar os dados: Exemplo de fix+const isSupplierRow = (v: unknown): v is SupplierRow => {
+ if (!v || typeof v !== 'object') return false;
+ const r = v as Record<string, unknown>;
+ return typeof r.id === 'string' && typeof r.name === 'string' && typeof r.code === 'string';
+};
const suppliersRecords: SupplierRow[] = [];
for (const idx of queryMap.suppliers) {
const r = batchResults[idx];
- if (r?.success && r.data?.records) suppliersRecords.push(...(r.data.records as SupplierRow[]));
+ if (r?.success && Array.isArray(r.data?.records)) {
+ suppliersRecords.push(...r.data.records.filter(isSupplierRow));
+ }
}Repita para variants, images, colorVariations e colorGroups (linhas 255, 260, 271, 276). 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| const suppliersMap = new Map(suppliersRecords.map(s => [s.id, s.name])); | ||
|
|
@@ -266,8 +283,8 @@ async function enrichProducts( | |
| if (s?.id && s?.name) putInCacheSafe('suppliers', { id: s.id, name: s.name, code: s.code }); | ||
| } | ||
| } catch { /* cache populate is best-effort */ } | ||
| const colorVariationMap = new Map(colorVariationsRecords.map((v) => [v.id as string, { name: v.name as string, slug: v.slug as string, group_id: v.group_id as string }])); | ||
| const colorGroupMap = new Map(colorGroupsRecords.map((g) => [g.id as string, { name: g.name as string, slug: g.slug as string }])); | ||
| const colorVariationMap = new Map(colorVariationsRecords.map((v) => [v.id, { name: v.name, slug: v.slug, group_id: v.group_id }])); | ||
| const colorGroupMap = new Map(colorGroupsRecords.map((g) => [g.id, { name: g.name, slug: g.slug }])); | ||
|
|
||
| // Build image map | ||
| const productIdSet = new Set(productIds); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VariantRow.idobrigatório está inconsistente com o payload consultado.VariantRowexigeid: string, mas a query deproduct_variantsnão selecionaid. Isso mascara erro de contrato e pode quebrar a associação porvariant.idna montagem das imagens.🔧 Ajuste sugerido
🤖 Prompt for AI Agents