()
| 907 | } |
| 908 | |
| 909 | protected createRootApply(): RootApply { |
| 910 | const byErrors = rootApplyRuntimeOf(this.$.cfg) |
| 911 | const runtime = $ark.inPlace?.runtimeOf(this as never, byErrors) ?? byErrors |
| 912 | const { Traversal } = runtime |
| 913 | switch (this.applyMode) { |
| 914 | case "allows": |
| 915 | return (data, onFail = this.onFail) => { |
| 916 | if (this.allows(data)) return data |
| 917 | |
| 918 | return this.rejectRoot(data, onFail, runtime) |
| 919 | } |
| 920 | |
| 921 | case "contextual": |
| 922 | return (data, onFail = this.onFail) => { |
| 923 | if (allowsInContext(this, data, this.$.cfg, Traversal)) return data |
| 924 | |
| 925 | return this.rejectRoot(data, onFail, runtime) |
| 926 | } |
| 927 | |
| 928 | case "transform": |
| 929 | case "contextualTransform": |
| 930 | if (this.hasAlias) { |
| 931 | return (data, onFail = this.onFail) => { |
| 932 | const untracked = allowsAcyclic(this, data) |
| 933 | const allowed = |
| 934 | untracked ?? allowsInContext(this, data, this.$.cfg, Traversal) |
| 935 | if (!allowed) return this.rejectRoot(data, onFail, runtime) |
| 936 | const ctx = new Traversal(data, this.$.cfg) |
| 937 | ctx.isTree = untracked === undefined |
| 938 | const result = transformResolution( |
| 939 | ctx, |
| 940 | this.id, |
| 941 | data, |
| 942 | this.tTransform!, |
| 943 | this |
| 944 | ) |
| 945 | return ctx.hasError() ? ctx.fin(onFail) : result |
| 946 | } |
| 947 | } |
| 948 | if (!this.tfCtx) { |
| 949 | if ( |
| 950 | (this as {} as BaseRoot).branches.every( |
| 951 | branch => !branch.tfs || (branch.is("morph") && !branch.head?.tfs) |
| 952 | ) |
| 953 | ) |
| 954 | return this.optimisticApply(runtime) |
| 955 | if (this.is("union") && !this.discriminant) { |
| 956 | return (data, onFail = this.onFail) => { |
| 957 | const ctx = new Traversal(data, this.$.cfg) |
| 958 | const result = transform(ctx, this, data) |
| 959 | if (result === unset) |
| 960 | return this.rejectRoot(data, onFail, runtime) |
| 961 | return ctx.hasError() ? ctx.fin(onFail) : result |
| 962 | } |
| 963 | } |
| 964 | } |
| 965 | return (data, onFail = this.onFail) => { |
| 966 | if (!this.allows(data)) return this.rejectRoot(data, onFail, runtime) |
nothing calls this directly
no test coverage detected