-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Sessions] Add meta.size to bfetched responses #95774
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ import { | |
| createBatchedFunction, | ||
| BatchResponseItem, | ||
| ErrorLike, | ||
| BatchResultBase, | ||
| } from '../../common'; | ||
| import { fetchStreaming, split } from '../streaming'; | ||
| import { normalizeError } from '../../common'; | ||
|
|
@@ -22,7 +23,7 @@ export interface BatchedFunctionProtocolError extends ErrorLike { | |
| code: string; | ||
| } | ||
|
|
||
| export interface StreamingBatchedFunctionParams<Payload, Result> { | ||
| export interface StreamingBatchedFunctionParams<Payload, Result extends BatchResultBase> { | ||
| /** | ||
| * URL endpoint that will receive a batch of requests. This endpoint is expected | ||
| * to receive batch as a serialized JSON array. It should stream responses back | ||
|
|
@@ -56,7 +57,7 @@ export interface StreamingBatchedFunctionParams<Payload, Result> { | |
| * server using `params.fetchStreaming` in a POST request. Responses are streamed back | ||
| * and each batch item is resolved once corresponding response is received. | ||
| */ | ||
| export const createStreamingBatchedFunction = <Payload, Result extends object>( | ||
| export const createStreamingBatchedFunction = <Payload, Result extends BatchResultBase>( | ||
| params: StreamingBatchedFunctionParams<Payload, Result> | ||
| ): BatchedFunc<Payload, Result> => { | ||
| const { | ||
|
|
@@ -134,6 +135,11 @@ export const createStreamingBatchedFunction = <Payload, Result extends object>( | |
| if (response.error) { | ||
| items[response.id].future.reject(response.error); | ||
| } else if (response.result !== undefined) { | ||
| if (typeof response.result === 'object') { | ||
| response.result.meta = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't really like it that we are adding things to actual response, i would preffer to se meta information separate from actual responses. also, i think this information could be useful on the server as well, and i would really prefer to keep our server/client API as similar as possible. |
||
| size: json.length, | ||
| }; | ||
| } | ||
| items[response.id].future.resolve(response.result); | ||
| } | ||
| } catch (e) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.