convex
Version:
Client for the Convex Cloud
152 lines • 5.37 kB
TypeScript
import { Value } from "../values/index.js";
/**
* A document stored in Convex.
* @public
*/
export declare type GenericDocument = Record<string, Value>;
/**
* A type describing all of the document fields in a table.
*
* These can either be field names (like "name") or references to fields on
* nested objects (like "properties.name").
* @public
*/
export declare type GenericFieldPaths = string;
/**
* A type describing the ordered fields in an index.
*
* These can either be field names (like "name") or references to fields on
* nested objects (like "properties.name").
* @public
*/
export declare type GenericIndexFields = string[];
/**
* A type describing the indexes in a table.
*
* It's an object mapping each index name to the fields in the index.
* @public
*/
export declare type GenericTableIndexes = Record<string, GenericIndexFields>;
/**
* A type describing the configuration of a search index.
* @public
*/
export declare type GenericSearchIndexConfig = {
searchField: string;
filterFields: string;
};
/**
* A type describing all of the search indexes in a table.
*
* This is an object mapping each index name to the config for the index.
* @public
*/
export declare type GenericTableSearchIndexes = Record<string, GenericSearchIndexConfig>;
/**
* The type of a field in a document.
*
* Note that this supports both simple fields like "name" and nested fields like
* "properties.name".
*
* If the field is not present in the document it is considered to be `null`.
*
* @public
*/
export declare type FieldTypeFromFieldPath<Document extends GenericDocument, FieldPath extends string> = FieldPath extends `${infer First}.${infer Second}` ? First extends keyof Document ? Document[First] extends GenericDocument ? FieldTypeFromFieldPath<Document[First], Second> : null : null : FieldPath extends keyof Document ? Document[FieldPath] : null;
/**
* A type describing the document type and indexes in a table.
* @public
*/
export declare type GenericTableInfo = {
document: GenericDocument;
fieldPaths: GenericFieldPaths;
indexes: GenericTableIndexes;
searchIndexes: GenericTableSearchIndexes;
};
/**
* The type of a document in a table for a given {@link GenericTableInfo}.
* @public
*/
export declare type DocumentByInfo<TableInfo extends GenericTableInfo> = TableInfo["document"];
/**
* The field paths in a table for a given {@link GenericTableInfo}.
*
* These can either be field names (like "name") or references to fields on
* nested objects (like "properties.name").
* @public
*/
export declare type FieldPaths<TableInfo extends GenericTableInfo> = TableInfo["fieldPaths"];
/**
* The database indexes in a table for a given {@link GenericTableInfo}.
*
* This will be an object mapping index names to the fields in the index.
* @public
*/
export declare type Indexes<TableInfo extends GenericTableInfo> = TableInfo["indexes"];
/**
* The names of indexes in a table for a given {@link GenericTableInfo}.
* @public
*/
export declare type IndexNames<TableInfo extends GenericTableInfo> = keyof Indexes<TableInfo>;
/**
* Extract the fields of an index from a {@link GenericTableInfo} by name.
* @public
*/
export declare type NamedIndex<TableInfo extends GenericTableInfo, IndexName extends IndexNames<TableInfo>> = Indexes<TableInfo>[IndexName];
/**
* The search indexes in a table for a given {@link GenericTableInfo}.
*
* This will be an object mapping index names to the search index config.
* @public
*/
export declare type SearchIndexes<TableInfo extends GenericTableInfo> = TableInfo["searchIndexes"];
/**
* The names of search indexes in a table for a given {@link GenericTableInfo}.
* @public
*/
export declare type SearchIndexNames<TableInfo extends GenericTableInfo> = keyof SearchIndexes<TableInfo>;
/**
* Extract the fields of an index from a {@link GenericTableInfo} by name.
* @public
*/
export declare type NamedSearchIndex<TableInfo extends GenericTableInfo, IndexName extends SearchIndexNames<TableInfo>> = SearchIndexes<TableInfo>[IndexName];
/**
* A type describing the tables in a Convex project.
*
* This is designed to be code generated with `npx convex codegen`.
* @public
*/
export declare type GenericDataModel = Record<string, GenericTableInfo>;
/**
* A {@link GenericDataModel} that considers documents to be `any` and does not
* support indexes.
*
* This is the default before a schema is defined.
* @public
*/
export declare type AnyDataModel = {
[tableName: string]: {
document: any;
fieldPaths: GenericFieldPaths;
indexes: {};
searchIndexes: {};
};
};
/**
* A type of all of the table names defined in a {@link GenericDataModel}.
* @public
*/
export declare type TableNamesInDataModel<DataModel extends GenericDataModel> = keyof DataModel & string;
/**
* Extract the `TableInfo` for a table in a {@link GenericDataModel} by table
* name.
*
* @public
*/
export declare type NamedTableInfo<DataModel extends GenericDataModel, TableName extends keyof DataModel> = DataModel[TableName];
/**
* The type of a document in a {@link GenericDataModel} by table name.
* @public
*/
export declare type DocumentByName<DataModel extends GenericDataModel, TableName extends TableNamesInDataModel<DataModel>> = DataModel[TableName]["document"];
//# sourceMappingURL=data_model.d.ts.map