Stored queries
A stored query names a question about the fleet. r is the eval result. The other formal args are its parameters:
required, unless they have a default.
# A stored query names a question. `r` is the eval result; the other args are its parameters.{ yen, lib, ... }:{ yen.queries = { aspectsOn = { r, host }: lib.sort (a: b: a < b) ( lib.filter (a: r.active.${a}."fleet:main/host:${host}" or false) (lib.attrNames r.active) ); hostsWith = { r, aspect, kind ? "host", }: map (s: s.name) (lib.filter (s: s.kind == kind && r.active.${aspect}.${s.id}) r.scopes); };}r.queries lists them with their parameters:
{ aspectsOn = { optional = [ ]; required = [ "host" ]; }; hostsWith = { optional = [ "kind" ]; required = [ "aspect" ]; };}r.ask name args answers:
[ "git" "nginx"][ "ana"]A wrong call is an error record, never a throw: a missing parameter, an unknown one, or an unknown query with near.
{ class = "fixable"; code = "missing-param"; error = "query aspectsOn: missing host"; from = "ask"; got = [ ]; path = [ ]; want = [ "host" ];}{ class = "fixable"; code = "unknown-query"; error = "no query aspectsOff"; from = "ask"; near = [ "aspectsOn" ]; path = [ ];}nix eval --impure --json --expr '(import ./query.nix).ask "aspectsOn" { host = "web"; }'