UNPKG

@beignet/core

Version:

Core framework primitives for Beignet

39 lines 1.35 kB
/** * Normalize a server context configuration into its runtime parts. */ export function resolveServerContext(config) { const value = config; if (typeof value === "function") { return { request: value }; } return { request: value.request, service: value.service, gate: value.gate, }; } /** * Create the context finalizer for a resolved server context. * * When the blueprint declares a gate, the finalizer strips hand-assigned * `gate` values from seeds and attaches the live gate. Without a gate * declaration the seed is the context. */ export function createContextFinalizer(resolved, getPorts) { const gateSelector = resolved.gate; if (!gateSelector) { return (seed) => seed; } return (seed) => { const target = seed; const existing = Object.getOwnPropertyDescriptor(target, "gate"); if (existing && existing.get === undefined) { if (process.env.NODE_ENV !== "production") { console.warn("[beignet] Ignoring a hand-assigned ctx.gate value. The server context blueprint owns gate attachment; remove `gate` from context factories and hook additions."); } delete target.gate; } return gateSelector(getPorts()).attach(target); }; } //# sourceMappingURL=context.js.map