1import type { ProviderDriverKind, ServerProvider } from "@t3tools/contracts";
2
3import type { ProviderInstance } from "@t3tools/provider-core/server/driver";
4import type { ServerProviderDraft } from "@t3tools/provider-core/server/snapshotProbe";
5
6/**
7 * Stamp instance identity onto a `ServerProvider` snapshot produced by the
8 * driver-kind-only snapshot helpers. Every driver builds its snapshot without
9 * knowing its own instance, so it pipes the draft through this stamper before
10 * publishing. Once `buildServerProvider` in `providerSnapshot.ts` is widened to
11 * accept `instanceId`/`driver`, this wrapper disappears.
12 */
13export const withInstanceIdentity =
14 (input: {
15 readonly instanceId: ProviderInstance["instanceId"];
16 readonly driverKind: ProviderDriverKind;
17 readonly displayName: string | undefined;
18 readonly accentColor: string | undefined;
19 readonly continuationGroupKey: string;
20 }) =>
21 (snapshot: ServerProviderDraft): ServerProvider => ({
22 ...snapshot,
23 instanceId: input.instanceId,
24 driver: input.driverKind,
25 ...(input.displayName ? { displayName: input.displayName } : {}),
26 ...(input.accentColor ? { accentColor: input.accentColor } : {}),
27 continuation: { groupKey: input.continuationGroupKey },
28 });