> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Multiple Repositories

> Use Bijection in multiple repositories

Your TypeScript clients can call Bijection functions in a type-safe way outside of
the repository where your Bijection functions are defined. By following the steps
below, you can generate a file similar to `bijection/_generated/api.d.ts` that you
can check in and use in a separate repository.

<Warning>
  TypeScript API generation is in beta.
</Warning>

<Steps>
  <Step title="Export your function metadata">
    [`bijection function-spec`](/cli/reference/function-spec) reads the
    argument and return value validators of your deployment's functions and
    writes them as JSON.

    ```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
    bijection function-spec --file
    ```
  </Step>

  <Step title="Generate a TypeScript API file">
    Convert the function metadata into an `api.ts` file like the one below, for
    example with a community helper library that reads this JSON.
  </Step>
</Steps>

## Example

Below are code snippets of what this workflow looks like in action. These
snippets include three different files:

* `bijection/messages.ts` - contains Bijection function definitions
* `api.ts` - a generated file from running the command above
* `src/App.tsx` - frontend code in a separate repository where `api.ts` is
  checked in

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { v } from "bijection/values";
import { mutation } from "./_generated/server";

export const send = mutation({
  args: { body: v.string(), author: v.string() },
  returns: v.null(),
  handler: async (ctx, { body, author }) => {
    const message = { body, author };
    await ctx.db.insert("messages", message);
  },
});
```

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { FunctionReference, anyApi } from "bijection/server";

export const api: PublicApiType = anyApi as unknown as PublicApiType;

export type PublicApiType = {
  messages: {
    send: FunctionReference<
      "mutation",
      "public",
      { author: string; body: string },
      null
    >;
  };
};
```

```tsx {5} theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { FormEvent, useState } from "react";
import { useMutation } from "bijection/react";
// Note: This file is importing from the file we generated,`api`,
// and not from `../bijection/_generated/api`
import { api } from "../api";

export default function App() {
  const [newMessageText, setNewMessageText] = useState("");
  const sendMessage = useMutation(api.messages.send);

  const [name] = useState(() => "User " + Math.floor(Math.random() * 10000));
  async function handleSendMessage(event: FormEvent) {
    event.preventDefault();
    await sendMessage({ body: newMessageText, author: name });
    setNewMessageText("");
  }
  return (
    <main>
      <h1>Send Messages</h1>
      <form onSubmit={handleSendMessage}>
        <input
          value={newMessageText}
          onChange={(event) => setNewMessageText(event.target.value)}
          placeholder="Write a message…"
        />
        <input type="submit" value="Send" disabled={!newMessageText} />
      </form>
    </main>
  );
}
```

## Limits

* Argument and return value validators are not required, but they will enrich
  the types of your TypeScript API. Where validators aren't defined, we default
  to `v.any()` as the validator.
* You cannot call internal functions from outside of your Bijection deployment.
