convex
Version:
Client for the Convex Cloud
136 lines (128 loc) • 4.16 kB
TypeScript
/**
* Convert a Convex value to its JSON representation.
*
* Use {@link jsonToConvex} to recreate the original value.
*
* To learn more about Convex values, see [Types](https://docs.convex.dev/using/types).
*
* @param value - A Convex value to convert into JSON.
* @returns The JSON representation of `value`.
*
* @public
*/
export declare function convexToJson(value: Value): JSONValue;
/**
* An identifier for a document in Convex.
*
* Convex documents are uniquely identified by their `GenericId`, which is accessible
* on the `_id` field. To learn more, see [Data Modeling](https://docs.convex.dev/using/data-modeling).
*
* Documents can be loaded using `db.get(id)` in query and mutation functions.
*
* **Important**: Use `myId.equals(otherId)` to check for equality.
* Using `===` will not work because two different instances of `GenericId` can refer
* to the same document.
*
* `GenericId`s are 17 bytes long and consist of:
* - A 15-byte random value.
* - A 2-byte timestamp representing the document's creation, in days since the Unix epoch.
* This is encoded in base 62 ([0-9A-Za-z]).
*
* If you're using code generation, use the `Id` class typed for your data model in
* `convex/_generated/dataModel.js`.
*
* @typeParam TableName - A string literal type of the table name (like "users").
*
* @public
*/
export declare class GenericId<TableName extends string> {
/**
* The table name this {@link GenericId} references.
*/
readonly tableName: TableName;
/**
* The identifier string.
*
* This contains the characters `[0-9A-Za-z]`.
*/
readonly id: string;
constructor(tableName: TableName, id: string);
/**
* Check if this {@link GenericId} refers to the same document as another {@link GenericId}.
*
* @param other - The other {@link GenericId} to compare to.
* @returns `true` if the objects refer to the same document.
*/
equals(other: unknown): boolean;
/**
* Parse a {@link GenericId} from its JSON representation.
*/
static fromJSON(obj: any): GenericId<string>;
/**
* Convert a {@link GenericId} into its JSON representation.
*/
toJSON(): JSONValue;
/**
* Convert a {@link GenericId} into its string representation.
*
* This includes the identifier but not the table name.
*/
toString(): string;
/**
* Pretty-print this {@link GenericId} for debugging.
*/
inspect(): string;
}
/**
* Internal type used in Convex code generation.
*
* @public
*/
export declare type GenericIdConstructor<TableNames extends string> = {
new <TableName extends TableNames>(tableName: TableName, id: string): GenericId<TableName>;
prototype: GenericId<string>;
fromJSON(obj: any): GenericId<string>;
};
/**
* Parse a Convex value from its JSON representation.
*
* This function will revive classes like {@link GenericId} that have been serialized to JSON, parse out `BigInt`s, and so on.
*
* To learn more about Convex values, see [Types](https://docs.convex.dev/using/types).
*
* @param value - The JSON representation of a Convex value previously created with {@link convexToJson}.
* @returns The JavaScript representation of the Convex value.
*
* @public
*/
export declare function jsonToConvex(value: JSONValue): Value;
/**
* The type of JavaScript values serializable to JSON.
*
* @public
*/
export declare type JSONValue = null | boolean | number | string | JSONValue[] | {
[key: string]: JSONValue;
};
/**
* The types of {@link Value} that can be used to represent numbers.
*
* @public
*/
export declare type NumericValue = bigint | number;
/**
* A value supported by Convex.
*
* Values can be:
* - stored inside of documents.
* - used as arguments and return types to queries and mutation functions.
*
* You can see the full set of supported types at
* [Types](https://docs.convex.dev/using/types).
*
* @public
*/
export declare type Value = GenericId<string> | null | bigint | number | boolean | string | ArrayBuffer | Value[] | Set<Value> | Map<Value, Value> | {
[key: string]: Value;
};
export { }