The shape of the first contract.
The shape of the second contract.
A new frozen contract whose type is MergedContracts<A, B>.
// shared/public-api.ts — safe to import in the client bundle
export const publicApi = defineApi({
todos: { list: ..., get: ..., create: ... },
auth: { login: ..., register: ... },
});
// shared/admin-api.ts — only imported by the admin application
const adminApi = defineApi({
admin: { activityLog: ..., banUser: ... },
});
// admin-app/contract.ts
import { mergeContracts } from '@cleverbrush/server/contract';
export const fullApi = mergeContracts(publicApi, adminApi);
// TypeScript sees: { todos, auth, admin } — fully typed
// client-app/contract.ts
import { publicApi } from 'shared/public-api';
// TypeScript sees: { todos, auth } — admin groups are absent
Merges two API contracts into one.
This is the primary building block for audience-scoped bundles: define a
publicApithat is safe to ship to every client, and a separateadminApithat is only imported by the admin application. Combine them at the admin entry point withmergeContracts.Object.assign).