#How to get Doc<tablename> (document type) of a table in a second repository?

4 messages · Page 1 of 1 (latest)

feral quarry
#

Given that the second repo only has a ts-spec-api generated file to understand all APIs, what needs to be done to the model object type of different documents?

void shardBOT
#

Hi @feral quarry. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

To get the Doc<tablename> (document type) of a table in a second repository using the ts-spec-api generated file, you can follow these steps:

  1. First, make sure you have generated the TypeScript API specification file using the convex-helpers package in your main repository. Run the following command:
npx convex-helpers ts-api-spec

This will generate an api.ts file containing the type information for your Convex functions and data model.

  1. Copy the generated api.ts file to your second repository.

  2. In your second repository, you can now import the necessary types from the api.ts file. To get the Doc<tablename> type, you'll need to use the DocumentByName type alias. Here's how you can do it:

import { PublicApiType } from "./api";
import { DocumentByName } from "convex/server";

// Replace 'tablename' with the actual name of your table
type MyTableDoc = DocumentByName<PublicApiType, "tablename">;

This approach allows you to get the document type for a specific table in your second repository.

It's important to note that for this to work correctly, you need to ensure that your Convex functions in the main repository have proper argument and return value validators defined. Without these validators, the generated types may not be as precise or useful.

For more detailed information on this process, you can refer to the following resources:

  1. Convex in Multiple Repositories
  2. End-to-end TypeScript with Convex
#

Remember to keep your api.ts file up to date in the second repository whenever you make changes to your Convex functions or schema in the main repository.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: