Declare a server context blueprint once and share it between the runtime server and tests.
The helper preserves the blueprint exactly as written — request,
service, and gate keep their inferred types — so apps can keep the
blueprint in a canonical server/context.ts file and pass the same value to
createServer(...) (through an adapter such as createNextServer or
createFetchServer) and to createTestApp(...).
A function that collects and returns the typed context blueprint.
// server/context.ts
export const appContext = defineServerContext<AppContext, AppPorts>()({
gate: (ports) => ports.gate,
request: async ({ req, ports, requestId, trace }) => ({
actor: await resolveActor(req),
auth: null,
requestId,
...trace,
ports,
}),
service: ({ ports, requestId, trace }) => ({
actor: createServiceActor("app-service"),
auth: null,
requestId,
...trace,
ports,
}),
});
Server context blueprint declaration helper.