mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 05:02:40 +00:00
fix(cli): reuse decoded inline JSON during admission (#11790)
This commit is contained in:
4 files changed
+121
-23
No files matched your search
@@ -714,9 +714,9 @@ export interface ContractCliDescription {
|
||||
/** The command adds `--detail` and `--evidence_output`. */
|
||||
readonly evidenceDelivery: boolean;
|
||||
/**
|
||||
* Decode run-time JSON, then map parsed values to the contract input and
|
||||
* the selected delivery. An input or delivery that is not admitted is
|
||||
* refused before any target is opened.
|
||||
* Map values decoded by `admitDeliveryOptions` and the JSON input reader
|
||||
* to the contract input and selected delivery. An input or delivery that
|
||||
* is not admitted is refused before any target is opened.
|
||||
*/
|
||||
readonly admit: (
|
||||
values: Readonly<Record<string, unknown>>,
|
||||
@@ -724,11 +724,12 @@ export interface ContractCliDescription {
|
||||
/**
|
||||
* Refuse inline JSON options and a delivery the options cannot select,
|
||||
* before any JSON input is read, so an invalid invocation never waits on a
|
||||
* file or stdin. `admit` still checks the admitted view with the input.
|
||||
* file or stdin. Return the decoded options for the input reader and `admit`;
|
||||
* `admit` still checks the admitted view with the input.
|
||||
*/
|
||||
readonly admitDeliveryOptions: (
|
||||
values: Readonly<Record<string, unknown>>,
|
||||
) => Result<void, AnalysisInputError>;
|
||||
) => Result<Record<string, unknown>, AnalysisInputError>;
|
||||
}
|
||||
|
||||
/** One contract from a contract group, keeping its exact schema types. */
|
||||
@@ -2506,7 +2507,7 @@ export const describeContractCommand = <
|
||||
admitDeliveryOptions: (values) => {
|
||||
const decoded = decodeInlineJson(contract.name, parameters, values);
|
||||
if (!decoded.ok) return decoded;
|
||||
if (!evidenceDelivery) return ok(undefined);
|
||||
if (!evidenceDelivery) return decoded;
|
||||
const view =
|
||||
viewDelivery === undefined
|
||||
? undefined
|
||||
@@ -2537,7 +2538,7 @@ export const describeContractCommand = <
|
||||
evidenceOutput: decoded.value.evidence_output as string | undefined,
|
||||
view,
|
||||
});
|
||||
return refused === undefined ? ok(undefined) : err(refused);
|
||||
return refused === undefined ? decoded : err(refused);
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -2653,8 +2654,8 @@ const selectSpelledSelector = (
|
||||
};
|
||||
|
||||
/**
|
||||
* Decode run-time JSON, then map the values to the contract input and the
|
||||
* selected delivery. When the projection decodes JSON at run time, the
|
||||
* Map decoded values to the contract input and selected delivery.
|
||||
* When the projection decodes JSON at run time, the
|
||||
* decoded input, delivery and view are admitted together by the contract
|
||||
* input schema, so the contract's own rules and messages apply. When argv
|
||||
* supplies the whole contract input, it is parsed once the same way and the
|
||||
@@ -2690,9 +2691,7 @@ const admitInvocation = (
|
||||
wholeInput,
|
||||
checkedFields,
|
||||
} = command;
|
||||
const inline = decodeInlineJson(contract.name, parameters, values);
|
||||
if (!inline.ok) return inline;
|
||||
const decoded = inline.value;
|
||||
const decoded = values;
|
||||
const input = toContractInput(decoded);
|
||||
const detail = evidenceDelivery
|
||||
? (decoded[rename("detail")] as "complete" | "summary" | undefined)
|
||||
|
||||
@@ -663,7 +663,7 @@ export const registerContractCommand = <
|
||||
logCliCommand(logger, description.command, async () => {
|
||||
const options = selected.admitDeliveryOptions(values);
|
||||
if (!options.ok) return projectAnalysisError(options.error);
|
||||
const read = await readJsonInputs(selected, values, signal);
|
||||
const read = await readJsonInputs(selected, options.value, signal);
|
||||
if (!read.ok) return read.error;
|
||||
const admitted = selected.admit(read.value);
|
||||
// Admission and handler issues alike name renamed fields by CLI key.
|
||||
@@ -981,7 +981,7 @@ export const registerRoutedCommand = (
|
||||
if (!options.ok) return projectAnalysisError(options.error);
|
||||
const read = await readJsonInputs(
|
||||
description,
|
||||
shared.value,
|
||||
options.value,
|
||||
signal,
|
||||
ownJsonInputs(description, sharedJson),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user