import { C as ResultRecord, D as StoredObject, E as Statement, S as RemoveQuery, T as SetQuery, _ as PublicModel, b as QueryType, c as CreateQuery, f as GetQuery, g as ModelPreset, h as ModelIndex, i as CombinedInstructions, l as DatabaseResult, m as ModelField, n as AddQuery, p as ListQuery, r as AlterQuery, s as CountQuery, u as DropQuery, v as Query } from "./index-l2pJm30F.js"; //#region ../blade-syntax/dist/schema.d.ts /** * Calculates the absolute value of a number. * * @param value - The number to get absolute value of. * * @returns SQL expression that evaluates to the absolute value. */ declare function abs(value: any): { __RONIN_EXPRESSION: any; }; declare function blob(initialAttributes?: {}): any; declare function boolean(initialAttributes?: {}): any; /** * Concatenates a list of strings together. * * @param values - The list of strings to concatenate. * * @returns An expression representing the concatenated string. */ declare function concat(...values: any[]): { __RONIN_EXPRESSION: any; }; declare function date(initialAttributes?: {}): any; declare function json(initialAttributes?: {}): any; /** * Extracts a value from a JSON document at the specified path. * * @param json - The JSON document to extract from. * @param path - The path to extract the value from. * * @returns SQL expression that evaluates to the extracted value. */ declare function json_extract(json$1: any, path: any): { __RONIN_EXPRESSION: any; }; /** * Inserts a value into a JSON document at the specified path. * Only creates new paths, will not modify existing ones. * * @param json - The JSON document to modify. * @param path - The path to insert the value at. * @param value - The value to insert. * * @returns SQL expression that evaluates to the modified JSON document. */ declare function json_insert(json$1: any, path: any, value: any): { __RONIN_EXPRESSION: any; }; /** * Applies a JSON patch operation to a JSON document. * * @param patch - The JSON patch document defining the modifications. * @param input - The JSON document to patch. * * @returns SQL expression that evaluates to the patched JSON document. */ declare function json_patch(patch: any, input: any): { __RONIN_EXPRESSION: any; }; /** * Replaces a value in a JSON document at the specified path. * Only modifies existing paths, will not create new ones. * * @param json - The JSON document to modify. * @param path - The path to replace the value at. * @param value - The new value. * * @returns SQL expression that evaluates to the modified JSON document. */ declare function json_replace(json$1: any, path: any, value: any): { __RONIN_EXPRESSION: any; }; /** * Sets a value in a JSON document at the specified path. * Creates the path if it doesn't exist and overwrites if it does. * * @param json - The JSON document to modify. * @param path - The path to set the value at. * @param value - The value to set. * * @returns SQL expression that evaluates to the modified JSON document. */ declare function json_set(json$1: any, path: any, value: any): { __RONIN_EXPRESSION: any; }; declare function link(initialAttributes?: {}): any; /** * Generates a model definition and adds default fields to the provided model. * * @example * ```ts * const Account = model({ * slug: 'account', * pluralSlug: 'accounts', * fields: { * name: string() * }, * }); * ``` * * @template T - A generic type representing the model structure, which contains a slug * and fields. * @param model - An object containing the slug and fields of the model. * * @returns The generated model definition. */ declare function model(model$1: any): any; declare function number(initialAttributes?: {}): any; /** * Creates a binary operation expression with type safety for operands. * * @param left - The left operand. * @param operator - The operator to use (string concatenation or arithmetic). * @param right - The right operand (must match type of left operand). * * @returns The formatted binary operation expression. */ declare function op(left: any, operator: any, right: any): { __RONIN_EXPRESSION: any; }; /** * Generates a pseudo-random integer between -9223372036854775808 and +9223372036854775807. * * @returns SQL expression that evaluates to a random number. */ declare function random(): { __RONIN_EXPRESSION: any; }; /** * Replaces all occurrences of a substring within a string with a replacement value. * * @param input - The string to perform replacements on. * @param search - The substring to search for. * @param replacement - The string to replace matches with. * * @returns SQL expression that evaluates to the modified string. */ declare function replace(input: any, search: any, replacement: any): { __RONIN_EXPRESSION: any; }; /** * Wraps a raw SQL expression as-is. * Use with caution as this bypasses SQL injection protection. * * @param expressions - The raw SQL expression to use. * * @returns The wrapped SQL expression */ declare function sql$1(expressions: any): { __RONIN_EXPRESSION: any; }; /** * Formats a timestamp according to the specified format string. * * @param format - The format string (e.g. '%Y-%m-%d'). * @param timestamp - The timestamp to format, or 'now' for current time. * * @returns SQL expression that evaluates to the formatted timestamp. */ declare function strftime(format: any, timestamp: any): { __RONIN_EXPRESSION: any; }; declare function string(initialAttributes?: {}): any; //#endregion //#region ../blade-client/dist/index-D9P9itFa.d.ts //#region src/triggers/index.d.ts type ParentTrigger = { model: string; type: TriggerType; }; interface TriggerOptions> { /** The instructions of the query that is being executed. */ query: TQuery; /** Whether multiple records are being accessed by the query. */ multipleRecords: boolean; /** An instance of the current client, which can be used for nested queries. */ client: ReturnType; /** Can be used for sharing values between the triggers of a model. */ context: Map; /** * If the query was generated by another trigger, this property will contain * information about that trigger. */ parentTrigger?: ParentTrigger; /** The model for which the query is being executed. */ model?: string; /** The database for which the query is being executed. */ database?: string; /** A function for keeping the worker alive as long as a promise is not resolved. */ waitUntil?: QueryHandlerOptions['waitUntil']; /** The list of records, before the query was executed. */ previousRecords: Array; /** The list of records, after the query was executed. */ records: Array; } type ReturnedQueries = () => Array>; type FilteredTriggerQuery = RecursivePartial & Pick; type BeforeTriggerHandler = (options: TOptions) => Array | Promise> | ReturnedQueries | Promise; type DuringTriggerHandler = FilteredTriggerQuery> = (options: TOptions) => TQuery | Promise | Query | Promise; type AfterTriggerHandler = (options: TOptions) => Array | Promise> | ReturnedQueries | Promise; type ResolvingTriggerHandler = (options: TOptions) => TSchema | Promise; type FollowingTriggerHandler = (options: TOptions) => void | Promise; declare const TRIGGER_TYPES: readonly ["before", "during", "after", "resolving", "following"]; type TriggerType = (typeof TRIGGER_TYPES)[number]; type TriggerName = ({ [K in QueryType]: `before${Capitalize}` } | { [K in QueryType]: K } | { [K in QueryType]: `after${Capitalize}` } | { [K in QueryType]: `resolving${Capitalize}` } | { [K in QueryType]: `following${Capitalize}` })[QueryType]; type Trigger> = TStage extends 'before' ? BeforeTriggerHandler : TStage extends 'during' ? DuringTriggerHandler : TStage extends 'after' ? AfterTriggerHandler : TStage extends 'resolving' ? ResolvingTriggerHandler : TStage extends 'following' ? FollowingTriggerHandler : never; type Triggers> = { [K in TriggerName]?: K extends 'before' | `before${string}` ? Trigger<'before', TType, never, TOptions> : K extends 'after' | `after${string}` ? Trigger<'after', TType, never, TOptions> : K extends 'resolving' | `resolving${string}` ? Trigger<'resolving', TType, TSchema, TOptions> : K extends 'following' | `following${string}` ? Trigger<'following', TType, TSchema, TOptions> : Trigger<'during', TType, never, TOptions> }; type TriggersPerModel = Record>; /** * Constructs the method name used for a particular type of trigger and query. * For example, if `triggerType` is "following" and `queryType` is "add", the * resulting method name would be `followingAdd`. * * @param triggerType - The type of trigger. * @param queryType - The type of query. * * @returns The method name constructed from the trigger and query types. */ //#endregion //#region src/types/storage.d.ts type StorableObject = { query: { index: number; type: 'set' | 'add'; }; name?: string; schema: string; field: string; value?: any; contentType: string; reference: StoredObject | null; }; type StorableObjectValue = File | ReadableStream | Buffer | ArrayBuffer | Blob; //#endregion //#region src/types/utils.d.ts interface QueryHandlerOptions { /** * Object containing triggers for defined schemas. */ triggers?: TriggersPerModel; /** * Token used to authenticate against RONIN. By default, * `process.env.RONIN_TOKEN` will be used. */ token?: string; /** * Allows for executing SQL statements generated by the client. * * @param statements - An array of SQL statements to execute. * @param options - Additional configuration for the database call. * * @returns A promise that resolves with the result of the SQL statements. */ databaseCaller?: (statements: Array, options: { database: string; token?: string; stream?: string; }) => Promise | DatabaseResult; /** * Allows for uploading storage objects provided to the client. * * @param object - The object to upload. * @param options - Additional configuration for the storage call. * * @returns A promise that resolves with a reference to the uploaded object. */ storageCaller?: (object: StorableObject, options: { token: string; }) => Promise | StoredObject; /** * Invoked by the query syntax when queries are to be executed. * * @param queries - A list of queries that should be executed. * @param options - Configuration options that were provided for the queries. * * @returns Formatted results for the provided queries. */ syntaxCallback?: (queries: Array, options: QueryHandlerOptions) => Promise>; /** * A particular connection identifier to re-use for the provided queries. * * Useful for ensuring that multiple transactions are sent through the same connection, * which guarantees their order during transport. */ stream?: string; /** * Allows for extending the lifetime of the edge worker invocation until the * provided promise has been resolved. If the `triggers` option is provided on * an edge runtime, this option is required. */ waitUntil?: (promise: Promise) => void; /** * If the query should be run for a specific database within your space, you may * provide the desired database name here. */ database?: string; /** * Allows for indicating whether the client is being invoked from inside of a trigger, * which lets the client ensure that the trigger is not invoked recursively. * * It is highly recommended to rely on `options.client` for running queries in triggers * instead of initializing a custom client, as that resumes the configuration. */ parentTrigger?: ParentTrigger; /** A list of models used for compiling Blade queries to SQL. */ models?: Array; /** * Applies a default `limitedTo` instruction to queries obtaining multiple records. * Useful for environments in which memory is tightly constrained. */ defaultRecordLimit?: number; /** Log helpful debugging information. */ debug?: boolean; } /** * Utility type to make all properties of an object optional. */ type RecursivePartial = { [K in keyof T$1]?: T$1[K] extends Array ? Array> : T$1[K] extends object ? RecursivePartial : T$1[K] }; /** * 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 }; type RegularFormattedResult = number | (T$1 & ResultRecord) | (Array & { moreBefore?: string; moreAfter?: string; }) | null; type ExpandedFormattedResult = Record>; type FormattedResult = RegularFormattedResult | ExpandedFormattedResult; type FormattedResults = Array>; //#endregion //#region src/queries.d.ts declare function runQueriesWithStorageAndTriggers(queries: Array, options: QueryHandlerOptions): Promise>; declare function runQueriesWithStorageAndTriggers(queries: Record>, options: QueryHandlerOptions): Promise>>; //#endregion //#region src/index.d.ts /** * Creates a syntax factory for generating and executing queries. * * @param options - An optional object of options for the query execution. * * Alternatively, a function that returns the object may be provided instead, which is * useful for cases in which the config must be generated dynamically whenever a query * is executed. * * @returns An object with methods for generating and executing different types * of queries. * * ### Usage * ```typescript * const { get, set, add, remove, count } = createSyntaxFactory({ * token: '...' * }); * * await get.accounts(); * * await set.account({ * with: { * email: 'mike@gmail.com', * }, * to: { * status: 'active', * }, * }); * * await add.account({ with: { email: 'mike@gmail.com' } }); * * await remove.accounts.with.emailVerified.notBeing(true); * * await count.accounts(); * * // Execute a batch of operations * const batchResult = await batch(() => [ * get.accounts(), * get.account.with.email('mike@gmail.com') * ]); * ``` */ declare const createSyntaxFactory: (options: QueryHandlerOptions | (() => QueryHandlerOptions)) => { get: DeepCallable; set: DeepCallable; add: DeepCallable; remove: DeepCallable; count: DeepCallable; list: DeepCallable; create: DeepCallable; alter: DeepCallable; drop: DeepCallable; batch: , ...Array>] | Array>>(operations: () => T, queryOptions?: Record) => Promise>; sql: (strings: TemplateStringsArray, ...values: Array) => Promise; sqlBatch: , ...Array>] | Array>>(operations: () => T, queryOptions?: Record) => Promise>; }; declare const get: DeepCallable; declare const set: DeepCallable; declare const add: DeepCallable; declare const remove: DeepCallable; declare const count: DeepCallable; declare const list: DeepCallable; declare const create: DeepCallable; declare const alter: DeepCallable; declare const drop: DeepCallable; declare const batch: , ...Array>] | Array>>(operations: () => T, queryOptions?: Record) => Promise>; declare const sql: (strings: TemplateStringsArray, ...values: Array) => Promise; declare const sqlBatch: , ...Array>] | Array>>(operations: () => T, queryOptions?: Record) => Promise>; declare const runQueries: typeof runQueriesWithStorageAndTriggers; //#endregion //#endregion export { json_insert as A, sql$1 as B, abs as C, date as D, concat as E, model as F, string as H, number as I, op as L, json_replace as M, json_set as N, json as O, link as P, random as R, sqlBatch as S, boolean as T, strftime as V, list as _, Trigger as a, set as b, Triggers as c, batch as d, count as f, get as g, drop as h, StorableObjectValue as i, json_patch as j, json_extract as k, add as l, createSyntaxFactory as m, PromiseTuple as n, TriggerOptions as o, create as p, QueryHandlerOptions as r, TriggerType as s, FormattedResults as t, alter as u, remove as v, blob as w, sql as x, runQueries as y, replace as z };