import { S as AnyFractionalIndex, i as AnyFraci, n as FractionalIndexOf } from "./types-CZ96tVYo.js"; //#region src/drizzle/types.d.ts /** * The stable structural portion of a Drizzle column used by fraci. * * Drizzle's nominal Column class changes between major versions, while the * inferred data slot is shared by every supported version. */ type DrizzleColumnLike = { readonly _: { readonly data: Data; }; }; /** * The stable structural portion of a Drizzle table used by fraci. */ type DrizzleTableLike = { readonly _: unknown; }; /** * Represents a Drizzle ORM column that stores a fractional index. * This type extends the standard Drizzle Column type with additional * type information to ensure type safety when working with fractional indices. * * @template FI - The specific fractional index type this column will store */ type DrizzleFraciColumn = DrizzleColumnLike; /** * Configuration for using fractional indexing with Drizzle ORM. * This type defines the structure needed to integrate fractional indexing * into a Drizzle ORM database schema, including the table, column, and * grouping information. * * @template F - The fractional indexing utility type * @template T - The Drizzle table type * @template FraciColumn - The column type that stores fractional indices * @template Group - The record type for grouping columns * @template Cursor - The record type for cursor columns */ interface DrizzleFraciConfig> = DrizzleFraciColumn>, Group extends Record = Record, Cursor extends Record = Record> { /** A fraci instance. */ readonly fraci: F; /** The table to which the fractional index belongs. */ readonly table: T; /** * The column that stores the fractional index. * Must be branded with the fractional index type using `$type>()`. * * @see {@link FractionalIndexOf} */ readonly column: FraciColumn; /** The columns that define the grouping context for the fractional index. */ readonly group: Group; /** The columns that uniquely identify a row within a group. */ readonly cursor: Cursor; } /** * Represents a cursor for navigating through fractionally indexed rows. * This type maps the cursor columns defined in the configuration to their * corresponding data types, creating a type-safe cursor object. * * @template Config - The Drizzle fractional indexing configuration */ type DrizzleFraciCursor = { [K in keyof Config["cursor"]]: Config["cursor"][K]["_"]["data"]; }; /** * Represents a group context for fractional indices. * This type maps the group columns defined in the configuration to their * corresponding data types, creating a type-safe group object. * * @template Config - The Drizzle fractional indexing configuration */ type DrizzleFraciGroup = { [K in keyof Config["group"]]: Config["group"][K]["_"]["data"]; }; /** * The fractional index type associated with a specific configuration. * This type alias extracts the exact fractional index type from the * configuration's fraci instance. * * @template Config - The Drizzle fractional indexing configuration */ type DrizzleFractionalIndex = FractionalIndexOf; //#endregion //#region src/drizzle/runtime-sync.d.ts /** * Structural type shared by synchronous Drizzle database clients. * * Drizzle renamed its SQLite database base class in v1, while the select API * consumed by fraci stayed compatible. */ type SupportedDrizzleDatabaseSync = { readonly select: any; }; /** * Type representing the enhanced fractional indexing utility for Drizzle ORM with synchronous database engine. * This type extends the base fractional indexing utility with additional * methods for retrieving indices based on synchronous database queries. * * This is the synchronous counterpart to the {@link FraciForDrizzle} type. * * @template Config - The type of the fractional indexing configuration * * @see {@link Fraci} - The base fractional indexing utility type * @see {@link drizzleFraciSync} - The main function to create an instance of this type * @see {@link FraciForDrizzle} - The asynchronous version of this type */ type FraciForDrizzleSync = Config["fraci"] & { /** * Returns the indices to calculate the new index of the item to be inserted after the cursor. * * @param group - A record of the columns that uniquely identifies the group. * @param cursor - A record of the cursor row columns that uniquely identifies the item within a group. If `null`, this function returns the indices to calculate the new index of the first item in the group. * @returns The indices to calculate the new index of the item to be inserted after the cursor. */ readonly indicesForAfter: { (group: DrizzleFraciGroup, cursor: DrizzleFraciCursor): [DrizzleFractionalIndex, DrizzleFractionalIndex | null] | undefined; (group: DrizzleFraciGroup, cursor: null): [null, DrizzleFractionalIndex | null]; }; /** * Returns the indices to calculate the new index of the item to be inserted before the cursor. * * @param group - A record of the columns that uniquely identifies the group. * @param cursor - A record of the cursor row columns that uniquely identifies the item within a group. If `null`, this function returns the indices to calculate the new index of the last item in the group. * @returns The indices to calculate the new index of the item to be inserted before the cursor. */ readonly indicesForBefore: { (group: DrizzleFraciGroup, cursor: DrizzleFraciCursor): [DrizzleFractionalIndex | null, DrizzleFractionalIndex] | undefined; (group: DrizzleFraciGroup, cursor: null): [DrizzleFractionalIndex | null, null]; }; /** * Returns the indices to calculate the new index of the first item in the group. * Identical to {@link FraciForDrizzleSync.indicesForAfter `indicesForAfter(null, group)`}. * * @param group - A record of the columns that uniquely identifies the group. * @returns The indices to calculate the new index of the first item in the group. */ readonly indicesForFirst: (group: DrizzleFraciGroup) => [null, DrizzleFractionalIndex | null]; /** * Returns the indices to calculate the new index of the last item in the group. * Identical to {@link FraciForDrizzleSync.indicesForBefore `indicesForBefore(null, group)`}. * * @param group - A record of the columns that uniquely identifies the group. * @returns The indices to calculate the new index of the last item in the group. */ readonly indicesForLast: (group: DrizzleFraciGroup) => [DrizzleFractionalIndex | null, null]; }; /** * Creates a synchronous fractional indexing utility for Drizzle ORM. * This function enhances a fractional indexing instance with Drizzle-specific * methods for retrieving indices based on synchronous database queries. * * This is the synchronous counterpart to the {@link drizzleFraci} function. * Use this function when working with synchronous SQLite drivers. * The API is identical except that methods return values directly instead of Promises. * * @template Config - The type of the fractional indexing configuration * * @param client - The synchronous Drizzle database client to use for queries (SQLite in sync mode) * @param config - The configuration for fractional indexing * @returns An enhanced fractional indexing utility with Drizzle-specific synchronous methods * * @example * ```typescript * const db = drizzle(connection); * const taskFraci = drizzleFraciSync(db, defineDrizzleFraci({ * fraciString({ lengthBase: BASE62, digitBase: BASE62 }), * tasks, * tasks.position, * { userId: tasks.userId }, * { id: tasks.id } * })); * * // Get indices for inserting at the beginning of a user's task list * // Note: No await needed since this is synchronous * const [a, b] = taskFraci.indicesForFirst({ userId: 123 }); * const [newPosition] = taskFraci.generateKeyBetween(a, b); * ``` * * @see {@link drizzleFraci} - The asynchronous version of this function */ declare function drizzleFraciSync(client: SupportedDrizzleDatabaseSync, config: Config): FraciForDrizzleSync; //#endregion //#region src/drizzle/runtime.d.ts /** * Structural type shared by asynchronous Drizzle database clients. * * Drizzle renamed its public database base classes in v1. Depending only on * the query entry point used by fraci keeps this type compatible with both * Drizzle v0 and v1 without weakening the inferred table, group, or cursor * types. */ type SupportedDrizzleDatabase = { readonly select: any; }; /** * Type representing the enhanced fractional indexing utility for Drizzle ORM with asynchronous database engine. * This type extends the base fractional indexing utility with additional * methods for retrieving indices based on asynchronous database queries. * * @template Config - The type of the fractional indexing configuration * * @see {@link drizzleFraci} - The main function to create an instance of this type * @see {@link FraciForDrizzleSync} - The synchronous version of this type */ type FraciForDrizzle = Config["fraci"] & { /** * Returns the indices to calculate the new index of the item to be inserted after the cursor. * * @param group - A record of the columns that uniquely identifies the group. * @param cursor - A record of the cursor row columns that uniquely identifies the item within a group. If `null`, this function returns the indices to calculate the new index of the first item in the group. * @returns The indices to calculate the new index of the item to be inserted after the cursor. */ readonly indicesForAfter: { (group: DrizzleFraciGroup, cursor: DrizzleFraciCursor): Promise<[DrizzleFractionalIndex, DrizzleFractionalIndex | null] | undefined>; (group: DrizzleFraciGroup, cursor: null): Promise<[null, DrizzleFractionalIndex | null]>; }; /** * Returns the indices to calculate the new index of the item to be inserted before the cursor. * * @param group - A record of the columns that uniquely identifies the group. * @param cursor - A record of the cursor row columns that uniquely identifies the item within a group. If `null`, this function returns the indices to calculate the new index of the last item in the group. * @returns The indices to calculate the new index of the item to be inserted before the cursor. */ readonly indicesForBefore: { (group: DrizzleFraciGroup, cursor: DrizzleFraciCursor): Promise<[DrizzleFractionalIndex | null, DrizzleFractionalIndex] | undefined>; (group: DrizzleFraciGroup, cursor: null): Promise<[DrizzleFractionalIndex | null, null]>; }; /** * Returns the indices to calculate the new index of the first item in the group. * Identical to {@link FraciForDrizzle.indicesForAfter `indicesForAfter(null, group)`}. * * @param group - A record of the columns that uniquely identifies the group. * @returns The indices to calculate the new index of the first item in the group. */ readonly indicesForFirst: (group: DrizzleFraciGroup) => Promise<[null, DrizzleFractionalIndex | null]>; /** * Returns the indices to calculate the new index of the last item in the group. * Identical to {@link FraciForDrizzle.indicesForBefore `indicesForBefore(null, group)`}. * * @param group - A record of the columns that uniquely identifies the group. * @returns The indices to calculate the new index of the last item in the group. */ readonly indicesForLast: (group: DrizzleFraciGroup) => Promise<[DrizzleFractionalIndex | null, null]>; }; /** * Creates an asynchronous fractional indexing utility for Drizzle ORM. * This function enhances a fractional indexing instance with Drizzle-specific * methods for retrieving indices based on asynchronous database queries. * * This is the asynchronous version that works with all supported database engines. * For synchronous SQLite drivers, use the {@link drizzleFraciSync} function. * The API is identical except that methods return Promises instead of direct values. * * @template Config - The type of the fractional indexing configuration * * @param client - The asynchronous Drizzle database client to use for queries * @param config - The configuration for fractional indexing * @returns An enhanced fractional indexing utility with Drizzle-specific asynchronous methods * * @example * ```typescript * const db = drizzle(connection); * const taskFraci = drizzleFraci(db, defineDrizzleFraci({ * fraciString({ lengthBase: BASE62, digitBase: BASE62 }), * tasks, * tasks.position, * { userId: tasks.userId }, * { id: tasks.id } * })); * * // Get indices for inserting at the beginning of a user's task list * // Note: await is needed since this is asynchronous * const [a, b] = await taskFraci.indicesForFirst({ userId: 123 }); * const [newPosition] = taskFraci.generateKeyBetween(a, b); * ``` * * @see {@link drizzleFraciSync} - The synchronous version of this function */ declare function drizzleFraci(client: SupportedDrizzleDatabase, config: Config): FraciForDrizzle; //#endregion //#region src/drizzle/schema.d.ts /** * Creates a configuration object for fractional indexing with Drizzle ORM. * This function defines how fractional indices are integrated into a Drizzle schema, * specifying the table, column, grouping context, and cursor information. * * @template F - The fractional indexing utility type * @template T - The Drizzle table type * @template FraciColumn - The column type that stores fractional indices * @template Group - The record type for grouping columns * @template Cursor - The record type for cursor columns * * @param fraci - The fractional indexing utility instance * @param table - The Drizzle table object * @param column - The column that will store the fractional index * @param group - The columns that define the grouping context * @param cursor - The columns that uniquely identify a row within a group * @returns A configuration object for fractional indexing */ declare function defineDrizzleFraci>, Group extends Record, Cursor extends Record>(fraci: F, table: T, column: FraciColumn, group: Group, cursor: Cursor): DrizzleFraciConfig; //#endregion export { type DrizzleColumnLike, type DrizzleFraciColumn, type DrizzleFraciConfig, type DrizzleFraciCursor, type DrizzleFraciGroup, type DrizzleFractionalIndex, type DrizzleTableLike, FraciForDrizzle, FraciForDrizzleSync, SupportedDrizzleDatabase, SupportedDrizzleDatabaseSync, defineDrizzleFraci, drizzleFraci, drizzleFraciSync }; //# sourceMappingURL=drizzle.d.ts.map