Skip to content

Commit

Permalink
refactor: update fetcher interface to support retries
Browse files Browse the repository at this point in the history
  • Loading branch information
aleortega committed May 5, 2023
1 parent 22f0edb commit cb8324b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
12 changes: 10 additions & 2 deletions etc/interfaces.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ export interface IDatabase {
query<T extends Record<string, any>>(sql: string): Promise<IDatabase.IQueryResult<T>>;
}

// @alpha (undocumented)
// @public (undocumented)
export type IFetchComponent = {
fetch(url: fetch_2.Request): Promise<fetch_2.Response>;
fetch(url: fetch_2.RequestInfo, init?: fetch_2.RequestInit): Promise<fetch_2.Response>;
fetch(url: fetch_2.RequestInfo, init?: RequestOptions): Promise<fetch_2.Response>;
};

// @alpha (undocumented)
Expand Down Expand Up @@ -372,6 +372,14 @@ export namespace Lifecycle {
export function run<Components extends Record<string, any>>(config: ProgramConfig<Components>): PromiseLike<ComponentBasedProgram<Components>>;
}

// @public (undocumented)
export type RequestOptions = fetch_2.RequestInit & {
abortController?: AbortController;
timeout?: number;
attempts?: number;
retryDelay?: number;
};

// @public (undocumented)
export type Trace = Pick<TraceContext, "traceId" | "version" | "parentId" | "traceFlags">;

Expand Down
16 changes: 13 additions & 3 deletions src/components/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import * as fetch from "node-fetch"

/**
* @alpha
* @public
*/
export type RequestOptions = fetch.RequestInit & {
abortController?: AbortController
timeout?: number
attempts?: number
retryDelay?: number
}

/**
* @public
*/
export type IFetchComponent = {
fetch(url: fetch.Request): Promise<fetch.Response>
fetch(url: fetch.RequestInfo, init?: fetch.RequestInit): Promise<fetch.Response>
}
fetch(url: fetch.RequestInfo, init?: RequestOptions): Promise<fetch.Response>
}

0 comments on commit cb8324b

Please sign in to comment.