import { SQL } from 'drizzle-orm'; type TableCursor = { order?: "ASC" | "DESC"; key: string; schema: unknown; }; type SQLCursor = { order?: "ASC" | "DESC"; key: string; sql: SQL; }; type Cursor = TableCursor | SQLCursor; type RelationsOrderBy = Record; type RelationsWhere = { RAW?: (table: unknown) => SQL; [key: string]: unknown; }; /** * C is an optional parameter for user-facing type annotations * (e.g. `CursorConfig`). * * generateCursor uses the non-parameterised form `CursorConfig` (= CursorConfig) * as its constraint so TypeScript infers C as the full config literal type, not as a * unified cursor type — which would fail when different columns are used as cursors. */ type CursorConfig = { primaryCursor: C; cursors?: Array; }; /** * decoder: similar to `atob()` but compatible with UTF-8 strings * converts a base64 encoded string to a UTF-8 string * @link https://developer.mozilla.org/en-US/docs/Web/API/atob */ declare const decoder: (data: string) => string; /** * encoder: similar to `btoa()` but compatible with UTF-8 strings * converts a UTF-8 string to a base64 encoded string * @link https://developer.mozilla.org/en-US/docs/Web/API/btoa */ declare const encoder: (str: string) => string; /** * parser: similar to `JSON.parse()` * converts a JSON string to a JavaScript object * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse */ declare const parser: { (text: string, reviver?: ((this: any, key: string, value: any) => any) | undefined): any; (text: string, reviver?: ((this: any, key: string, value: any) => any) | undefined): unknown; }; /** * serializer: similar to `JSON.stringify()` * converts a JavaScript object to a JSON string * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify */ declare const serializer: { (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }; /** * parse: * takes a cursor and returns a JavaScript object * useful to retrive object from the FE client token */ declare function parse = Record>({ primaryCursor, cursors }: CursorConfig, cursor?: string | null, decoder?: (data: string) => string, parser?: { (text: string, reviver?: ((this: any, key: string, value: any) => any) | undefined): any; (text: string, reviver?: ((this: any, key: string, value: any) => any) | undefined): unknown; }): T | null; /** * serialize: * takes a JavaScript object and returns a cursor * useful to generate token to the FE client */ declare function serialize = Record>({ primaryCursor, cursors }: CursorConfig, data?: T | null, encoder?: (str: string) => string, serializer?: { (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }): string | null; type CursorIsSql = C extends SQLCursor ? true : false; type ConfigHasSqlCursor = true extends CursorIsSql ? true : C["cursors"] extends Array ? true extends CursorIsSql ? true : false : false; /** * When every cursor uses `schema`, `relations.orderBy` is a plain * `Record` (RQB v2 field-name form). * * When any cursor uses `sql`, it becomes `() => SQL[]` — pass it directly * as the RQB v2 `orderBy` callback so the SQL expression is evaluated. */ type RelationsOrderByFor = ConfigHasSqlCursor extends true ? () => Array : RelationsOrderBy; declare const generateCursor: (config: C, options?: { /** * decoder: similar to `atob()` but compatible with UTF-8 strings * converts a base64 encoded string to a UTF-8 string * @link https://developer.mozilla.org/en-US/docs/Web/API/atob */ decoder?: typeof decoder; /** * encoder: similar to `btoa()` but compatible with UTF-8 strings * converts a UTF-8 string to a base64 encoded string * @link https://developer.mozilla.org/en-US/docs/Web/API/btoa */ encoder?: typeof encoder; /** * parser: similar to `JSON.parse()` * converts a JSON string to a JavaScript object * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse */ parser?: typeof parser; /** * serializer: similar to `JSON.stringify()` * converts a JavaScript object to a JSON string * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify */ serializer?: typeof serializer; /** * parse: * takes a cursor and returns a JavaScript object * useful to retrive object from the FE client token */ parse?: typeof parse; /** * serialize: * takes a JavaScript object and returns a cursor * useful to generate token to the FE client */ serialize?: typeof serialize; }) => { orderBy: SQL[]; where: (lastPreviousItemData?: Record | string | null) => SQL | undefined; relations: { orderBy: RelationsOrderByFor; where: (lastPreviousItemData?: Record | string | null) => { OR: RelationsWhere[]; } | undefined; }; parse: (cursor: string | null) => Record | null; serialize: (data?: Record | null) => string | null; }; export { type Cursor, type CursorConfig, type RelationsOrderBy, type RelationsWhere, type SQLCursor, type TableCursor, decoder, generateCursor as default, encoder, generateCursor, parse, parser, serialize, serializer };