/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * Building and reading jq programs as East values (#933): the nodes of * `JqType` the steps print as, and the readers their recognisers parse back * with. A literal is the typed East value it writes (`JqLiteralType`), as * east's parser makes it. * * @packageDocumentation */ import { type EastType, type JqNode } from "@elaraai/east"; import type { StepValue } from "./values.js"; /** * A child's path, as the parser and the printer key a node's span: the * parent's path, then the step to the child. * * @param path - the parent's path, `""` for the root * @param step - the steps to the child: `"pipe.left"`, `"call.args[0]"`, …; `""` for the node itself * @returns the child's path */ export declare function at(path: string, step: string): string; /** * Whether a name can name a jq variable. * * @param name - the name * @returns whether `$name` reads as a variable */ export declare function isVariableName(name: string): boolean; /** `.` */ export declare const IDENTITY: JqNode; /** `target.name` */ export declare function fieldNode(target: JqNode, name: string): JqNode; /** * The read of a field path: `.a.b` from `.`, or from another node. * * @param names - the fields read, outermost first * @param from - what they are read from; `.` by default * @returns the node */ export declare function pathNode(names: readonly string[], from?: JqNode): JqNode; /** `left | right` */ export declare function pipe(left: JqNode, right: JqNode): JqNode; /** * Segments piped in order, as the parser nests them: `a | (b | c)`. * * @param nodes - the segments, one or more * @returns the pipe */ export declare function pipeAll(nodes: readonly JqNode[]): JqNode; /** * The path of the `i`th of `n` segments piped by {@link pipeAll}, relative * to the pipe. * * @param i - the segment's index * @param n - how many segments * @returns its path */ export declare function pipedPath(i: number, n: number): string; /** `name(args…)` */ export declare function call(name: string, args?: readonly JqNode[]): JqNode; /** `left op right` */ export declare function binary(left: JqNode, op: string, right: JqNode): JqNode; /** * Operands joined by one operator, as the parser nests them: `(a and b) and c`. * * @param operands - the operands, one or more * @param op - `and` or `or` * @returns the chain */ export declare function chain(operands: readonly JqNode[], op: string): JqNode; /** * The path of the `i`th of `n` operands joined by {@link chain}, relative to * the chain. * * @param i - the operand's index * @param n - how many operands * @returns its path */ export declare function chainedPath(i: number, n: number): string; /** `-operand` */ export declare function negate(operand: JqNode): JqNode; /** `$name` */ export declare function variable(name: string): JqNode; /** * `{key: value, key, …}`: each entry a name, with a value or none. * * @param entries - the entries * @returns the object */ export declare function objectNode(entries: readonly { key: string; value?: JqNode; }[]): JqNode; /** `[body]`, or `[]` with no body. */ export declare function arrayNode(body?: JqNode): JqNode; /** * Outputs one after another, as the parser nests them: `(a, b), c`. * * @param nodes - the outputs, one or more * @returns the comma */ export declare function commaAll(nodes: readonly JqNode[]): JqNode; /** `target[]` */ export declare function iterate(target: JqNode): JqNode; /** `target[key]` */ export declare function index(target: JqNode, key: JqNode): JqNode; /** `target[:to]` */ export declare function sliceTo(target: JqNode, to: JqNode): JqNode; /** `source as $name | body` */ export declare function bind(source: JqNode, name: string, body: JqNode): JqNode; /** `path op value`, for an update operator */ export declare function updateNode(path: JqNode, op: string, value: JqNode): JqNode; /** A String literal. */ export declare function stringLiteral(text: string): JqNode; /** An Integer literal. */ export declare function integerLiteral(n: bigint): JqNode; /** A Float literal. */ export declare function floatLiteral(x: number): JqNode; /** A Boolean literal. */ export declare function booleanLiteral(b: boolean): JqNode; /** `null` */ export declare function nullLiteral(): JqNode; /** * A number as jq writes it: an Integer when it is whole, which a Float * compares with as its own, and a Float otherwise. * * @param x - the number * @returns the literal */ export declare function numberLiteral(x: number): JqNode; /** * The literal of a step's value. * * @param value - the value * @returns its literal */ export declare function valueLiteral(value: StepValue): JqNode; /** * The fields a node reads in a row, from `.`: `.a.b` gives `["a", "b"]`. * * @param node - the node * @param from - what the reads start from; `.` when omitted, else a test of the base node * @returns the names, or `undefined` when the node is not a plain path */ export declare function readPath(node: JqNode, from?: (base: JqNode) => boolean): string[] | undefined; /** * A call's arguments. * * @param node - the node * @param name - the function's name * @param arity - how many arguments * @returns the arguments, or `undefined` when the node is not that call */ export declare function readCall(node: JqNode, name: string, arity: number): JqNode[] | undefined; /** * A literal's value, with its type. * * @param node - the node * @returns the type and value, or `undefined` when it is not a literal */ export declare function readLiteral(node: JqNode): { type: EastType; value: unknown; } | undefined; /** * A literal as a step's value: text, a number, yes or no, or nothing. * * @param node - the node * @returns the value, or `undefined` when it is not a literal */ export declare function readStepValue(node: JqNode): StepValue | undefined; /** * A pipe's segments, in order. * * @param node - the node * @returns the segments; the node alone when it is no pipe */ export declare function readPipe(node: JqNode): JqNode[]; /** * An object's entries, when every key is a name. * * @param node - the node * @returns each entry's key and value, or `undefined` when it is no such object */ export declare function readObject(node: JqNode): { key: string; value: JqNode | undefined; }[] | undefined; /** * The operands of a chain of one operator, as {@link chain} builds it: the * left side read down while it is the same operator. * * @param node - the node * @param op - `and` or `or` * @returns the operands; the node alone when it is no such chain */ export declare function readChain(node: JqNode, op: string): JqNode[]; //# sourceMappingURL=jq.d.ts.map