| 2904 | * whole query for `patchAll`. |
| 2905 | */ |
| 2906 | const compileTargets = ( |
| 2907 | invalidates: ReadonlyArray<Target>, |
| 2908 | optimistic: ReadonlyArray<Patch> = [] |
| 2909 | ): Targets => { |
| 2910 | const queries = new Set<string>() |
| 2911 | const entries = new Map<string, Set<string>>() |
| 2912 | const tags = new Set<string>() |
| 2913 | const addEntry = (name: string, argsKey: string): void => { |
| 2914 | let keys = entries.get(name) |
| 2915 | if (keys === undefined) entries.set(name, keys = new Set()) |
| 2916 | keys.add(argsKey) |
| 2917 | } |
| 2918 | for (const target of invalidates) { |
| 2919 | if (isQuery(target)) queries.add(defOf(target).name) |
| 2920 | else if (target._tag === "Entry") { |
| 2921 | addEntry(defOf(target.query).name, argsKeyOf(target)) |
| 2922 | } else tags.add(target.name) |
| 2923 | } |
| 2924 | for (const patch of optimistic) { |
| 2925 | if (patch._tag === "Patch") { |
| 2926 | addEntry(defOf(patch.query).name, argsKeyOf(patch)) |
| 2927 | } else queries.add(defOf(patch.query).name) |
| 2928 | } |
| 2929 | return { queries, entries, tags } |
| 2930 | } |
| 2931 | |
| 2932 | /** |
| 2933 | * Whether compiled targets hit an entry. `tags` is `undefined` for a raw |