mvp-ai's picture
download
raw
2.19 kB
// Copyright (c) 2026 the Zuke contributors
// SPDX-License-Identifier: MIT
/**
* Running a command for a reader. Internal to the package: every reader —
* the `AwsTasks` ones, the Logs Insights query, the canary analysis and the
* canary platform — runs its commands through here, so they agree on three
* things.
*
* - It runs quietly: what a reader reads is not streamed to the build log.
* - A failed exit is a `CommandError`, even after `.noThrow()`: a reader
* promises a value, and reading a failed command's empty stdout would only
* turn the CLI's real error into a misleading "not JSON".
* - Its `--output` and `--query` are pinned after the caller's lambda, so the
* CLI prints what the reader parses.
*
* @module
*/
import { readJson, readScalar } from "./scalar_output.ts";
import { type AwsSettings, failOnExit } from "./settings.ts";
/**
* The `--query` that keeps the CLI's whole answer — JMESPath's current node.
* Pinned where a reader parses the full document, so a query set through a
* shared `.aws(...)` lambda cannot reshape it.
*/
export const WHOLE_ANSWER = "@";
/**
* Run `settings` and insist that it succeeded, whatever `.noThrow()` said:
* a caller that goes on as if it had — a reader parsing stdout, a canary
* reporting a rollback — must not run on after a failed exit.
*/
export async function runChecked(settings: AwsSettings) {
const output = await settings.run();
failOnExit(settings, output);
return output;
}
/** Run `settings` quietly and insist that it succeeded. */
function succeeded(settings: AwsSettings) {
return runChecked(settings.quiet());
}
/** The one line `settings` print with `--output text` and `--query query`. */
export async function scalarFrom(
settings: AwsSettings,
task: string,
subject: string,
): Promise<string> {
return readScalar(await succeeded(settings), task, subject);
}
/** The JSON document `settings` print with `--output json` and `--query query`. */
export async function jsonFrom(
settings: AwsSettings,
task: string,
query: string,
): Promise<unknown> {
return readJson(
await succeeded(settings.output("json").query(query)),
task,
);
}

Xet Storage Details

Size:
2.19 kB
·
Xet hash:
a001ae09f4576351909d7ad8ef25a78a3a9cb76f7b784da6805eb23bdc482723

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.