| 250 | // --------------------------------------------------------------------------- |
| 251 | |
| 252 | function render( |
| 253 | overrides: Map<string, Partial<Record<RoleKey, string>>>, |
| 254 | ): string { |
| 255 | const clientVersion = ( |
| 256 | JSON.parse(readFileSync(CLIENT_PKG_JSON, 'utf8')) as { version: string } |
| 257 | ).version |
| 258 | const dtsHash = createHash('sha256') |
| 259 | .update(readFileSync(ENDPOINTS_DTS)) |
| 260 | .digest('hex') |
| 261 | |
| 262 | const sortedIds = [...overrides.keys()].sort() |
| 263 | const entries = sortedIds |
| 264 | .map((id) => { |
| 265 | const entry = overrides.get(id)! |
| 266 | const pairs = ROLE_ORDER.filter((role) => entry[role]).map( |
| 267 | (role) => `${role}: '${entry[role]}'`, |
| 268 | ) |
| 269 | return ` '${id}': { ${pairs.join(', ')} },` |
| 270 | }) |
| 271 | .join('\n') |
| 272 | |
| 273 | // Union of every field name the runtime mapper may emit: the per-role |
| 274 | // defaults plus every field referenced by an override. |
| 275 | const fieldNames = new Set<string>(Object.values(DEFAULTS)) |
| 276 | for (const entry of overrides.values()) { |
| 277 | for (const field of Object.values(entry)) fieldNames.add(field) |
| 278 | } |
| 279 | const fieldNameUnion = [...fieldNames] |
| 280 | .sort() |
| 281 | .map((name) => ` | '${name}'`) |
| 282 | .join('\n') |
| 283 | |
| 284 | return `/* eslint-disable */ |
| 285 | // --------------------------------------------------------------------------- |
| 286 | // AUTO-GENERATED — do not edit by hand. |
| 287 | // |
| 288 | // Generated from @fal-ai/client@${clientVersion} EndpointTypeMap by |
| 289 | // scripts/generate-fal-image-field-map.ts. Regenerate after bumping |
| 290 | // @fal-ai/client: |
| 291 | // |
| 292 | // pnpm tsx scripts/generate-fal-image-field-map.ts |
| 293 | // |
| 294 | // Maps fal endpoint ids to the image-conditioning input fields they accept |
| 295 | // whenever those differ from the defaults in image-inputs.ts. Endpoints |
| 296 | // matching the defaults are omitted. The \`satisfies\` clause below checks |
| 297 | // every field name against the SDK's endpoint input types at compile time |
| 298 | // (type-only import — nothing from endpoints.d.ts is shipped at runtime). |
| 299 | // --------------------------------------------------------------------------- |
| 300 | import type { EndpointTypeMap } from '@fal-ai/client/endpoints' |
| 301 | |
| 302 | /** sha256 of the endpoints.d.ts this file was generated from. */ |
| 303 | export const FAL_ENDPOINTS_DTS_SHA256 = |
| 304 | '${dtsHash}' |
| 305 | |
| 306 | /** Every input field name the image-input mappers may emit. */ |
| 307 | export type FalImageFieldName = |
| 308 | ${fieldNameUnion} |
| 309 | |