Skip to content

Commit

Permalink
feat: setup createStub function
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniAkash committed Feb 8, 2024
1 parent 30d7d32 commit 3b328c2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/client/auth/register.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AuthorizedStub, RetryStub } from "./stub";

// Interface equivalent to V2Stub abstract class
export interface V2Stub {
// This interface will be extended by other interfaces
}
export type V2Stub = AuthorizedStub | RetryStub;

// Interface equivalent to RpcCallable abstract class
export interface RpcCallable {
Expand Down
23 changes: 23 additions & 0 deletions src/client/auth/stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,26 @@ export class RetryStub extends AuthorizedStub {
throw new Error("Max retry attempts reached");
}
}

export function createStub(
authHelper: ClarifaiAuthHelper,
maxRetryAttempts: number = 10,
): AuthorizedStub | RetryStub {
/*
Create client stub that handles authorization and basic retries for
unavailable or throttled connections.
Args:
authHelper: ClarifaiAuthHelper to use for auth metadata (default: from env)
maxRetryAttempts: max attempts to retry RPCs with retryable failures
*/

// Assuming AuthorizedStub's constructor can handle a null authHelper by defaulting internally or through another mechanism
const stub: AuthorizedStub = new AuthorizedStub(authHelper);

if (maxRetryAttempts > 0) {
return new RetryStub(authHelper, maxRetryAttempts);
}

return stub;
}

0 comments on commit 3b328c2

Please sign in to comment.