$npx -y skills add wrtnlabs/autobe --skill fix-providerFix Provider, Collector, Transformer compilation errors
| 1 | # Fix Provider Errors |
| 2 | |
| 3 | Fix provider, collector, and transformer compilation errors according to code conventions. |
| 4 | |
| 5 | ## FORBIDDEN |
| 6 | |
| 7 | **NEVER use:** |
| 8 | - `as` keyword (type assertion) |
| 9 | - `any` type |
| 10 | |
| 11 | Fix type issues by properly defining Collectors and Transformers. |
| 12 | |
| 13 | --- |
| 14 | |
| 15 | ## Purpose |
| 16 | |
| 17 | Fix compilation errors in provider files to ensure `npm run build:main` passes. |
| 18 | |
| 19 | ## Workflow |
| 20 | |
| 21 | ``` |
| 22 | ┌─────────────────────────────────────┐ |
| 23 | │ Step 1: Run Build │ |
| 24 | │ npm run build:main │ |
| 25 | └───────────────┬─────────────────────┘ |
| 26 | │ |
| 27 | ▼ |
| 28 | ┌─────────────────────────────────────┐ |
| 29 | │ Step 2: Parse Provider Errors │ |
| 30 | │ - as any usage │ |
| 31 | │ - Type mismatches │ |
| 32 | │ - Missing imports │ |
| 33 | └───────────────┬─────────────────────┘ |
| 34 | │ |
| 35 | ▼ |
| 36 | ┌─────────────────────────────────────┐ |
| 37 | │ Step 3: Fix by Convention │ |
| 38 | │ - Create Collectors │ |
| 39 | │ - Create Transformers │ |
| 40 | │ - Remove type assertions │ |
| 41 | └───────────────┬─────────────────────┘ |
| 42 | │ |
| 43 | ▼ |
| 44 | ┌─────────────────────────────────────┐ |
| 45 | │ Step 4: Re-run Build │ |
| 46 | │ Loop until 0 errors │ |
| 47 | └─────────────────────────────────────┘ |
| 48 | ``` |
| 49 | |
| 50 | --- |
| 51 | |
| 52 | ## Step 1: Run Build |
| 53 | |
| 54 | ```bash |
| 55 | npm run build:main 2>&1 | head -100 |
| 56 | ``` |
| 57 | |
| 58 | Capture provider-related errors. |
| 59 | |
| 60 | --- |
| 61 | |
| 62 | ## Step 2: Find Issues |
| 63 | |
| 64 | ```bash |
| 65 | # Find as any usage |
| 66 | grep -rn "as any" src/providers/ --include="*.ts" |
| 67 | |
| 68 | # Find any type |
| 69 | grep -rn ": any" src/providers/ --include="*.ts" |
| 70 | |
| 71 | # Find type assertions |
| 72 | grep -rn " as " src/providers/ --include="*.ts" | grep -v "import" |
| 73 | ``` |
| 74 | |
| 75 | --- |
| 76 | |
| 77 | ## Step 3: Fix by Convention |
| 78 | |
| 79 | ### Create Collector (if missing) |
| 80 | |
| 81 | ```typescript |
| 82 | // src/collectors/{Prefix}{Entity}Collector.ts |
| 83 | import { I{Prefix}{Entity} } from "@ORGANIZATION/PROJECT-api/lib/structures/I{Prefix}{Entity}"; |
| 84 | import { Prisma } from "@prisma/sdk"; |
| 85 | import { v4 } from "uuid"; |
| 86 | |
| 87 | export namespace {Prefix}{Entity}Collector { |
| 88 | export function collect(props: { |
| 89 | body: I{Prefix}{Entity}.ICreate; |
| 90 | }): Prisma.{table_name}CreateInput { |
| 91 | const id = v4(); |
| 92 | const now = new Date(); |
| 93 | |
| 94 | return { |
| 95 | id, |
| 96 | field_name: props.body.field_name, |
| 97 | optional_field: props.body.optional_field ?? null, |
| 98 | parent: props.body.parent_id |
| 99 | ? { connect: { id: props.body.parent_id } } |
| 100 | : undefined, |
| 101 | created_at: now, |
| 102 | updated_at: now, |
| 103 | deleted_at: null, |
| 104 | }; |
| 105 | } |
| 106 | } |
| 107 | ``` |
| 108 | |
| 109 | ### Create Transformer (if missing) |
| 110 | |
| 111 | ```typescript |
| 112 | // src/transformers/{Prefix}{Entity}Transformer.ts |
| 113 | import { I{Prefix}{Entity} } from "@ORGANIZATION/PROJECT-api/lib/structures/I{Prefix}{Entity}"; |
| 114 | import { {table_name} } from "@prisma/sdk"; |
| 115 | |
| 116 | export namespace {Prefix}{Entity}Transformer { |
| 117 | export function transform(record: {table_name}): I{Prefix}{Entity} { |
| 118 | return { |
| 119 | id: record.id, |
| 120 | name: record.name, |
| 121 | status: record.status, |
| 122 | created_at: record.created_at.toISOString(), |
| 123 | updated_at: record.updated_at.toISOString(), |
| 124 | deleted_at: record.deleted_at |
| 125 | ? record.deleted_at.toISOString() |
| 126 | : null, |
| 127 | }; |
| 128 | } |
| 129 | |
| 130 | export function toSummary(record: {table_name}): I{Prefix}{Entity}.ISummary { |
| 131 | return { |
| 132 | id: record.id, |
| 133 | name: record.name, |
| 134 | status: record.status, |
| 135 | created_at: record.created_at.toISOString(), |
| 136 | }; |
| 137 | } |
| 138 | |
| 139 | export function transformMany(records: {table_name}[]): I{Prefix}{Entity}[] { |
| 140 | return records.map(transform); |
| 141 | } |
| 142 | |
| 143 | export function toSummaryList(records: {table_name}[]): I{Prefix}{Entity}.ISummary[] { |
| 144 | return records.map(toSummary); |
| 145 | } |
| 146 | } |
| 147 | ``` |
| 148 | |
| 149 | ### Fix POST Provider |
| 150 | |
| 151 | ```typescript |
| 152 | // Before |
| 153 | const createData: any = { ... }; |
| 154 | return { id: created.id as string & tags.Format<"uuid">, ... }; |
| 155 | |
| 156 | // After |
| 157 | import { {Prefix}{Entity}Collector } from "../collectors/{Prefix}{Entity}Collector"; |
| 158 | import { {Prefix}{Entity}Transformer } from "../transformers/{Prefix}{Entity}Transformer"; |
| 159 | |
| 160 | export async function post{Prefix}{Entity}(props: { |
| 161 | body: I{Prefix}{Entity}.ICreate; |
| 162 | }): Promise<I{Prefix}{Entity}> { |
| 163 | const data = {Prefix}{Entity}Collector.collect({ body: props.body }); |
| 164 | const created = await MyGlobal.prisma.{table}.create({ data }); |
| 165 | return {Prefix}{Entity}Transformer.transform(created); |
| 166 | } |
| 167 | ``` |
| 168 | |
| 169 | ### Fix GET Provider |
| 170 | |
| 171 | ```typescript |
| 172 | // Before |
| 173 | return { |
| 174 | id: record.id as string & tags.Format<"uuid">, |
| 175 | ... |
| 176 | }; |
| 177 | |
| 178 | // After |
| 179 | import { {Prefix}{Entity}Transformer } from "../transformers/{Prefix}{Entity}Transformer"; |
| 180 | |
| 181 | export async function get{Prefix}{Entity}(props: { id: string }): Promise<I{Prefix}{Entity}> { |
| 182 | const record = await MyGlobal.prisma.{table}.findUnique({ where: { id: props.id } }); |
| 183 | if (!record) throw new HttpException("Not found", 404); |
| 184 | return {Prefix}{Entity}Transformer.transform(record); |
| 185 | } |
| 186 | ``` |
| 187 | |
| 188 | --- |
| 189 | |
| 190 | ## Step 4: Verify |
| 191 | |
| 192 | ```bash |
| 193 | npm run build:main |
| 194 | ``` |
| 195 | |
| 196 | R |