Skip to main content
Glama
builders.ts1.03 kB
export class FixtureBuilder<T> { protected entity: Partial<T> = {}; constructor(defaults: T) { this.entity = { ...defaults }; } with(overrides: Partial<T>): this { this.entity = { ...this.entity, ...overrides }; return this; } build(): T { return this.entity as T; } buildMany(count: number, modifier?: (item: T, index: number) => T): T[] { return Array.from({ length: count }, (_, i) => { const item = this.build(); return modifier ? modifier(item, i) : item; }); } } // Base class for domain-specific builders export abstract class DomainFixtureBuilder<T> extends FixtureBuilder<T> { protected abstract getDefaultEntity(): T; constructor() { super({} as T); this.entity = this.getDefaultEntity(); } // Helper to merge nested objects protected mergeNested<K extends keyof T>(key: K, value: Partial<T[K]>): this { this.entity[key] = { ...(typeof this.entity[key] === "object" && this.entity[key] !== null ? this.entity[key] : {}), ...value, } as T[K]; return this; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/AbdallahAHO/lokalise-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server