import { Expand } from "../type_utils.js"; import { GenericId } from "./index.js"; import { GenericValidator, ObjectType } from "./validator.js"; import { JSONValue } from "./value.js"; type TableNameFromType = T extends GenericId ? TableName : string; /** * Avoid using `instanceof BaseValidator`; this is inheritence for code reuse * not type heirarchy. */ declare abstract class BaseValidator { /** * Only for TypeScript, the TS type of the JS values validated * by this validator. */ readonly type: Type; /** * Only for TypeScript, if this an Object validator, then * this is the TS type of its property names. */ readonly fieldPaths: FieldPaths; /** * Whether this is an optional Object property value validator. */ readonly isOptional: IsOptional; /** * Always `"true"`. */ readonly isConvexValidator: true; constructor({ isOptional }: { isOptional: IsOptional; }); } /** * The type of the `v.id(tableName)` validator. */ export declare class VId extends BaseValidator { /** * The name of the table that the validated IDs must belong to. */ readonly tableName: TableNameFromType; /** * The kind of validator, `"id"`. */ readonly kind: "id"; /** * Usually you'd use `v.id(tableName)` instead. */ constructor({ isOptional, tableName, }: { isOptional: IsOptional; tableName: TableNameFromType; }); } /** * The type of the `v.float64()` validator. */ export declare class VFloat64 extends BaseValidator { /** * The kind of validator, `"float64"`. */ readonly kind: "float64"; } /** * The type of the `v.int64()` validator. */ export declare class VInt64 extends BaseValidator { /** * The kind of validator, `"int64"`. */ readonly kind: "int64"; } /** * The type of the `v.boolean()` validator. */ export declare class VBoolean extends BaseValidator { /** * The kind of validator, `"boolean"`. */ readonly kind: "boolean"; } /** * The type of the `v.bytes()` validator. */ export declare class VBytes extends BaseValidator { /** * The kind of validator, `"bytes"`. */ readonly kind: "bytes"; } /** * The type of the `v.string()` validator. */ export declare class VString extends BaseValidator { /** * The kind of validator, `"string"`. */ readonly kind: "string"; } /** * The type of the `v.null()` validator. */ export declare class VNull extends BaseValidator { /** * The kind of validator, `"null"`. */ readonly kind: "null"; } /** * The type of the `v.any()` validator. */ export declare class VAny extends BaseValidator { /** * The kind of validator, `"any"`. */ readonly kind: "any"; } /** * The type of the `v.object()` validator. */ export declare class VObject, IsOptional extends OptionalProperty = "required", FieldPaths extends string = { [Property in keyof Fields]: JoinFieldPaths | Property; }[keyof Fields] & string> extends BaseValidator { /** * An object with the validator for each property. */ readonly fields: Fields; /** * The kind of validator, `"object"`. */ readonly kind: "object"; /** * Usually you'd use `v.object({ ... })` instead. */ constructor({ isOptional, fields, }: { isOptional: IsOptional; fields: Fields; }); /** * Create a new VObject with the specified fields omitted. * @param fields The field names to omit from this VObject. */ omit(...fields: K[]): VObject>, Expand>, IsOptional>; /** * Create a new VObject with only the specified fields. * @param fields The field names to pick from this VObject. */ pick(...fields: K[]): VObject>>, Expand>, IsOptional>; /** * Create a new VObject with all fields marked as optional. */ partial(): VObject<{ [K in keyof Type]?: Type[K]; }, { [K in keyof Fields]: VOptional; }, IsOptional>; /** * Create a new VObject with additional fields merged in. * @param fields An object with additional validators to merge into this VObject. */ extend>(fields: NewFields): VObject>, Expand, IsOptional>; } /** * The type of the `v.literal()` validator. */ export declare class VLiteral extends BaseValidator { /** * The value that the validated values must be equal to. */ readonly value: Type; /** * The kind of validator, `"literal"`. */ readonly kind: "literal"; /** * Usually you'd use `v.literal(value)` instead. */ constructor({ isOptional, value }: { isOptional: IsOptional; value: Type; }); } /** * The type of the `v.array()` validator. */ export declare class VArray, IsOptional extends OptionalProperty = "required"> extends BaseValidator { /** * The validator for the elements of the array. */ readonly element: Element; /** * The kind of validator, `"array"`. */ readonly kind: "array"; /** * Usually you'd use `v.array(element)` instead. */ constructor({ isOptional, element, }: { isOptional: IsOptional; element: Element; }); } /** * The type of the `v.record()` validator. */ export declare class VRecord, Value extends Validator, IsOptional extends OptionalProperty = "required", FieldPaths extends string = string> extends BaseValidator { /** * The validator for the keys of the record. */ readonly key: Key; /** * The validator for the values of the record. */ readonly value: Value; /** * The kind of validator, `"record"`. */ readonly kind: "record"; /** * Usually you'd use `v.record(key, value)` instead. */ constructor({ isOptional, key, value, }: { isOptional: IsOptional; key: Key; value: Value; }); } /** * The type of the `v.union()` validator. */ export declare class VUnion[], IsOptional extends OptionalProperty = "required", FieldPaths extends string = T[number]["fieldPaths"]> extends BaseValidator { /** * The array of validators, one of which must match the value. */ readonly members: T; /** * The kind of validator, `"union"`. */ readonly kind: "union"; /** * Usually you'd use `v.union(...members)` instead. */ constructor({ isOptional, members }: { isOptional: IsOptional; members: T; }); } export type VOptional> = T extends VId ? VId : T extends VString ? VString : T extends VFloat64 ? VFloat64 : T extends VInt64 ? VInt64 : T extends VBoolean ? VBoolean : T extends VNull ? VNull : T extends VAny ? VAny : T extends VLiteral ? VLiteral : T extends VBytes ? VBytes : T extends VObject ? VObject : T extends VArray ? VArray : T extends VRecord ? VRecord : T extends VUnion ? VUnion : never; /** * Type representing whether a property in an object is optional or required. * * @public */ export type OptionalProperty = "optional" | "required"; /** * A validator for a Convex value. * * This should be constructed using the validator builder, {@link v}. * * A validator encapsulates: * - The TypeScript type of this value. * - Whether this field should be optional if it's included in an object. * - The TypeScript type for the set of index field paths that can be used to * build indexes on this value. * - A JSON representation of the validator. * * Specific types of validators contain additional information: for example * an `ArrayValidator` contains an `element` property with the validator * used to validate each element of the list. Use the shared 'kind' property * to identity the type of validator. * * More validators can be added in future releases so an exhaustive * switch statement on validator `kind` should be expected to break * in future releases of Convex. * * @public */ export type Validator = VId | VString | VFloat64 | VInt64 | VBoolean | VNull | VAny | VLiteral | VBytes | VObject>, IsOptional, FieldPaths> | VArray, IsOptional> | VRecord, Validator, IsOptional, FieldPaths> | VUnion[], IsOptional, FieldPaths>; /** * Join together two index field paths. * * This is used within the validator builder, {@link v}. * @public */ export type JoinFieldPaths = `${Start}.${End}`; export type ObjectFieldType = { fieldType: ValidatorJSON; optional: boolean; }; export type ValidatorJSON = { type: "null"; } | { type: "number"; } | { type: "bigint"; } | { type: "boolean"; } | { type: "string"; } | { type: "bytes"; } | { type: "any"; } | { type: "literal"; value: JSONValue; } | { type: "id"; tableName: string; } | { type: "array"; value: ValidatorJSON; } | { type: "record"; keys: RecordKeyValidatorJSON; values: RecordValueValidatorJSON; } | { type: "object"; value: Record; } | { type: "union"; value: ValidatorJSON[]; }; export type RecordKeyValidatorJSON = { type: "string"; } | { type: "id"; tableName: string; } | { type: "union"; value: RecordKeyValidatorJSON[]; }; export type RecordValueValidatorJSON = ObjectFieldType & { optional: false; }; export {}; //# sourceMappingURL=validators.d.ts.map