Skip to content

Commit 091b053

Browse files
mbelskydrwpow
andauthored
Make urlCache as a part of load context (#707) (#708)
Co-authored-by: Drew Powers <[email protected]>
1 parent 72acb8d commit 091b053

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/load.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,18 @@ function parseHttpHeaders(httpHeaders: Record<string, any>): Headers {
8888
interface LoadOptions extends GlobalContext {
8989
rootURL: URL;
9090
schemas: SchemaMap;
91+
urlCache?: Set<string>; // URL cache (prevent URLs from being loaded over and over)
9192
httpHeaders?: Headers;
9293
httpMethod?: string;
9394
}
9495

95-
// temporary cache for load()
96-
let urlCache = new Set<string>(); // URL cache (prevent URLs from being loaded over and over)
97-
9896
/** Load a schema from local path or remote URL */
9997
export default async function load(
10098
schema: URL | PartialSchema,
10199
options: LoadOptions
102100
): Promise<{ [url: string]: PartialSchema }> {
101+
const urlCache = options.urlCache || new Set<string>();
102+
103103
const isJSON = schema instanceof URL === false; // if this is dynamically-passed-in JSON, we’ll have to change a few things
104104
let schemaID = isJSON ? new URL(VIRTUAL_JSON_URL).href : (schema.href as string);
105105

@@ -182,7 +182,7 @@ export default async function load(
182182

183183
const nextURL = isRemoteURL ? new URL(refURL) : new URL(slash(refURL), schema as URL);
184184
refPromises.push(
185-
load(nextURL, options).then((subschemas) => {
185+
load(nextURL, { ...options, urlCache }).then((subschemas) => {
186186
for (const subschemaURL of Object.keys(subschemas)) {
187187
schemas[subschemaURL] = subschemas[subschemaURL];
188188
}

0 commit comments

Comments
 (0)