| 116 | // Recurse over the remaining segments rather than an index, so "the head |
| 117 | // exists" is a fact about the array rather than something to assert. |
| 118 | const assign = (target: unknown, [segment, ...rest]: readonly string[]): unknown => { |
| 119 | if (segment === undefined) return pageParam; |
| 120 | const record: Record<string, unknown> = |
| 121 | typeof target === "object" && target !== null && !Array.isArray(target) |
| 122 | ? { ...(target as Record<string, unknown>) } |
| 123 | : {}; |
| 124 | record[segment] = rest.length === 0 ? pageParam : assign(record[segment], rest); |
| 125 | return record; |
| 126 | }; |
| 127 | |
| 128 | return assign(base, cursorKey.split(".")); |
| 129 | }; |