viell-effect-schema-http 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -5
- package/dist/http/Request.d.ts +12 -6
- package/dist/http/Request.d.ts.map +1 -1
- package/dist/http/Request.js.map +1 -1
- package/dist/http/internal/encoded-input.d.ts +1 -0
- package/dist/http/internal/encoded-input.d.ts.map +1 -1
- package/dist/http/internal/encoded-input.js +21 -17
- package/dist/http/internal/encoded-input.js.map +1 -1
- package/dist/http/internal/input.d.ts +1 -1
- package/dist/http/internal/input.d.ts.map +1 -1
- package/dist/http/internal/input.js +39 -16
- package/dist/http/internal/input.js.map +1 -1
- package/dist/http/internal/nested-input.d.ts +16 -0
- package/dist/http/internal/nested-input.d.ts.map +1 -0
- package/dist/http/internal/nested-input.js +211 -0
- package/dist/http/internal/nested-input.js.map +1 -0
- package/package.json +1 -1
- package/src/http/Request.ts +12 -6
- package/src/http/internal/encoded-input.ts +24 -20
- package/src/http/internal/input.ts +60 -18
- package/src/http/internal/nested-input.ts +250 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { encodedInput } from "./encoded-input.js";
|
|
2
|
+
const keyOf = (name) => typeof name === "number" ? String(name) : name;
|
|
3
|
+
const ancestor = (ast) => ast._tag === "Objects" &&
|
|
4
|
+
ast.encoding === undefined &&
|
|
5
|
+
ast.indexSignatures.length === 0 &&
|
|
6
|
+
!ast.propertySignatures.some(({ name }) => name === Symbol.iterator);
|
|
7
|
+
/** Retain the actual enumerable output link or write, including its object identity. */
|
|
8
|
+
const writtenData = (output, key) => {
|
|
9
|
+
if (typeof output !== "object" ||
|
|
10
|
+
output === null ||
|
|
11
|
+
Symbol.iterator in output)
|
|
12
|
+
return undefined;
|
|
13
|
+
const prototype = Object.getPrototypeOf(output);
|
|
14
|
+
const property = Object.getOwnPropertyDescriptor(output, key);
|
|
15
|
+
if (property?.enumerable !== true ||
|
|
16
|
+
!("value" in property) ||
|
|
17
|
+
property.value === undefined)
|
|
18
|
+
return undefined;
|
|
19
|
+
return {
|
|
20
|
+
value: property.value,
|
|
21
|
+
matches() {
|
|
22
|
+
try {
|
|
23
|
+
const current = Object.getOwnPropertyDescriptor(output, key);
|
|
24
|
+
return (Object.getPrototypeOf(output) === prototype &&
|
|
25
|
+
!(Symbol.iterator in output) &&
|
|
26
|
+
current?.enumerable === true &&
|
|
27
|
+
"value" in current &&
|
|
28
|
+
Object.is(property.value, current.value) &&
|
|
29
|
+
current.writable === property.writable &&
|
|
30
|
+
current.configurable === property.configurable);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
/** Data only; capture each shared ancestor prefix once, without copying the caller's values. */
|
|
39
|
+
const ownData = (input, names) => {
|
|
40
|
+
if (typeof input !== "object" || input === null)
|
|
41
|
+
return undefined;
|
|
42
|
+
const prototype = Object.getPrototypeOf(input);
|
|
43
|
+
if ((prototype !== Object.prototype && prototype !== null) ||
|
|
44
|
+
Symbol.iterator in input)
|
|
45
|
+
return undefined;
|
|
46
|
+
const keys = Reflect.ownKeys(input);
|
|
47
|
+
const properties = new Map(keys.map((key) => [key, Object.getOwnPropertyDescriptor(input, key)]));
|
|
48
|
+
if ([...properties.values()].some((property) => property === undefined || !("value" in property)))
|
|
49
|
+
return undefined;
|
|
50
|
+
const absent = names.filter((name) => !properties.has(name));
|
|
51
|
+
if (absent.some((name) => name in input))
|
|
52
|
+
return undefined;
|
|
53
|
+
return {
|
|
54
|
+
properties,
|
|
55
|
+
matches() {
|
|
56
|
+
try {
|
|
57
|
+
if (Object.getPrototypeOf(input) !== prototype ||
|
|
58
|
+
Symbol.iterator in input ||
|
|
59
|
+
absent.some((name) => name in input))
|
|
60
|
+
return false;
|
|
61
|
+
const currentKeys = Reflect.ownKeys(input);
|
|
62
|
+
return (currentKeys.length === keys.length &&
|
|
63
|
+
keys.every((key, index) => {
|
|
64
|
+
const before = properties.get(key);
|
|
65
|
+
const after = Object.getOwnPropertyDescriptor(input, key);
|
|
66
|
+
return (key === currentKeys[index] &&
|
|
67
|
+
after !== undefined &&
|
|
68
|
+
"value" in after &&
|
|
69
|
+
Object.is(before.value, after.value) &&
|
|
70
|
+
before.enumerable === after.enumerable &&
|
|
71
|
+
before.writable === after.writable &&
|
|
72
|
+
before.configurable === after.configurable);
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Nested encoded-only evidence through unchanged direct object fields. Union and transformed
|
|
83
|
+
* nodes may be terminals; they never supply ancestor correspondence. No schema or thunk runs.
|
|
84
|
+
*/
|
|
85
|
+
export const nestedEncodedInput = (ast) => {
|
|
86
|
+
if (!ancestor(ast))
|
|
87
|
+
return undefined;
|
|
88
|
+
const known = new Map();
|
|
89
|
+
const active = new Set();
|
|
90
|
+
let cyclic = false;
|
|
91
|
+
const nodeOf = (part, root = false) => {
|
|
92
|
+
if (active.has(part)) {
|
|
93
|
+
cyclic = true;
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
if (known.has(part))
|
|
97
|
+
return known.get(part);
|
|
98
|
+
const terminal = root ? undefined : encodedInput(part);
|
|
99
|
+
if (terminal !== undefined) {
|
|
100
|
+
const node = { terminal, names: [], fields: [] };
|
|
101
|
+
known.set(part, node);
|
|
102
|
+
return node;
|
|
103
|
+
}
|
|
104
|
+
if (!ancestor(part)) {
|
|
105
|
+
known.set(part, undefined);
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
active.add(part);
|
|
109
|
+
const fields = part.propertySignatures.flatMap(({ name, type }) => {
|
|
110
|
+
const node = nodeOf(type);
|
|
111
|
+
return node === undefined ? [] : [[keyOf(name), node]];
|
|
112
|
+
});
|
|
113
|
+
active.delete(part);
|
|
114
|
+
const node = fields.length === 0
|
|
115
|
+
? undefined
|
|
116
|
+
: {
|
|
117
|
+
names: part.propertySignatures.map(({ name }) => keyOf(name)),
|
|
118
|
+
fields,
|
|
119
|
+
};
|
|
120
|
+
known.set(part, node);
|
|
121
|
+
return node;
|
|
122
|
+
};
|
|
123
|
+
const root = nodeOf(ast, true);
|
|
124
|
+
if (root === undefined || cyclic)
|
|
125
|
+
return undefined;
|
|
126
|
+
const capture = (node, input) => {
|
|
127
|
+
if (node.terminal !== undefined) {
|
|
128
|
+
const evidence = node.terminal(input);
|
|
129
|
+
if (evidence === undefined)
|
|
130
|
+
return undefined;
|
|
131
|
+
return {
|
|
132
|
+
select(output) {
|
|
133
|
+
if (!evidence.matches())
|
|
134
|
+
return undefined;
|
|
135
|
+
const key = evidence.witness(output);
|
|
136
|
+
if (key === undefined || !evidence.matches())
|
|
137
|
+
return undefined;
|
|
138
|
+
const written = writtenData(output, key);
|
|
139
|
+
return written === undefined
|
|
140
|
+
? undefined
|
|
141
|
+
: {
|
|
142
|
+
key,
|
|
143
|
+
matches: evidence.matches,
|
|
144
|
+
written: written.matches,
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
const data = ownData(input, node.names);
|
|
150
|
+
if (data === undefined)
|
|
151
|
+
return undefined;
|
|
152
|
+
const children = node.fields.flatMap(([name, child]) => {
|
|
153
|
+
const property = data.properties.get(name);
|
|
154
|
+
const captured = property === undefined ? undefined : capture(child, property.value);
|
|
155
|
+
return captured === undefined ? [] : [[name, captured]];
|
|
156
|
+
});
|
|
157
|
+
if (children.length === 0)
|
|
158
|
+
return undefined;
|
|
159
|
+
return {
|
|
160
|
+
select(output) {
|
|
161
|
+
try {
|
|
162
|
+
if (!data.matches() ||
|
|
163
|
+
typeof output !== "object" ||
|
|
164
|
+
output === null ||
|
|
165
|
+
Symbol.iterator in output)
|
|
166
|
+
return undefined;
|
|
167
|
+
for (const [name, child] of children) {
|
|
168
|
+
const written = writtenData(output, name);
|
|
169
|
+
if (written === undefined)
|
|
170
|
+
continue;
|
|
171
|
+
const selected = child.select(written.value);
|
|
172
|
+
if (selected !== undefined) {
|
|
173
|
+
return {
|
|
174
|
+
key: selected.key,
|
|
175
|
+
matches: () => selected.matches() && data.matches(),
|
|
176
|
+
// Descendant reflection runs before rechecking the earlier links it may change.
|
|
177
|
+
written: () => selected.written() && written.matches(),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
return (input) => {
|
|
190
|
+
try {
|
|
191
|
+
const captured = capture(root, input);
|
|
192
|
+
if (captured === undefined)
|
|
193
|
+
return undefined;
|
|
194
|
+
return {
|
|
195
|
+
select(output) {
|
|
196
|
+
const selected = captured.select(output);
|
|
197
|
+
// Prove this fixed write once, then retain caller evidence while decoding fresh output.
|
|
198
|
+
return selected !== undefined &&
|
|
199
|
+
selected.written() &&
|
|
200
|
+
selected.matches()
|
|
201
|
+
? { key: selected.key, matches: selected.matches }
|
|
202
|
+
: undefined;
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
//# sourceMappingURL=nested-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nested-input.js","sourceRoot":"","sources":["../../../src/http/internal/nested-input.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAyBlD,MAAM,KAAK,GAAG,CAAC,IAAiB,EAAO,EAAE,CACvC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CA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,SAAS,CAAC;QACnB,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/http/Request.ts
CHANGED
|
@@ -93,13 +93,19 @@ export type QueryFields = Readonly<
|
|
|
93
93
|
*
|
|
94
94
|
* Stable plain root data, finite closed object/union names, a successful whole constructor and
|
|
95
95
|
* strict encoding can establish an encoded-only field overwritten by a default after a typed
|
|
96
|
-
* strict read failure. Additional whole decoding then validates that input.
|
|
97
|
-
*
|
|
96
|
+
* strict read failure. Additional whole decoding then validates that input. If the actual winning
|
|
97
|
+
* route instead ends in fieldwise construction after failed whole decoding, at the root or through
|
|
98
|
+
* root union members, the same successful strict output proof retains the original refusal. This
|
|
99
|
+
* does not replay decoding or reconstruct input. Default and writer effects can run before refusal;
|
|
100
|
+
* other constructor and decoder choices keep their existing priority.
|
|
98
101
|
* Ambiguous names, open/opaque/class or suspended/iterable groups, inherited/accessor fields and
|
|
99
|
-
* changing input remain outside this proof, as
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
102
|
+
* changing input remain outside this proof, as do later member-constructor and unsupported recovery
|
|
103
|
+
* routes. Successful initial whole construction also permits a nested proof through finite closed,
|
|
104
|
+
* untransformed direct objects: stable own-data links must reach the same encoded-only field
|
|
105
|
+
* actually written by the original strict writer. Whole decoding can repeat checks and services;
|
|
106
|
+
* construction is not replayed. Parent unions, arrays, opaque/suspended/transformed ancestors and
|
|
107
|
+
* unsupported member/fieldwise paths remain outside this extension (issue #170). Use decoded names
|
|
108
|
+
* or a validated decoded mapping there. The Request guide describes the bounds and migration.
|
|
103
109
|
*
|
|
104
110
|
* Under a union, a member that keeps every field wins over an earlier one that would strip one, on
|
|
105
111
|
* both sides and at any depth. A field no member can keep beside the others is a `SchemaError` that
|
|
@@ -109,28 +109,32 @@ export const encodedInput = (ast: SchemaAST.AST) => {
|
|
|
109
109
|
const inherited = () =>
|
|
110
110
|
allNames.some((name) => !Object.hasOwn(input, name) && name in input);
|
|
111
111
|
if (inherited()) return undefined;
|
|
112
|
+
const witness = (output: unknown): string | symbol | undefined => {
|
|
113
|
+
try {
|
|
114
|
+
if (
|
|
115
|
+
typeof output !== "object" ||
|
|
116
|
+
output === null ||
|
|
117
|
+
Symbol.iterator in output
|
|
118
|
+
)
|
|
119
|
+
return undefined;
|
|
120
|
+
return properties.find(([key, property]) => {
|
|
121
|
+
if (!encodedOnly.has(key) || property.value === undefined)
|
|
122
|
+
return false;
|
|
123
|
+
const written = Object.getOwnPropertyDescriptor(output, key);
|
|
124
|
+
return (
|
|
125
|
+
written?.enumerable === true &&
|
|
126
|
+
"value" in written &&
|
|
127
|
+
written.value !== undefined
|
|
128
|
+
);
|
|
129
|
+
})?.[0];
|
|
130
|
+
} catch {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
112
134
|
return {
|
|
135
|
+
witness,
|
|
113
136
|
written(output: unknown) {
|
|
114
|
-
|
|
115
|
-
if (
|
|
116
|
-
typeof output !== "object" ||
|
|
117
|
-
output === null ||
|
|
118
|
-
Symbol.iterator in output
|
|
119
|
-
)
|
|
120
|
-
return false;
|
|
121
|
-
return properties.some(([key, property]) => {
|
|
122
|
-
if (!encodedOnly.has(key) || property.value === undefined)
|
|
123
|
-
return false;
|
|
124
|
-
const written = Object.getOwnPropertyDescriptor(output, key);
|
|
125
|
-
return (
|
|
126
|
-
written?.enumerable === true &&
|
|
127
|
-
"value" in written &&
|
|
128
|
-
written.value !== undefined
|
|
129
|
-
);
|
|
130
|
-
});
|
|
131
|
-
} catch {
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
137
|
+
return witness(output) !== undefined;
|
|
134
138
|
},
|
|
135
139
|
matches() {
|
|
136
140
|
try {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Effect, Schema, SchemaAST } from "effect";
|
|
2
2
|
import { encodedInput } from "./encoded-input.js";
|
|
3
3
|
import * as Excess from "./excess.js";
|
|
4
|
+
import { nestedEncodedInput } from "./nested-input.js";
|
|
4
5
|
import { snapshotter } from "./snapshot.js";
|
|
5
6
|
|
|
6
7
|
/** What a schema's constructor takes. This is the one place that names the `~`-prefixed key. */
|
|
@@ -82,24 +83,32 @@ export const toDecoded = <S extends Schema.Top>(
|
|
|
82
83
|
(issue) => new Schema.SchemaError(issue),
|
|
83
84
|
);
|
|
84
85
|
const decode = Schema.decodeUnknownEffect(contract);
|
|
85
|
-
const byField = Effect.fnUntraced(function* (
|
|
86
|
+
const byField = Effect.fnUntraced(function* (
|
|
87
|
+
input: object,
|
|
88
|
+
onFieldwise?: () => void,
|
|
89
|
+
) {
|
|
86
90
|
const output: Record<PropertyKey, unknown> = { ...input };
|
|
87
91
|
// A field need not be a key, as an accessor on a class is not, so it comes from `input`.
|
|
88
92
|
const fields: Record<PropertyKey, unknown> = input as never;
|
|
89
93
|
for (const { name, type } of Excess.fieldsOf(contract.ast))
|
|
90
94
|
if (fields[name] !== undefined)
|
|
91
95
|
output[name] = yield* fromPart(type, fields[name], options);
|
|
92
|
-
|
|
96
|
+
const value = yield* make(output);
|
|
97
|
+
onFieldwise?.();
|
|
98
|
+
return value;
|
|
93
99
|
});
|
|
94
|
-
const byMember = (input: object) =>
|
|
100
|
+
const byMember = (input: object, onFieldwise?: () => void) =>
|
|
95
101
|
contract.ast._tag === "Union" && contract.ast.types.length > 0
|
|
96
102
|
? Effect.firstSuccessOf(
|
|
97
|
-
contract.ast.types.map((member) =>
|
|
103
|
+
contract.ast.types.map((member) =>
|
|
104
|
+
fromPart(member, input, options, onFieldwise),
|
|
105
|
+
),
|
|
98
106
|
)
|
|
99
|
-
: byField(input);
|
|
107
|
+
: byField(input, onFieldwise);
|
|
100
108
|
return (
|
|
101
109
|
input: Input<S>,
|
|
102
110
|
onConstructed?: () => void,
|
|
111
|
+
onFieldwise?: () => void,
|
|
103
112
|
): Effect.Effect<S["Type"], Schema.SchemaError, S["DecodingServices"]> =>
|
|
104
113
|
Effect.matchEffect(make(input), {
|
|
105
114
|
onSuccess: (value) => {
|
|
@@ -111,7 +120,7 @@ export const toDecoded = <S extends Schema.Top>(
|
|
|
111
120
|
Effect.mapError(
|
|
112
121
|
Effect.catch(decode(input, options), (encodedFailure) =>
|
|
113
122
|
typeof input === "object" && input !== null
|
|
114
|
-
? byMember(input)
|
|
123
|
+
? byMember(input, onFieldwise)
|
|
115
124
|
: Effect.fail(encodedFailure),
|
|
116
125
|
),
|
|
117
126
|
() => failure,
|
|
@@ -124,8 +133,13 @@ const fromPart = (
|
|
|
124
133
|
ast: SchemaAST.AST,
|
|
125
134
|
value: unknown,
|
|
126
135
|
options?: SchemaAST.ParseOptions,
|
|
136
|
+
onFieldwise?: () => void,
|
|
127
137
|
): Effect.Effect<unknown, Schema.SchemaError, unknown> =>
|
|
128
|
-
toDecoded(Schema.make<Schema.Top>(ast), options)(
|
|
138
|
+
toDecoded(Schema.make<Schema.Top>(ast), options)(
|
|
139
|
+
value,
|
|
140
|
+
undefined,
|
|
141
|
+
onFieldwise,
|
|
142
|
+
);
|
|
129
143
|
|
|
130
144
|
/** What a schema wrote, and the fields of its input it would lose, which may be held elsewhere. */
|
|
131
145
|
export interface Written<A> {
|
|
@@ -217,7 +231,8 @@ export const reader = <S extends Schema.Top, A, R>(
|
|
|
217
231
|
);
|
|
218
232
|
const ast = contract.ast;
|
|
219
233
|
const encoded = encodedInput(ast);
|
|
220
|
-
const
|
|
234
|
+
const nested = nestedEncodedInput(ast);
|
|
235
|
+
const decode = (encoded || nested) && Schema.decodeUnknownEffect(contract);
|
|
221
236
|
const recoverable =
|
|
222
237
|
ast._tag === "Objects" &&
|
|
223
238
|
ast.encoding === undefined &&
|
|
@@ -286,6 +301,7 @@ export const reader = <S extends Schema.Top, A, R>(
|
|
|
286
301
|
R | S["DecodingServices"]
|
|
287
302
|
> => {
|
|
288
303
|
const encodedEvidence = encoded?.(input);
|
|
304
|
+
const nestedEvidence = nested?.(input);
|
|
289
305
|
const captured = snapshot?.(input);
|
|
290
306
|
const given = Excess.normalised([contract.ast], input);
|
|
291
307
|
// A strict read cannot see a field outside a value's keys, so it may not fall back on `input`.
|
|
@@ -302,15 +318,26 @@ export const reader = <S extends Schema.Top, A, R>(
|
|
|
302
318
|
})),
|
|
303
319
|
),
|
|
304
320
|
({ failure, reading }) => {
|
|
305
|
-
if (
|
|
321
|
+
if (
|
|
322
|
+
!reading ||
|
|
323
|
+
decode === undefined ||
|
|
324
|
+
(!encodedEvidence?.matches() && nestedEvidence === undefined)
|
|
325
|
+
)
|
|
306
326
|
return compared(input, given);
|
|
307
327
|
return Effect.suspend(() => {
|
|
308
328
|
let constructed = false;
|
|
329
|
+
let fieldwise = false;
|
|
309
330
|
let strictWrite = true;
|
|
310
331
|
const read = (current: Input<S>) =>
|
|
311
|
-
decoded(
|
|
312
|
-
|
|
313
|
-
|
|
332
|
+
decoded(
|
|
333
|
+
current,
|
|
334
|
+
() => {
|
|
335
|
+
constructed = true;
|
|
336
|
+
},
|
|
337
|
+
() => {
|
|
338
|
+
fieldwise = true;
|
|
339
|
+
},
|
|
340
|
+
);
|
|
314
341
|
return Effect.flatMap(
|
|
315
342
|
compared(input, given, read, () => {
|
|
316
343
|
strictWrite = false;
|
|
@@ -319,25 +346,40 @@ export const reader = <S extends Schema.Top, A, R>(
|
|
|
319
346
|
// Keep constructor alternatives and existing failures. Only an actual encoded write
|
|
320
347
|
// can hide this constructor's inability to consume the encoded-only caller field.
|
|
321
348
|
if (
|
|
322
|
-
!constructed ||
|
|
349
|
+
(!constructed && !fieldwise) ||
|
|
323
350
|
!strictWrite ||
|
|
324
|
-
!encodedEvidence
|
|
325
|
-
!encodedEvidence.written(constructedResult.output) ||
|
|
326
|
-
!encodedEvidence.matches()
|
|
351
|
+
(!constructed && !encodedEvidence)
|
|
327
352
|
)
|
|
328
353
|
return Effect.succeed(constructedResult);
|
|
354
|
+
const rootWitness =
|
|
355
|
+
encodedEvidence?.matches() &&
|
|
356
|
+
encodedEvidence.written(constructedResult.output) &&
|
|
357
|
+
encodedEvidence.matches()
|
|
358
|
+
? encodedEvidence
|
|
359
|
+
: undefined;
|
|
360
|
+
const witness =
|
|
361
|
+
rootWitness ??
|
|
362
|
+
(constructed
|
|
363
|
+
? nestedEvidence?.select(constructedResult.output)
|
|
364
|
+
: undefined);
|
|
365
|
+
if (witness === undefined)
|
|
366
|
+
return Effect.succeed(constructedResult);
|
|
367
|
+
// This winning fieldwise route followed a failed whole decode and never read the
|
|
368
|
+
// encoded-only caller name. Refuse its generated replacement without replaying effects.
|
|
369
|
+
if (fieldwise && rootWitness !== undefined)
|
|
370
|
+
return Effect.fail(failure);
|
|
329
371
|
const encodedRead = (current: Input<S>) =>
|
|
330
372
|
Effect.flatMap(
|
|
331
373
|
Effect.mapError(decode(current), () => failure),
|
|
332
374
|
(value) =>
|
|
333
|
-
|
|
375
|
+
witness.matches()
|
|
334
376
|
? Effect.succeed(value)
|
|
335
377
|
: Effect.fail(failure),
|
|
336
378
|
);
|
|
337
379
|
return Effect.flatMap(
|
|
338
380
|
compared(input, given, encodedRead),
|
|
339
381
|
(result) =>
|
|
340
|
-
|
|
382
|
+
witness.matches()
|
|
341
383
|
? Effect.succeed(result)
|
|
342
384
|
: Effect.fail(failure),
|
|
343
385
|
);
|