* Recursively sort all keys in an object for consistent hashing
(obj: unknown)
| 131 | * Recursively sort all keys in an object for consistent hashing |
| 132 | */ |
| 133 | function sortKeysDeep(obj: unknown): unknown { |
| 134 | if (Array.isArray(obj)) { |
| 135 | return obj.map(sortKeysDeep) |
| 136 | } |
| 137 | if (obj !== null && typeof obj === 'object') { |
| 138 | const sorted: Record<string, unknown> = {} |
| 139 | for (const [key, value] of Object.entries(obj).sort(([a], [b]) => |
| 140 | a.localeCompare(b), |
| 141 | )) { |
| 142 | sorted[key] = sortKeysDeep(value) |
| 143 | } |
| 144 | return sorted |
| 145 | } |
| 146 | return obj |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Compute a checksum from restrictions content for HTTP caching |
no test coverage detected