( items: Array<T>, field: K, direction: `asc` | `desc` = `asc`, message?: string, )
| 106 | * Assert that items are sorted correctly |
| 107 | */ |
| 108 | export function assertSorted<T, K extends keyof T>( |
| 109 | items: Array<T>, |
| 110 | field: K, |
| 111 | direction: `asc` | `desc` = `asc`, |
| 112 | message?: string, |
| 113 | ) { |
| 114 | for (let i = 1; i < items.length; i++) { |
| 115 | const prev = items[i - 1]![field] |
| 116 | const curr = items[i]![field] |
| 117 | |
| 118 | if (direction === `asc`) { |
| 119 | if (prev > curr) { |
| 120 | throw new Error( |
| 121 | message ?? |
| 122 | `Items not sorted ascending by ${String(field)}: ${prev} > ${curr} at index ${i}`, |
| 123 | ) |
| 124 | } |
| 125 | } else { |
| 126 | if (prev < curr) { |
| 127 | throw new Error( |
| 128 | message ?? |
| 129 | `Items not sorted descending by ${String(field)}: ${prev} < ${curr} at index ${i}`, |
| 130 | ) |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Assert that predicate pushdown occurred (no over-fetching) |
no outgoing calls
no test coverage detected