( sources: SourceConfig[], baseDir: string, fetcher: Fetcher, cache?: ContentCache )
| 183 | } |
| 184 | if (Array.isArray(value)) { |
| 185 | return value; |
| 186 | } |
| 187 | return []; |
| 188 | } |
| 189 | |
| 190 | async 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 |
no test coverage detected