From 1d160e7e2243e093421ce4b7baaa99c2869cdb24 Mon Sep 17 00:00:00 2001 From: Danijel Martinek Date: Sat, 9 May 2026 12:36:06 +0200 Subject: [PATCH] feat(core-shared): BindContext + BindProductionContext types --- packages/core-shared/src/di/bind-context.ts | 42 +++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 packages/core-shared/src/di/bind-context.ts diff --git a/packages/core-shared/src/di/bind-context.ts b/packages/core-shared/src/di/bind-context.ts new file mode 100644 index 0000000..9fcadb9 --- /dev/null +++ b/packages/core-shared/src/di/bind-context.ts @@ -0,0 +1,42 @@ +import type { SanitizedConfig } from "payload"; +import type { ITracer, ILogger } from "../instrumentation"; +import type { IJobQueue } from "../jobs"; +import type { + EventBusProtocol, + RealtimeBroadcasterProtocol, + RealtimeRegistryProtocol, +} from "./bind-protocols"; + +/** Always-present fields. Feature binders rely on these unconditionally. */ +export type BindContextBase = { + tracer: ITracer; + logger: ILogger; +}; + +/** + * Optional cross-cutting deps. Generics let the app aggregator narrow the + * shape to full interfaces (`IEventBus`, `IRealtimeBroadcaster`, etc.); feature + * binders see only the protocol surface, which is enough for the methods they + * call. When an optional core package is absent the corresponding generic + * defaults to its protocol type, and `ctx.bus` / `ctx.realtime` are undefined + * at runtime. + */ +export type BindContext< + Bus extends EventBusProtocol = EventBusProtocol, + Realtime extends RealtimeBroadcasterProtocol = RealtimeBroadcasterProtocol, + RealtimeReg extends RealtimeRegistryProtocol = RealtimeRegistryProtocol, +> = BindContextBase & { + bus?: Bus; + queue?: IJobQueue; + realtime?: Realtime; + realtimeRegistry?: RealtimeReg; +}; + +/** Production binders also receive the resolved Payload config. */ +export type BindProductionContext< + Bus extends EventBusProtocol = EventBusProtocol, + Realtime extends RealtimeBroadcasterProtocol = RealtimeBroadcasterProtocol, + RealtimeReg extends RealtimeRegistryProtocol = RealtimeRegistryProtocol, +> = BindContext & { + config: SanitizedConfig; +};