Libraries
    Preparing search index...
    • Merges two API contracts into one.

      This is the primary building block for audience-scoped bundles: define a publicApi that is safe to ship to every client, and a separate adminApi that is only imported by the admin application. Combine them at the admin entry point with mergeContracts.

      • Groups that exist in only one contract are passed through unchanged.
      • Groups that share a key have their endpoint maps shallowly merged (later endpoints with the same name override earlier ones, same semantics as Object.assign).
      • The returned contract is frozen, matching the invariant of defineApi.

      Type Parameters

      Parameters

      • a: A

        The base contract (e.g. the public API).

      • b: B

        The contract to merge in (e.g. admin-only groups).

      Returns Readonly<MergedContracts<A, B>>

      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