import type { CombiTableColumn } from "./combitabletypes"; export interface PrismaFields { take?: number; skip?: number; where?: { [key: string]: any; }; orderBy?: { [key: string]: "asc" | "desc"; }; } export interface PrismaField { name: string; kind: string; type: string; } export interface PrismaModel { name: string; fields: readonly PrismaField[]; } export interface PrismaFieldMap { [key: string]: PrismaField; } export interface PrismaModelMap { name: string; fields: PrismaFieldMap; } export interface PrismaModelMaps { [key: string]: PrismaModelMap; } /** * * Creates and parses URLs which have the following: * * - `s` sort field optionally prefixed with `+` or `-` * - `f` filter string which is `fieldname:value`. Multiple filters separated by comma * - `t` take: return at most this number odf rows * - `k` skip: skip this number of rows * - `b` back URL - all of the above, prefixed with the pathname and `?`, URL-encoded. * - `i` individual ids, comma-separated * * `b` may also contain a `b` so this is recursive */ export declare class SearchUrl { defaultTake: number; private _url; get url(): URL | undefined; readonly body: { [key: string]: any; } | undefined; suffix: string; idColumn: string; emptySearch: string | undefined; insensitive: boolean; private disallowedColumns; /** * Construct from a URL * @param url the URL to construct from (eg $page.url) * @param defaultTake if passed, use this for pagination size. If omitted * then `P`UBLIC_SEARCHURL_DEFAULT_TAKE` env variable is used. * If that is also not present, 20 is used * @param emptySearch For filtering, you can use this value to indicate * filter for empty values. Default `-` */ constructor(url: URL | { [key: string]: any; }, defaultTake?: number | undefined, emptySearch?: string | undefined, backUrl?: SearchUrl | undefined | null); /** * You may have multiple tables in the same page, each with different filter and sort values. * If this is the case, give each one a name with this method. * @param val All URL parameters set by SearchUrl will have this appended, eg `"1"`, `"2"` etc. * Default is no suffix */ setSuffix(val: string | undefined): void; /** * Returns the suffix set in `setSuffix` * @returns */ getSuffix(): string; /** * For some sorts, the id of the table is needed. Default `id_pk`. * * Relevant for Prisma only. If you are not using the Prisma functionality * you can ignore this, * @param val */ setIdColumn(val: string): void; /** * Returns the value set `setIdColumn` * @returns the name of the ID column */ getIdColumn(): string; /** * For Prisma searches, indicate search should be case insensitve * (only works where the Prisma API allows this to be set, ie in * `contains`). Default false * @param val */ setInsensitive(val: boolean): void; /** * Returns whether Prisma contains searches are set to insensitive * @returns the value set in `setInsensitive` */ getInsensitive(): boolean; setDisallowedColumns(cols: string[]): void; private columnIsDisallowed; /** * Sets the sort URL parameter * @param col the column to sort on * @param direction the sort direction */ sort(col: string, direction?: "ascending" | "descending"): void; /** * Returns the sorting set in the URL parameters * @param defaultCol if there is no sort value in the URL parametersm return this, * @returns the sort column and direction */ getSort(defaultCol?: string): { sortCol: string; sortDirection: "ascending" | "descending"; }; /** * Set the default sort column, overriding what is in the constructor * @param col the default column to sort by */ setDefaultSortCol(col: string): void; /** * Sets the URL parameters to return only these IDs instead of a value-based filter * @param vals the IDs to return */ ids(vals: number[] | undefined): void; /** * Returns the set of IDs from the URL parameters * @returns IDs as set in `ids()` */ getIds(): number[]; /** * You can filter on multiple values (ANDed). Add the given condition to the filters * @param col filter on this column * @param value the column must have this value (can include `*`) */ setFilterComponent(col: string, value: string): void; /** * Pre-filters are applied regardless of what is in the regular filter set. * Use this if you have a table that should only ever display a subset * of the data even when there is no user-defined filter * @param col column to filter by * @param value the column must have this value (can include `*`) */ setPreFilterComponent(col: string, value: string): void; private setFilterComponent_internal; /** * Set miltiple filters at once * @param values column/value pairs * @returns */ setFilters(values: { [key: string]: string; }): void; /** * Set miltiple pre-filters at once * @param values column/value pairs * @returns */ setPreFilters(values: { [key: string]: string; }): void; private setFilters_internal; /** * Returns all the set filöters * @returns filters are column/value pairs */ getFilters(): { [key: string]: string; }; /** * Returns all the set pre-filöters * @returns pre-filters are column/value pairs */ getPreFilters(): { [key: string]: string; }; private getFilters_internal; /** * Returns the take parameter in the URL which is the maximum number of * results to return. (Prisma `take` value) * @returns the number of rows to return as set in the URL params */ getTake(): number; /** * Returns the take parameter in the URL which is the maximum number of * results skip before returning the `take` number of rows. * (Prisma `skip` value) * @returns the number of rows to skip as set in the URL params */ getSkip(): number; /** * Puts the maximum number of rows to return in the URL params (Prisma `take`) * @param val the number of rows to return */ take(val: number): void; /** * Puts the number of rows to skip in the URL params (Prisma `skip`) * @param val the number of rows to skip */ skip(val: number): void; /** * Returns the URL-encoded search params * @returns URL-encoded search params */ encode(): string; /** * You can inplement go-to-previous-url functionality by setting the * `b` field in the URL params to a `SearchUrl` using this method. * * This `SearchUrl` can then be popped of with `popBack`. * * Back URLs are chained so you can keep a stain by repeatedly calling * `setBack` and `getBack` * @param back the url to set as back (eg the current URL) */ setBack(back: SearchUrl): void; private clipBack; /** * See `setBack` * @returns */ popBack(): SearchUrl | null; static makePrismaWhere(name: string, value: string, models: PrismaModelMaps, modelName: string, { suffix, emptySearch, columns, insensitive, tz }?: { suffix?: string; emptySearch?: string; columns?: CombiTableColumn[]; insensitive?: boolean; tz?: string; }): { [key: string]: any; }; static makePrismaOrderBy(name: string, direction: "asc" | "desc", suffix?: string): { [key: string]: any; }; /** * Convenience function to retun the URL search params as a string * @returns string representation of URL search params */ searchParamsAsString(): string; }