@softr/sdk
Version:
The SDK for building Softr apps on TanStack Start. It lets an app interact with Softr: auth, datasources, workflows and integrations.
51 lines (50 loc) • 1.85 kB
TypeScript
import { ActionShape, DatasourceAction, ReadShape } from "../action.js";
import "@tanstack/react-start/server-only";
//#region src/core/options.d.ts
/** One choice of a SELECT field, as the field holds it now. */
type FieldChoice = {
id: string;
label: string;
color: string | null;
};
/**
* The choices a SELECT field holds right now, read from Softr on every call. A choice the
* builder adds or renames later shows up without a new build. The field must be one the
* action declares. Any query or mutation over the table works.
*
* @example
* const loadCategories = createServerFn().handler(() => ds.choices(products, 'category'))
*/
declare function listChoices<TShape extends ActionShape>(action: DatasourceAction<TShape>, field: keyof TShape["fields"] & string): Promise<Array<FieldChoice>>;
/** One row a linked-record picker offers. */
type RecordOption = {
id: string;
label: string;
};
/** A page of a picker's rows, in the shape `LinkedRecordPicker`'s `load` answers with. */
type RecordOptions = {
options: RecordOption[];
nextOffset: number | null;
};
/**
* The rows a linked field can point at, for a picker: each record of the query as its id and the text
* of one field, searched on that field when a term is given, a page at a time.
*
* @example
* const loadCompanies = createServerFn()
* .validator(z.object({ term: z.string(), offset: z.number().nullable() }))
* .handler(({ data }) => ds.options(companiesQuery, { label: 'name', ...data }))
*/
declare function listOptions<TShape extends ReadShape>(query: DatasourceAction<TShape>, {
label,
term,
offset,
limit
}: {
label: keyof TShape["fields"] & string;
term?: string;
offset?: number | null;
limit?: number;
}): Promise<RecordOptions>;
//#endregion
export { FieldChoice, RecordOption, RecordOptions, listChoices, listOptions };