UNPKG

@convo-lang/convo-lang

Version:
35 lines (34 loc) 2.39 kB
import { CancelToken } from "@iyio/common"; import { PromiseOrResultType, PromiseResultType, ResultType } from "../result-type.js"; import { ConvoDb, ConvoDbFunctionCall, ConvoDbFunctionExecutionContext, ConvoDbFunctionImplementation, ConvoNode, ConvoNodeKeySelection, ConvoNodeQuery, ConvoNodeQueryStep, ConvoNodeStreamItem, ParsedConvoDbFunctionArgsType } from "./convo-db-types.js"; export interface CreateConvoDbFunctionExecutionContextResult { /** * The context that can be used to call a db function */ ctx: ConvoDbFunctionExecutionContext; /** * If true the main source of the function was compiled. The caller of `createConvoDbFunctionExecutionContextAsync` * may now choose to save the compile main to the node in the database for future reuse. */ mainWasCompiled: boolean; /** * If true the arg types where parsed. The caller of `createConvoDbFunctionExecutionContextAsync` * may now choose to save the parsed args to the node in the database for future reuse. */ argsTypeWereParsed: boolean; } /** * Create a ConvoDbFunctionExecutionContext that can be passed to `executeConvoDbFunction` * @param compileAndParse If true main will be compiled if needed and args type will be parsed if needed. * @param node * @param keys * @param call * @param db * @param query * @param step * @param paths * @returns */ export declare const createConvoDbFunctionExecutionContextAsync: (compileAndParse: boolean, node: ConvoNode, keys: ConvoNodeKeySelection, call: ConvoDbFunctionCall, db: ConvoDb, query: ConvoNodeQuery, step: ConvoNodeQueryStep, paths: string[], fnNextToken: string | undefined, cancel: CancelToken) => PromiseResultType<CreateConvoDbFunctionExecutionContextResult>; export declare const parseConvoDbFunctionArgsType: (argsType: string) => ResultType<ParsedConvoDbFunctionArgsType>; export declare function executeConvoDbFunction<TKeys extends ConvoNodeKeySelection = '*'>(ctx: ConvoDbFunctionExecutionContext, getRefFunction?: (uri: string) => PromiseOrResultType<ConvoDbFunctionImplementation>): AsyncIterableIterator<ConvoNodeStreamItem<TKeys extends null | undefined ? keyof ConvoNode : TKeys extends "*" ? keyof ConvoNode : TKeys extends keyof ConvoNode ? TKeys : TKeys extends (infer U)[] ? "*" extends U ? keyof ConvoNode : Exclude<U, "*" | null | undefined> & keyof ConvoNode : keyof ConvoNode>>;