import { CombinedInstructions, Query, ResultRecordBase, Statement, WithInstruction } from "blade-compiler"; //#region src/queries/types.d.ts type ResultRecord = ResultRecordBase; type WithInstructionKeys = T$1 extends WithInstruction ? keyof (T$1 extends Array ? U : T$1) : never; /** * A recursive type making every property callable and chainable. * * - If `Query` (minus null/undefined) is an object: * -- The call signature is `(arg?: Partial>) => Promise & DeepCallable`. * -- Each key in `Query` is also a `DeepCallable`, excluding null/undefined from the * sub-type so that calls to optional properties do not raise "possibly undefined" errors. * * - Otherwise (if it's a primitive like string/number/etc, or strictly null/undefined): * -- The call signature is `(arg?: Query) => Promise & DeepCallable`. * -- Can call it with an optional argument, and it returns a promise & chainable methods. * * This approach means you can do e.g. `get.spaces.orderedBy.descending(['handle'])` * without TS complaining about `descending` being possibly undefined, and every call * remains `await`able (returning `Result`) as well as chainable. */ type DeepCallable = [NonNullable] extends [object] ? /** * Calls the object with an optional partial argument, returning a promise that * resolves to `Result` and also remains a DeepCallable for further nested calls. */ ObjectCall>> & { [K in keyof NonNullable]-?: DeepCallable[K], null | undefined>, Result> & (K extends 'with' ? { [P in WithInstructionKeys[K]>]: ObjectCall } : object) } : ObjectCall; type InstructionMethods = { [K in keyof CombinedInstructions]-?: ObjectCall> }; /** * A helper function type used by `DeepCallable`. * * @typeParam Query - The `Query` type for recursion. * @typeParam DefaultResult - The default result if no generic is specified. * @typeParam Arg - The type of the call's optional argument. * * The call returns a `Promise`, with `FinalResult` defaulting to * `DefaultResult` if no generic is provided. It also remains chainable by returning * `DeepCallable`. */ type ObjectCall = ((arg?: ((f: Record) => Arg | any) | Arg | Array, options?: Record) => Promise & InstructionMethods & DeepCallable) & ReducedFunction; /** * Utility type to mark all Function.prototype methods as "deprecated" which * deranks them in the IDE suggestion popup. */ interface ReducedFunction { /** * @deprecated */ name: any; /** * @deprecated */ length: never; /** * @deprecated */ apply: never; /** * @deprecated */ call: never; /** * @deprecated */ bind: never; /** * @deprecated */ toString: never; /** * @deprecated */ caller: never; /** * @deprecated */ prototype: never; /** * @deprecated */ arguments: never; /** * @deprecated */ unify: never; } //#endregion //#region src/utils/index.d.ts declare const setProperty: (obj: T, path: string, value: K) => T; /** * Gets the property value of an object based on the given path segments * of the property. * * @param obj - The object to get the property value from. * @param pathSegments - An array of property keys leading up to the final * property at the end. * * @returns The property value at the specified path or `undefined` if the path * does not exist. * * @example * const exampleObject = \{ * user: \{ * name: \{ * first: 'John', * last: 'Doe' * \}, * age: 30 * \} * \}; * console.log(getProperty(exampleObject, ['user', 'name', 'first'])); // Output: 'John' * console.log(getProperty(exampleObject, ['user', 'age'])); // Output: 30 * console.log(getProperty(exampleObject, ['user', 'non', 'existing'])); // Output: undefined */ declare const getProperty: (obj: object, path: string) => unknown; //#endregion //#region src/queries/statements.d.ts /** * Provides a template literal function that, when called, constructs an SQL statement * and a separate list of parameters for the statement. * * @param options - An object containing configuration for the composed structure. * * @returns A function for constructing SQL statements. */ declare const getSyntaxProxySQL: (options: { callback: (statement: Statement) => Promise | any; }) => (strings: TemplateStringsArray, ...values: Array) => Promise; /** * Obtains a list of SQL statements from a function by wrapping the SQL functions into a * context that prevents the SQL statements from being executed. * * @param operations - A function that contains multiple SQL functions. * * @returns A list of SQL statements. */ declare const getBatchProxySQL: (operations: () => Array | Array>) => Array; //#endregion //#region src/queries/index.d.ts /** * Utility type to convert a tuple of promises into a tuple of their resolved types. */ type PromiseTuple, ...Array>] | Array>> = { [P in keyof T$1]: Awaited }; /** * Utility type that represents a particular query and any options that should * be used when executing it. */ interface SyntaxItem { structure: Structure$1; options?: Record; } /** * A utility function that creates a proxy object to handle dynamic property access and * function calls, which is used to compose the query and schema syntax. * * @param config - An object containing configuration for the composed structure. * * @returns A proxy object that intercepts property access and function calls. * * ### Usage * ```typescript * const getProxy = getSyntaxProxy({ * root: `${QUERY_SYMBOLS.QUERY}.get`, * // Execute the query and return the result * callback: async (query) => {} * }); * * const result = await get.account(); * * const result = await get.account.with.email('mike@gmail.com'); * ``` */ declare const getSyntaxProxy: (config?: { root?: string; callback?: (query: Query, options?: Record) => Promise | any; replacer?: (value: unknown) => unknown | undefined; propertyValue?: unknown; modelType?: boolean; chaining?: boolean; }) => DeepCallable; /** * Obtains a list of queries from a function by wrapping the queries into a context. * * @param operations - A function that contains multiple query functions. * * @returns A list of queries and their respective options. * * ### Usage * ```typescript * const queries = getBatchProxy(() => [ * get.accounts(), * get.account.with.email('mike@gmail.com') * ]); * ``` */ declare const getBatchProxy: (operations: () => Array | Promise>) => Array>; //#endregion export { getBatchProxySQL as a, setProperty as c, ResultRecord as d, getSyntaxProxy as i, DeepCallable as l, SyntaxItem as n, getSyntaxProxySQL as o, getBatchProxy as r, getProperty as s, PromiseTuple as t, ReducedFunction as u };