transforms a key's value through each constraint transforming it: its prop or the index signatures it matches
( data: object, k: Key, ctx: InternalTraversal, inPlace: boolean | undefined, pathKey: PropertyKey = k )
| 832 | |
| 833 | /** transforms a key's value through each constraint transforming it: its prop or the index signatures it matches */ |
| 834 | private tfSharedKey( |
| 835 | data: object, |
| 836 | k: Key, |
| 837 | ctx: InternalTraversal, |
| 838 | inPlace: boolean | undefined, |
| 839 | pathKey: PropertyKey = k |
| 840 | ): void { |
| 841 | const prop = this.byKey[k] |
| 842 | if (prop && !this.tfsOf(prop).length) return |
| 843 | const constraints: BaseNode[] = prop ? [prop.value] : [] |
| 844 | // a declared key data inherits or hides is no key of an index signature |
| 845 | const listed = !prop || isDeletableKeyOf(data, k) |
| 846 | if (listed) { |
| 847 | for (const index of this.index!) { |
| 848 | if (allowsInBranch(ctx, index.signature, k)) |
| 849 | constraints.push(index.value) |
| 850 | } |
| 851 | } |
| 852 | const steps: TransformStep[] = |
| 853 | prop ? |
| 854 | this.tfsOf(prop).filter(step => listed || !step.indexed) |
| 855 | : constraints.filter(n => n.tfs).map(node => ({ node })) |
| 856 | const input: unknown = data[k as never] |
| 857 | if ( |
| 858 | !steps.length || |
| 859 | !travKey( |
| 860 | pathKey, |
| 861 | () => constraints.every(n => allowsInBranch(ctx, n, input)), |
| 862 | ctx |
| 863 | ) |
| 864 | ) |
| 865 | return |
| 866 | const errN = ctx.errN |
| 867 | let value = input |
| 868 | for (const step of steps) { |
| 869 | if (ctx.errN > errN) break |
| 870 | if (step.signature && !allowsInBranch(ctx, step.signature, k)) continue |
| 871 | const stepInput = |
| 872 | value === input || step.node.allows(value) ? value : input |
| 873 | const transformed = travKey( |
| 874 | pathKey, |
| 875 | () => |
| 876 | transform( |
| 877 | ctx, |
| 878 | inPlace ? writingInPlace(step.node) : step.node, |
| 879 | stepInput |
| 880 | ), |
| 881 | ctx |
| 882 | ) |
| 883 | value = |
| 884 | stepInput === value ? transformed : ( |
| 885 | mergeTransformed(stepInput, value, transformed) |
| 886 | ) |
| 887 | } |
| 888 | transformedInApply(ctx, value) |
| 889 | } |
| 890 | |
| 891 | /** applies its defaults and structural morphs to data, writing into `out` */ |
no test coverage detected