| 66 | // right now we ignore scoped combinations, because they allow us to scope relation checks too. |
| 67 | // probably best to create a separate keyword and dsl for relation checks, so we can remove all the special casing alltogether.. |
| 68 | export const isRelationCheck = (f: readonly FilterResult[], isRelation: string | null) => { |
| 69 | const withPath = f.filter((_) => "path" in _) |
| 70 | if (withPath.length && withPath.every((_) => "path" in _ && _.path.includes(".-1."))) { |
| 71 | const first = withPath[0] as { path: string } |
| 72 | const rel = first.path.split(".-1.")[0] |
| 73 | if (isRelation && rel !== isRelation) { |
| 74 | throw new Error(`expected ${isRelation} relation but found ${rel}`) |
| 75 | } |
| 76 | if (!f.filter((_) => "path" in _).every((_) => "path" in _ && _.path.startsWith(rel + ".-1."))) { |
| 77 | throw new Error( |
| 78 | `Cannot mix relation checks of different props, expected all to be "${rel}"` |
| 79 | ) |
| 80 | } |
| 81 | return rel |
| 82 | } |
| 83 | if (f.some((_) => "path" in _ && _.path.includes(".-1."))) { |
| 84 | throw new Error( |
| 85 | "Cannot mix relation checks with non-relation checks in the same filter scope. create a separate one" |
| 86 | ) |
| 87 | } |
| 88 | |
| 89 | return false |
| 90 | } |
| 91 | |
| 92 | export const codeFilter3 = <E>(state: readonly FilterResult[]) => (sut: E) => codeFilter3_(state, sut) |
| 93 | const codeFilter3__ = <E>( |