/* eslint-disable */ import * as generatedApis from './apis/index'; import { Configuration, FetchAPI, Middleware } from './runtime'; export * from './runtime'; export * from './apis/index'; export * from './models/index'; // Helper to extract keys that are API classes (ending in 'Api' and are constructors) type GeneratedExports = typeof generatedApis; type ApiConstructor = new (configuration: Configuration) => any; // Helper to check if a value is an API constructor function isApiConstructor(value: any): value is ApiConstructor { return typeof value === 'function' && value.name.endsWith('Api'); } const APIS = Object.keys(generatedApis) .map((key) => (generatedApis as any)[key]) .filter(isApiConstructor); export interface FabricApiOptions { apiKey: string; baseId?: string; basePath?: string; middleware?: Middleware[]; fetchApi?: FetchAPI; } type ApiKeys = { [K in keyof GeneratedExports]: K extends `${string}Api` ? GeneratedExports[K] extends ApiConstructor ? K : never : never; }[keyof GeneratedExports]; type StripApiSuffix = T extends `${infer Name}Api` ? Name : T; type LowercaseFirst = T extends `${infer First}${infer Rest}` ? `${Lowercase}${Rest}` : T; type FabricApis = { [K in ApiKeys as LowercaseFirst< StripApiSuffix >]: GeneratedExports[K] extends ApiConstructor ? InstanceType : never; }; function apiPropertyName(className: string): string { return className .replace(/Api$/, '') // remove Api suffix .replace(/^./, (c) => c.toLowerCase()); // lowercase first letter } export interface Fabric extends FabricApis {} export class Fabric { constructor(options: FabricApiOptions) { const configuration = new Configuration({ middleware: options.middleware || [], apiKey: options.apiKey, basePath: options.basePath, fetchApi: options.fetchApi, ...(options.baseId && { headers: { 'X-Fabric-Base-Id': String(options.baseId), }, }), }); for (const Api of APIS) { const apiInstance = new Api(configuration); (this as any)[apiPropertyName(Api.name)] = apiInstance; } } }