-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat(functions): httpsCallable.stream support #8799
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
Open
MichaelVerdon
wants to merge
55
commits into
main
Choose a base branch
from
cloud-functions-streaming
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
3d6358a
feat(cloud_functions): httpsCallable.stream support
MichaelVerdon f20f329
feat: android impl
MichaelVerdon 87b000a
feat: typescript impl
MichaelVerdon b5aa190
feat: turbomodules impl and use correct native method for android
MichaelVerdon 2024041
feat: tests and event emission working
MichaelVerdon fe37b79
fix: tests
MichaelVerdon ff8c3b1
feat: definition tests
MichaelVerdon 9c44d18
feat: iOS impl
MichaelVerdon bb15bf4
fix: ios stream
MichaelVerdon 3560577
fix: jest
MichaelVerdon 1445156
feat: web impl
MichaelVerdon d2b94d1
feat: error handling
MichaelVerdon 0cfed52
format: js
MichaelVerdon bcf8869
fix: ts defs
MichaelVerdon a4e497d
fix: ts ignore
MichaelVerdon 6c0492f
fix: lint
MichaelVerdon 7ef1474
format: java format
MichaelVerdon 5c2c5f3
format: indentations
MichaelVerdon 65e5a5a
format: indentation
MichaelVerdon 9245d6d
format: clang
MichaelVerdon 14967b1
Merge branch 'main' into cloud-functions-streaming
MichaelVerdon 13e6b2f
fix: readd types from merge conflict fixes
MichaelVerdon b500b8d
fix(web): web types
MichaelVerdon b612452
fix: more web types
MichaelVerdon 0544303
fix: stream type
MichaelVerdon 6c81f40
feat: util mock func
MichaelVerdon 856e3b9
fix: mocking
MichaelVerdon b25f207
chore: format
MichaelVerdon b89038f
fix: android impl finished and web refactoring
MichaelVerdon 3d36554
Merge branch 'main' into cloud-functions-streaming
MichaelVerdon 66e973e
fix: define swift version in podspec
MichaelVerdon fc036de
chore: ignore clang error
MichaelVerdon bd32b12
feat: add error logging
MichaelVerdon 69ecdb6
fix: build issues
MichaelVerdon bfc3f18
Merge branch 'main' into cloud-functions-streaming
MichaelVerdon bd31336
chore: remove unneccessary timeout
MichaelVerdon 58302d6
fix: release mode build isuse
MichaelVerdon 4069444
fix: ios flags
MichaelVerdon 3ba82f5
fix: android implementation passing locally
MichaelVerdon edb93b5
fix: compiler flags
MichaelVerdon 6470b1d
fix: podspec
MichaelVerdon 4ffa0f6
fix: podspec
MichaelVerdon 0c9488a
format: java
MichaelVerdon 20a4980
fix: jest tests
MichaelVerdon 988d28c
format: js
MichaelVerdon cdc0e9c
fix: prevent timeouts on other platforms
MichaelVerdon db22a5d
fix: setnativemodule
MichaelVerdon a1ce057
fix: compiler flags
MichaelVerdon 920c424
fix: undo podfile changes in tests/
MichaelVerdon 48ebc77
fix: swift compilation
MichaelVerdon ab1c6f5
fix: listener funcs (other)
MichaelVerdon c9fab0b
fix: check before storage listener removal
MichaelVerdon ae0a742
fix: mac issues listener removal
MichaelVerdon b7bcc4f
chore: changes
MichaelVerdon a3558c1
feat: add ruby script for swift file compilation
MichaelVerdon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
205 changes: 205 additions & 0 deletions
205
.github/workflows/scripts/functions/src/testStreamingCallable.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,205 @@ | ||
| import { onCall, CallableRequest, CallableResponse } from 'firebase-functions/v2/https'; | ||
| import { logger } from 'firebase-functions/v2'; | ||
|
|
||
| /** | ||
| * Test streaming callable function that sends multiple chunks of data | ||
| * This function demonstrates Server-Sent Events (SSE) streaming | ||
| */ | ||
| export const testStreamingCallable = onCall( | ||
| async ( | ||
| req: CallableRequest<{ count?: number; delay?: number }>, | ||
| response?: CallableResponse<any>, | ||
| ) => { | ||
| const count = req.data.count || 5; | ||
| const delay = req.data.delay || 500; | ||
|
|
||
| logger.info('testStreamingCallable called', { count, delay }); | ||
|
|
||
| // Send chunks of data over time | ||
| for (let i = 0; i < count; i++) { | ||
| // Wait for the specified delay | ||
| await new Promise(resolve => setTimeout(resolve, delay)); | ||
|
|
||
| if (response) { | ||
| await response.sendChunk({ | ||
| index: i, | ||
| message: `Chunk ${i + 1} of ${count}`, | ||
| timestamp: new Date().toISOString(), | ||
| data: { | ||
| value: i * 10, | ||
| isEven: i % 2 === 0, | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| // Return final result | ||
| return { totalCount: count, message: 'Stream complete' }; | ||
| }, | ||
| ); | ||
|
|
||
| /** | ||
| * Test streaming callable that sends progressive updates | ||
| */ | ||
| export const testProgressStream = onCall( | ||
| async ( | ||
| req: CallableRequest<{ task?: string }>, | ||
| response?: CallableResponse<any>, | ||
| ) => { | ||
| const task = req.data.task || 'Processing'; | ||
|
|
||
| logger.info('testProgressStream called', { task }); | ||
|
|
||
| const updates = [ | ||
| { progress: 0, status: 'Starting...', task }, | ||
| { progress: 25, status: 'Loading data...', task }, | ||
| { progress: 50, status: 'Processing data...', task }, | ||
| { progress: 75, status: 'Finalizing...', task }, | ||
| { progress: 100, status: 'Complete!', task }, | ||
| ]; | ||
|
|
||
| for (const update of updates) { | ||
| await new Promise(resolve => setTimeout(resolve, 300)); | ||
| if (response) { | ||
| await response.sendChunk(update); | ||
| } | ||
| } | ||
|
|
||
| return { success: true }; | ||
| }, | ||
| ); | ||
|
|
||
| /** | ||
| * Test streaming with complex data types | ||
| */ | ||
| export const testComplexDataStream = onCall( | ||
| async (req: CallableRequest, response?: CallableResponse<any>) => { | ||
| logger.info('testComplexDataStream called'); | ||
|
|
||
| const items = [ | ||
| { | ||
| id: 1, | ||
| name: 'Item One', | ||
| tags: ['test', 'streaming', 'firebase'], | ||
| metadata: { | ||
| created: new Date().toISOString(), | ||
| version: '1.0.0', | ||
| }, | ||
| }, | ||
| { | ||
| id: 2, | ||
| name: 'Item Two', | ||
| tags: ['react-native', 'functions'], | ||
| metadata: { | ||
| created: new Date().toISOString(), | ||
| version: '1.0.1', | ||
| }, | ||
| }, | ||
| { | ||
| id: 3, | ||
| name: 'Item Three', | ||
| tags: ['cloud', 'streaming'], | ||
| metadata: { | ||
| created: new Date().toISOString(), | ||
| version: '2.0.0', | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
| // Stream each item individually | ||
| for (const item of items) { | ||
| await new Promise(resolve => setTimeout(resolve, 200)); | ||
| if (response) { | ||
| await response.sendChunk(item); | ||
| } | ||
| } | ||
|
|
||
| // Return summary | ||
| return { | ||
| summary: { | ||
| totalItems: items.length, | ||
| processedAt: new Date().toISOString(), | ||
| }, | ||
| }; | ||
| }, | ||
| ); | ||
|
|
||
| /** | ||
| * Test streaming with error handling | ||
| */ | ||
| export const testStreamWithError = onCall( | ||
| async ( | ||
| req: CallableRequest<{ shouldError?: boolean; errorAfter?: number }>, | ||
| response?: CallableResponse<any>, | ||
| ) => { | ||
| const shouldError = req.data.shouldError !== false; | ||
| const errorAfter = req.data.errorAfter || 2; | ||
|
|
||
| logger.info('testStreamWithError called', { shouldError, errorAfter }); | ||
|
|
||
| for (let i = 0; i < 5; i++) { | ||
| if (shouldError && i === errorAfter) { | ||
| throw new Error('Simulated streaming error after chunk ' + errorAfter); | ||
| } | ||
|
|
||
| await new Promise(resolve => setTimeout(resolve, 300)); | ||
| if (response) { | ||
| await response.sendChunk({ | ||
| chunk: i, | ||
| message: `Processing chunk ${i + 1}`, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| success: true, | ||
| message: 'All chunks processed successfully', | ||
| }; | ||
| }, | ||
| ); | ||
|
|
||
| /** | ||
| * Test streaming callable that returns the type of data sent | ||
| * Similar to Dart's testStreamResponse - sends back the type of input data | ||
| */ | ||
| export const testStreamResponse = onCall( | ||
| async (req: CallableRequest<any>, response?: CallableResponse<any>) => { | ||
| logger.info('testStreamResponse called', { data: req.data }); | ||
|
|
||
| // Determine the type of the input data | ||
| let partialData: string; | ||
| if (req.data === null || req.data === undefined) { | ||
| partialData = 'null'; | ||
| } else if (typeof req.data === 'string') { | ||
| partialData = 'string'; | ||
| } else if (typeof req.data === 'number') { | ||
| partialData = 'number'; | ||
| } else if (typeof req.data === 'boolean') { | ||
| partialData = 'boolean'; | ||
| } else if (Array.isArray(req.data)) { | ||
| partialData = 'array'; | ||
| } else if (typeof req.data === 'object') { | ||
| // For deep maps, check if it has the expected structure | ||
| if (req.data.type === 'deepMap' && req.data.inputData) { | ||
| partialData = req.data.inputData; | ||
| } else { | ||
| partialData = 'object'; | ||
| } | ||
| } else { | ||
| partialData = 'unknown'; | ||
| } | ||
|
|
||
| // Send chunk with the type information | ||
| if (response) { | ||
| await response.sendChunk({ | ||
| partialData, | ||
| }); | ||
| } | ||
|
|
||
| // Return final result | ||
| return { | ||
| partialData, | ||
| type: typeof req.data, | ||
| }; | ||
| }, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is there some explanation of what's going on here - that is, what 'C++ dependency scanner issues' exactly are being avoided, and is there some upstream issue logged?
This looks like an awful (tempted to say unacceptable really) developer experience to require library consumers to do a Podfile modification just to use this functions module after this. It implies more manual integration steps to document and answer issues for as well as some sort of Expo plugin that will need to be created and maintained
Especially if it's just because of using some Swift, when we are certainly not the first module to use Swift vs Objective-C 🤔
Additionally, there is some infra in react-native itself to run things that may help, for instance there is an ability to add things to build phases so scripts can run
If there truly is some insurmountable problem with the Obj-C++/Swift interop then perhaps the whole module could be ported to Swift - effort-wise that would probably be similar to the effort to correctly document this, answer the integration failure issues over time, and make the expo plugin
Basically, we need to do anything we can to avoid this