-
Notifications
You must be signed in to change notification settings - Fork 890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Vertex GA] Rewrite Schema #8479
Conversation
|
Size Report 1Affected Products
Test Logs |
Size Analysis Report 1Affected Products
Test Logs |
} | ||
|
||
/** Converts class to a plain JSON object (not a string). */ | ||
toJSON(): Record<string, unknown> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we name this toJSON()
if it returns a plain JS object? Is this an API requirement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the best name is - this is an intermediate object between the very abstract Schema, where all the children are Schemas, and a JSON string - it's a plain JS object or POJO, could call it toPOJO()
? I have this instead of going straight to the stringified JSON because it's easier to inspect and debug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I was wrong, toJSON() actually should not return a JSON string, it should in fact return a JS symbol that is ready to pass to JSON.stringify(). Changing this back. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#tojson_behavior
@@ -34,15 +34,15 @@ export class VertexAIError extends FirebaseError { | |||
*/ | |||
constructor( | |||
readonly code: VertexAIErrorCode, | |||
readonly message: string, | |||
message: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I know I reviewed this already, but is there a reason that this isn't readonly anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good question, I was going to mention it in the description. If it's readonly it can't be overwritten by super() which was causing some unexpected behavior. super() at the bottom of the constructor sets message
to fullMessage (adds the service name and code) but it simply won't do anything if it's readonly. The next question would be, what about code
- it's ok for code to not be overwritten with fullCode because adding the prefix just makes it harder to compare (e.g. error.code === VertexAIErrorCode.SOME_CODE
). The formatted fullCode
. only needs to go into the message.
See https://docs.google.com/document/d/1CXRbH7zmKqupD5LWUq8dh3spsGpozfRbOUa5MWi2tVY/edit?tab=t.wiordux8zots (internal)
Rewriting Schema as a class with static methods to enable easier building and some validation.
This is mostly backwards compatible - functionDeclaration.parameters takes an ObjectSchemaInterface which could be the ObjectSchema class or just a JS object that matches the interface. The only breaking change is the FunctionDeclarationSchemaType enum is now named SchemaType.
Keeping validation minimal as (1) TS should handle a lot of it and even if TS checking doesn't extend to JS-only developers, we don't really want to duplicate efforts with TS, (2) not a lot of rules have strong enough confirmation/guarantees from the backend for us to be sure enough to throw errors.