Raw
1 import { ResourceEntry, ResourceMap, ResourcePath } from "./types"
2
3 export function getOrCreateRegistry(
4 globalRegistry: Map<ResourcePath, ResourceMap>,
5 sourcePath: string
6 ): ResourceMap {
7 let registry = globalRegistry.get(sourcePath)
8
9 if (!registry) {
10 registry = new Map<string, ResourceEntry[]>()
11 globalRegistry.set(sourcePath, registry)
12 }
13
14 return registry
15 }
16
17 export function addToRegistry(
18 registry: ResourceMap,
19 type: string,
20 entry: ResourceEntry
21 ): void {
22 const entries = registry.get(type) || []
23 registry.set(type, [...entries, entry])
24 }
25
26 export function addToInverseRegistry(
27 inverseRegistry: Map<string, string[]>,
28 key: string,
29 sourcePath: string
30 ): void {
31 const existing = inverseRegistry.get(key) || []
32 const updated = Array.from(new Set([...existing, sourcePath]))
33 inverseRegistry.set(key, updated)
34 }