From d70642963dc0976e687873374d70f73e4315e2cc Mon Sep 17 00:00:00 2001 From: Moshe Dicker Date: Wed, 5 Nov 2025 10:11:25 -0500 Subject: [PATCH 1/2] Add name to object validator --- npm-packages/convex/src/values/validator.ts | 5 +++-- npm-packages/convex/src/values/validators.ts | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/npm-packages/convex/src/values/validator.ts b/npm-packages/convex/src/values/validator.ts index 8d988fc10..33129f094 100644 --- a/npm-packages/convex/src/values/validator.ts +++ b/npm-packages/convex/src/values/validator.ts @@ -166,9 +166,10 @@ export const v = { /** * Validates that the value is an Object with the given properties. * @param fields An object specifying the validator for each property. + * @param name An optional name for this object validator. */ - object: (fields: T) => { - return new VObject, T>({ isOptional: "required", fields }); + object: (fields: T, name?: string|undefined) => { + return new VObject, T>({ isOptional: "required", fields, name }); }, /** diff --git a/npm-packages/convex/src/values/validators.ts b/npm-packages/convex/src/values/validators.ts index 6156dbecf..3c3b62d90 100644 --- a/npm-packages/convex/src/values/validators.ts +++ b/npm-packages/convex/src/values/validators.ts @@ -286,15 +286,22 @@ export class VObject< */ readonly kind = "object" as const; + /** + * A name for this object. + */ + readonly name: string|undefined; + /** * Usually you'd use `v.object({ ... })` instead. */ constructor({ isOptional, fields, + name, }: { isOptional: IsOptional; fields: Fields; + name: string|undefined; }) { super({ isOptional }); globalThis.Object.values(fields).forEach((v) => { @@ -303,6 +310,7 @@ export class VObject< } }); this.fields = fields; + this.name = name; } /** @internal */ get json(): ValidatorJSON { @@ -317,6 +325,7 @@ export class VObject< }, ]), ), + name: this.name, }; } /** @internal */ @@ -324,6 +333,7 @@ export class VObject< return new VObject({ isOptional: "optional", fields: this.fields, + name: this.name, }); } } @@ -660,7 +670,7 @@ export type ValidatorJSON = keys: RecordKeyValidatorJSON; values: RecordValueValidatorJSON; } - | { type: "object"; value: Record } + | { type: "object"; value: Record, name: string|undefined } | { type: "union"; value: ValidatorJSON[] }; export type RecordKeyValidatorJSON = From cf2cbe92f83c29fecf3c6fdd40c87852a07fe2d0 Mon Sep 17 00:00:00 2001 From: Moshe Dicker Date: Wed, 5 Nov 2025 10:15:54 -0500 Subject: [PATCH 2/2] update object name parameter --- npm-packages/convex/src/values/validator.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/npm-packages/convex/src/values/validator.ts b/npm-packages/convex/src/values/validator.ts index 33129f094..83d43beb1 100644 --- a/npm-packages/convex/src/values/validator.ts +++ b/npm-packages/convex/src/values/validator.ts @@ -165,11 +165,14 @@ export const v = { /** * Validates that the value is an Object with the given properties. - * @param fields An object specifying the validator for each property. - * @param name An optional name for this object validator. + * @param options Optional configuration for this object validator. + * @param options.name An optional name for this object validator. */ - object: (fields: T, name?: string|undefined) => { - return new VObject, T>({ isOptional: "required", fields, name }); + object: ( + fields: T, + options?: { name?: string | undefined }, + ) => { + return new VObject, T>({ isOptional: "required", fields, name: options?.name }); }, /**