Skip to content

Commit

Permalink
Mark asyncIter-originated fetchPage calls
Browse files Browse the repository at this point in the history
  • Loading branch information
bryantpark04 committed Jul 12, 2024
1 parent 5d4c562 commit a1a7a69
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/client.api/src/objectSet/ObjectSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface MinimalObjectSet<Q extends ObjectOrInterfaceDefinition>
S extends NullabilityAdherence = NullabilityAdherenceDefault,
>(
args?: FetchPageArgs<Q, L, R, A, S>,
calledByAsyncIter?: boolean,
) => Promise<FetchPageResult<Q, L, R, S>>;

fetchPageWithErrors: <
Expand Down
19 changes: 17 additions & 2 deletions packages/client/src/object/fetchPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import type {
import { OntologiesV2 } from "@osdk/internal.foundry";
import type { MinimalClient } from "../MinimalClientContext.js";
import { addUserAgentAndRequestContextHeaders } from "../util/addUserAgentAndRequestContextHeaders.js";
import { augmentRequestContext } from "../util/augmentRequestContext.js";
import { convertWireToOsdkObjects } from "./convertWireToOsdkObjects.js";

export function augment<
Expand Down Expand Up @@ -129,11 +130,25 @@ export async function fetchPageInternal<
objectType: Q,
objectSet: ObjectSet,
args: FetchPageArgs<Q, L, R, A, S> = {},
calledByAsyncIter: boolean = false,
): Promise<FetchPageResult<Q, L, R, S>> {
const modifiedClient = calledByAsyncIter
? augmentRequestContext(client, _ => ({ finalMethodCall: "asyncIter" }))
: client;
if (objectType.type === "interface") {
return await fetchInterfacePage(client, objectType, args, objectSet) as any; // fixme
return await fetchInterfacePage(
modifiedClient,
objectType,
args,
objectSet,
) as any; // fixme
} else {
return await fetchObjectPage(client, objectType, args, objectSet) as any; // fixme
return await fetchObjectPage(
modifiedClient,
objectType,
args,
objectSet,
) as any; // fixme
}
}

Expand Down
3 changes: 1 addition & 2 deletions packages/client/src/objectSet/createObjectSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ export function createObjectSet<Q extends ObjectOrInterfaceDefinition>(
asyncIter: async function*(): AsyncIterableIterator<Osdk<Q, "$all">> {
let $nextPageToken: string | undefined = undefined;
do {
// TODO: figure out how to mark asyncIter-originated fetchPage requests
const result = await base.fetchPage({ $nextPageToken });
const result = await base.fetchPage({ $nextPageToken }, true);

for (const obj of result.data) {
yield obj as Osdk<Q, "$all">;
Expand Down

0 comments on commit a1a7a69

Please sign in to comment.