collectionConfigToVexSchema
collectionConfigToVexSchema(
props):string
Defined in: packages/core/src/collections/validator.ts:161
Converts a resolved CollectionConfig to a Convex defineTable(...) source string.
Iterates the collection’s fields, builds each field’s Convex validator via
adminFieldToValidator, and appends index chains:
.index()for every indexresolveCollectionIndexesresolves — field-level indexes may be compound, and win over a collection-level entry of the same name.searchIndex()for fields declaring their ownfield.searchIndex- a
.searchIndex(...)foruseAsTitleauto-generated when another collection has a relationship pointing HERE, viaresolveTitleSearchIndex— reuses theuseAsTitlefield’s ownsearchIndexname when it has one, generatessearch_<useAsTitle>when it doesn’t, and is omitted entirely whenuseAsTitleis a Convex system field or a non-searchable field type
Parameters
Section titled “Parameters”Input props.
collection
Section titled “collection”The resolved collection definition to convert.
config
Section titled “config”The full resolved VexCMS config, needed for cross-collection relationship detection.
Returns
Section titled “Returns”string
A TypeScript source string declaring the Convex table.
Example
Section titled “Example”const posts = defineCollection({ slug: "posts", fields: { author: relationship({ collection: "authors", required: true }) },});collectionConfigToVexSchema({ collection: posts, config });// → 'export const posts = defineTable({...})\n\t.index("by_author", ["author"])'
@see {@link generateVexSchema} for the full-file generator that wraps this function@see {@link getIncomingRelationships} for the cross-collection helper@see {@link resolveTitleSearchIndex} for the `useAsTitle` index-name resolution rule