UNPKG

fauna

Version:

A driver to query Fauna databases in browsers, Node.js, and other Javascript runtimes

61 lines (60 loc) 2.31 kB
import type { FQLFragment, QueryValue } from "./wire-protocol"; /** * A QueryArgumentObject is a plain javascript object where each property is a * valid QueryArgument. */ export type QueryArgumentObject = { [key: string]: QueryArgument; }; /** * A QueryArgument represents all possible values that can be encoded and passed * to Fauna as a query argument. * * The {@link fql} tagged template function requires all arguments to be of type * QueryArgument. */ export type QueryArgument = QueryValue | Query<any> | Date | ArrayBuffer | Uint8Array | Array<QueryArgument> | QueryArgumentObject; /** * Creates a new Query. Accepts template literal inputs. * @typeParam T - The expected type of the response from Fauna when evaluated. * @param queryFragments - An array that constitutes * the strings that are the basis of the query. * @param queryArgs - an Array\<QueryValue | Query\> that * constitute the arguments to inject between the queryFragments. * @throws Error - if you call this method directly (not using template * literals) and pass invalid construction parameters * @example * ```typescript * const str = "baz"; * const num = 17; * const innerQuery = fql`${num} + 3)`; * const queryRequestBuilder = fql`${str}.length == ${innerQuery}`; * ``` */ export declare function fql<T extends QueryValue = any>(queryFragments: ReadonlyArray<string>, ...queryArgs: QueryArgument[]): Query<T>; /** * Internal class. * A builder for composing queries using the {@link fql} tagged template * function * @typeParam T - The expected type of the response from Fauna when evaluated. * T can be used to infer the type of the response type from {@link Client} * methods. */ export declare class Query<T extends QueryValue = any> { #private; constructor(queryFragments: ReadonlyArray<string>, ...queryArgs: QueryArgument[]); /** * Converts this Query to an {@link FQLFragment} you can send * to Fauna. * @returns a {@link FQLFragment}. * @example * ```typescript * const num = 8; * const queryBuilder = fql`'foo'.length == ${num}`; * const queryRequest = queryBuilder.toQuery(); * // produces: * { fql: ["'foo'.length == ", { value: { "@int": "8" } }, ""] } * ``` */ encode(): FQLFragment; }