feat(functions): Implement TaskQueue Scopes#3210
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new FunctionScope type to represent the scope of a function in a task queue, deprecating the legacy extensionId string parameter. It updates FunctionsApiClient, Functions, and TaskQueue to support these scopes (including current, global, extension, and internal kit scopes) with fallback logic for migration, and adds comprehensive unit tests. The review feedback highlights a few issues and improvement opportunities: correcting a typo ('peformance') and an invalid scope value ({ scope: "self" } instead of { scope: "current" }) in warning messages (and their corresponding tests), removing a redundant type check in TaskQueue, and improving type safety in FunctionsApiClient by avoiding an as any cast through discriminated union narrowing.
lahirumaramba
left a comment
There was a problem hiding this comment.
Thank you for submitting this!
LGTM! Added a couple of comments.
| * @param id - The ID of the task to delete. | ||
| * @param functionName - The function name of the queue. | ||
| * @param extensionId - Optional canonical ID of the extension. | ||
| * @param scope - Optional FunctionScope configuration. |
There was a problem hiding this comment.
Could we get a TW review on these new docstrings, please?
There was a problem hiding this comment.
This looks like a literal, FunctionScope. Though, would just "function scope" work as a common noun/general term?
See bottom note here: https://docs.google.com/presentation/d/1Ezb4sp4XD6ItHISccnME-EVH_oJj59R5Naq0IskLrAo/edit?slide=id.g1cd7eabb964_0_10#slide=id.g1cd7eabb964_0_10
…fety and signature simplification
egilmorez
left a comment
There was a problem hiding this comment.
Thanks, I do have some nits! :)
| * @param id - The ID of the task to delete. | ||
| * @param functionName - The function name of the queue. | ||
| * @param extensionId - Optional canonical ID of the extension. | ||
| * @param scope - Optional FunctionScope configuration. |
There was a problem hiding this comment.
This looks like a literal, FunctionScope. Though, would just "function scope" work as a common noun/general term?
See bottom note here: https://docs.google.com/presentation/d/1Ezb4sp4XD6ItHISccnME-EVH_oJj59R5Naq0IskLrAo/edit?slide=id.g1cd7eabb964_0_10#slide=id.g1cd7eabb964_0_10
| * @param data - The data payload of the task. | ||
| * @param functionName - The functionName of the queue. | ||
| * @param extensionId - Optional canonical ID of the extension. | ||
| * @param scope - Optional FunctionScope configuration. |
| @@ -132,10 +140,15 @@ export class FunctionsApiClient { | |||
| * | |||
| * @param data - The data payload of the task. | |||
| * @param functionName - The functionName of the queue. | |||
There was a problem hiding this comment.
Should be either functionName or just "function name."
Better yet, more words might make it all more clear. Is it the name of the function associated with the queue, or some even better verb than "associate?"
| * | ||
| * @param functionName - The name of the function. | ||
| * @param extensionId - Optional Firebase extension ID. | ||
| * @param scope - Optional FunctionScope configuration. Only needed if targeting a scope other than the current one. |
There was a problem hiding this comment.
I think this should be FunctionScope with code font for the literal.
| * @param functionName - The name of the function. | ||
| * @param client - The `FunctionsApiClient` instance. | ||
| * @param extensionId - Optional canonical ID of the extension. | ||
| * @param scope - Optional FunctionScope configuration. Only needed if targeting a scope other than the current one. |
There was a problem hiding this comment.
Same as above RE literal.
| /** | ||
| * @param functionName - The name of the function. | ||
| * @param client - The `FunctionsApiClient` instance. | ||
| * @param extensionIdOrScope - Optional canonical ID of the extension or FunctionScope. |
| }).not.to.throw(); | ||
| }); | ||
|
|
||
| it('should not throw given a valid scope object: current', () => { |
There was a problem hiding this comment.
LMK if these "it('...." comments are public. I think they are not.
Description
This PR introduces Task Queue Scopes to the Firebase Admin SDK functions module. It decouples the legacy backward-compatible string-to-scope migration logic from the stateless client and isolates it inside the API wrapper layer (
TaskQueue).Key Changes
TaskQueue):TaskQueue.enqueue()anddelete()now capture404errors for legacy string parameters ('extensionOrKit'scope).404error, they automatically retry using a temporarykitscope.'kit'and logs a legacy targeting warning.process.env.EXT_INSTANCE_IDandprocess.env.KIT_INSTANCE_IDat construction time.'extension'or'kit', bypassing unnecessary404fallback call roundtrips.scoperesolves to global if no environment variables are set.