MCPcopy Create free account
hub / github.com/openai/openai-node / buildURL

Method buildURL

src/client.ts:666–688  ·  view source on GitHub ↗
(
    path: string,
    query: Record<string, unknown> | null | undefined,
    defaultBaseURL?: string | undefined,
  )

Source from the content-addressed store, hash-verified

664 }
665
666 buildURL(
667 path: string,
668 query: Record<string, unknown> | null | undefined,
669 defaultBaseURL?: string | undefined,
670 ): string {
671 const baseURL = (!this.#baseURLOverridden() && defaultBaseURL) || this.baseURL;
672 const url =
673 isAbsoluteURL(path) ?
674 new URL(path)
675 : new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
676
677 const defaultQuery = this.defaultQuery();
678 const pathQuery = Object.fromEntries(url.searchParams);
679 if (!isEmptyObj(defaultQuery) || !isEmptyObj(pathQuery)) {
680 query = { ...pathQuery, ...defaultQuery, ...query };
681 }
682
683 if (typeof query === 'object' && query && !Array.isArray(query)) {
684 url.search = this.stringifyQuery(query);
685 }
686
687 return url.toString();
688 }
689
690 /**
691 * Used as a callback for mutating the given `FinalRequestOptions` object.

Callers 5

buildRequestMethod · 0.95
buildURLFunction · 0.80
index.test.tsFile · 0.80
provider.test.tsFile · 0.80
azure.test.tsFile · 0.80

Calls 7

#baseURLOverriddenMethod · 0.95
defaultQueryMethod · 0.95
stringifyQueryMethod · 0.95
isAbsoluteURLFunction · 0.90
isEmptyObjFunction · 0.90
sliceMethod · 0.80
toStringMethod · 0.80

Tested by

no test coverage detected