/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * A query's calls answered in memory (#940, #941), where there is no server: * a host that answers a query's calls itself, as `createInMemoryFunctionApi` * stands in for a deployed function. The builder's tests run its calls on e3 * itself (#1376); one uses these as a host of its own would. * * - **A one-shot call** ({@link createInMemoryQueryCall}), which the builder * makes through it when a `QueryCallProvider` hands it over. * - **A split call** ({@link createInMemorySplitCall}), run as e3 runs one: * the partitioned dataset cut into pieces — datasets partitioned together * cut at the same keys — each piece's program run, the pieces' outputs * assembled by the output kind and kept by their hash, which a later call's * `object` argument reads, and the final function run once over them and * the arguments not partitioned (#1107) — through a * `QuerySplitCallProvider`; and its explain, the pieces it cuts with none * run (#1132). * - **A data source's status** ({@link createInMemorySourceStatus}): what each * dataset holds and weighs — through a `QuerySourceStatusProvider`. * * @packageDocumentation */ import { type EastType } from "@elaraai/east"; import { type TreePath } from "@elaraai/e3-types"; import type { QueryCall, QuerySourceStatus, QuerySplitCall, QuerySplitExplain } from "./hooks.js"; /** * A dataset an in-memory call may read. * * @property path - Its path in the workspace, as a call's argument names it * @property type - Its East type * @property value - Its value * @property hash - The hash a run pins it at; the SHA-256 of its beast2 bytes when omitted * @property bytes - What it weighs in the store, as its status says; its beast2 bytes' length when omitted */ export interface InMemoryDataset { /** Its path in the workspace, as a call's argument names it. */ readonly path: TreePath; /** Its East type. */ readonly type: EastType; /** Its value. */ readonly value: unknown; /** The hash a run pins it at; the SHA-256 of its beast2 bytes when omitted. */ readonly hash?: string; /** What it weighs in the store, in bytes, as its status says; its beast2 bytes' length when omitted. A test weighs a small dataset as a large one with it. */ readonly bytes?: number; } /** * Builds a one-shot call answered in memory, as e3 answers one: the request's * body decoded from its IR and compiled with no platform function — a query's * call is platform-free — then called with the value of each dataset its * arguments name, each pinned at its hash. * * @param datasets - The datasets a call may read * @returns The call * * @remarks * - **Success**: the answer, beast2 at the body's output type, and each * dataset read with its hash. * - **Failed**: a body that raises an East error fails as a runner's run does — * exit code 1, and on stderr `Error: ` with each place it was * raised, so the builder places it in the jq. * - **Invalid**: an argument naming no dataset here is refused as e3 refuses * an unassigned one ("Dataset argument 0 is not assigned"), and an inline * value as one this stand-in does not take. * - **Too large**: an answer over the request's `maxResultBytes`. * * The time limit is not kept: a body runs to its end. * * @example * ```tsx * const call = createInMemoryQueryCall([ * { path: [variant("field", "inputs"), variant("field", "orders")], type: ArrayType(Order), value: orders }, * ]); * return {surface}; * ``` */ export declare function createInMemoryQueryCall(datasets: readonly InMemoryDataset[]): QueryCall; /** Options for {@link createInMemorySplitCall}. */ export interface InMemorySplitCallOptions { /** * How many pieces the partitioned dataset is cut into, in order: as near * equal runs of its rows as can be, some empty when there are more pieces * than rows. */ readonly pieces: number; } /** * A split call answered in memory ({@link createInMemorySplitCall}), and its * explain (#1132): what e3's explain of the same call answers, with no piece * run. */ export type InMemorySplitCall = QuerySplitCall & { /** How many pieces a call cuts, the argument they are cut over and what it weighs. */ readonly explain: QuerySplitExplain; }; /** * Builds a split call answered in memory, run as e3 runs one: the request's * programs decoded and compiled with no platform function — a plan's are * platform-free — the partitioned dataset cut into a given number of pieces, * each piece's program run with an `emit` that collects what it emits, the * pieces' outputs assembled by the output kind, and the final function run * once over the assembled output and then the arguments not partitioned, in * their order, as e3 gives them (#1107). * * @param datasets - The datasets a call may read * @param options - How many pieces the partitioned dataset is cut into * @returns The call, and its `explain` * * @remarks * Each output kind assembles as e3 assembles it (`e3-data-architecture.md` * §3.7), a piece at a time and then across the pieces in input order: * - `array`: each piece's rows, concatenated; * - `set`: their union, in East's order; * - `dict`: by key, a key emitted again folded with `merge(key, a, b)` in * emission order — within a piece, then across the pieces; without `merge`, * a key emitted twice fails, naming it; * - `first` (#1110): the first `limit` rows an `array` would hold, in input * order — every piece run, where e3 stops once it has them; * - `fold`: every value a piece emits folded with `combine`, starting from * `zero`; then the pieces' partials folded the same way. * * Arguments partitioned together — dicts keyed alike (#942) — are cut at the * same keys: the first key of each run of the one whose beast2 bytes weigh * the most. The assembled output is kept by the SHA-256 of its beast2 bytes, * which the answer gives, and a later call of this stand-in reads it by that * hash as an `object` argument, as e3 reads an earlier call's output. * * With no `then`, the call's value is the assembled output. Its answer is as a * one-shot call's: beast2 at the value's type with each dataset argument * pinned at its hash, `failed` for an East error with its places on stderr, * `invalid` for an argument naming nothing here — a dataset, or an object no * call of this stand-in assembled — for arguments that cannot be cut * together, or for a final function that takes any other count than the * assembled output and the arguments not partitioned, and `too_large` over the * request's `maxResultBytes`. It reports * each piece done, then the merge or the fold, to `onProgress`, yielding * between pieces, and rejects with the signal's reason once abandoned. The * time limit is not kept, and its answer has no `report`: e3's says how its * units ran, and this stand-in runs none. * * Its `explain` answers what e3's explain of the same call does, and runs no * piece (#1132): how many pieces the call cuts — `pieces`, whatever the data — * the argument it cuts them over, by its position — the one partitioned, or of * several, the one whose beast2 bytes weigh the most — and what that argument * weighs: a dataset's weight as its status says it, else its beast2 bytes. It * rejects with an `Error` what the call answers `invalid`, as e3-api-client's * `splitCallExplain` does — "Split call explain refused: …" — reads an object * argument an earlier call of this stand-in assembled, and rejects with the * signal's reason once abandoned. * * @example * ```tsx * const split = createInMemorySplitCall([{ path: ORDERS, type: OrdersType, value: orders }], { pieces: 7 }); * return {surface}; * ``` */ export declare function createInMemorySplitCall(datasets: readonly InMemoryDataset[], options: InMemorySplitCallOptions): InMemorySplitCall; /** * Builds a data source's status answered in memory: how many rows each * dataset holds, its hash, and what it weighs — its beast2 bytes' length, or * the weight a test gives it. * * @param datasets - The datasets * @returns The status * * @remarks * A list's, a set's or a lookup table's rows are its elements; any other * value's are not counted. A path with nothing in memory is refused, as e3 * refuses a dataset it does not hold. * * @example * ```tsx * const status = createInMemorySourceStatus([{ path: ORDERS, type: OrdersType, value: orders }]); * return {surface}; * ``` */ export declare function createInMemorySourceStatus(datasets: readonly InMemoryDataset[]): QuerySourceStatus; //# sourceMappingURL=in-memory-call.d.ts.map