UNPKG

@beignet/core

Version:

Core framework primitives for Beignet

48 lines 1.51 kB
/** * PortsBuilder - Mutable builder for composing ports during app initialization * * This builder is a small composition helper for tests and custom bootstrapping * code that wants to assemble ports incrementally. */ /** * Create a new PortsBuilder from an initial ports object. * * The builder wraps a mutable object internally and provides type-safe methods * to extend or replace ports. This is used during application composition * helpers that want to modify ports before passing them to a server. * * @example * ```ts * const initialPorts = definePorts({ db: dbAdapter }); * const builder = createPortsBuilder(initialPorts); * * // Provider extends with cache * builder.extend("cache", cacheAdapter); * * // Final ports includes both db and cache * const finalPorts = builder.ports; * ``` */ export function createPortsBuilder(initialPorts) { // Keep a mutable object internally // biome-ignore lint/suspicious/noExplicitAny: internal mutable state needs any to accept arbitrary port extensions const state = { ports: { ...initialPorts }, }; const builder = { get ports() { // Could freeze in dev, but keep simple return state.ports; }, extend(key, value) { state.ports[key] = value; return builder; }, replace(key, value) { state.ports[key] = value; return builder; }, }; return builder; } //# sourceMappingURL=builder.js.map