MCPcopy Create free account
hub / github.com/VPSDance/ai-proxy-rules / loadSourceRules

Function loadSourceRules

scripts/sync/build.ts:185–219  ·  view source on GitHub ↗
(
  sources: SourceConfig[],
  baseDir: string,
  fetcher: Fetcher,
  cache?: ContentCache
)

Source from the content-addressed store, hash-verified

183 }
184 if (Array.isArray(value)) {
185 return value;
186 }
187 return [];
188}
189
190async function loadSourceRules(
191 sources: SourceConfig[],
192 baseDir: string,
193 fetcher: Fetcher,
194 cache?: ContentCache
195): Promise<RuleSet> {
196 const textCache = new Map<string, Promise<string>>();
197 const rules = await Promise.all(
198 sources.map(async (source) => {
199 const text = await loadSourceText(source, baseDir, fetcher, cache);
200 const parsed = await parseSourceRules(text, source.parser as SourceParser, {
201 sourceUrl: source.type === "remote-text" || source.type === "remote-html" ? source.url : undefined,
202 followIncludes: source.followIncludes,
203 fetchText: async (url) => {
204 const cached = textCache.get(url);
205 if (cached) {
206 return cached;
207 }
208
209 const fetched = fetcher(url);
210 textCache.set(url, fetched);
211 return fetched;
212 }
213 });
214
215 if (!source.importAsn) {
216 parsed.asn = [];
217 }
218
219 return parsed;
220 })
221 );
222

Callers 1

buildProviderDataFunction · 0.85

Calls 3

loadSourceTextFunction · 0.85
parseSourceRulesFunction · 0.85
mergeRuleSetsFunction · 0.85

Tested by

no test coverage detected