#How to get Doc<tablename> (document type) of a table in a second repository?
4 messages · Page 1 of 1 (latest)
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:
- First, make sure you have generated the TypeScript API specification file using the
convex-helperspackage 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.
-
Copy the generated
api.tsfile to your second repository. -
In your second repository, you can now import the necessary types from the
api.tsfile. To get theDoc<tablename>type, you'll need to use theDocumentByNametype 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: