@softr/sdk
Version:
The SDK for building Softr apps on TanStack Start. It lets an app interact with Softr: auth, datasources, workflows and integrations.
45 lines (43 loc) • 2.22 kB
TypeScript
import { Formatting } from "../formatting.js";
//#region src/fields/format.d.ts
/**
* A field's type and options, which is all its text depends on. The generated `src/softr-fields.ts`
* holds one per field of every registered datasource.
*/
type FieldShape = {
type: string;
options?: Record<string, unknown> | null;
/** True when the field holds several values, which read back as an array. */
allowMultipleEntries?: boolean;
};
/** The fields of every registered datasource, by datasource id then field id. */
type SoftrFieldRegistry = Record<string, Record<string, FieldShape>>;
/**
* Makes the app's fields known to `fieldShape` and `formatValue`. The generated `src/softr-fields.ts`
* calls it once as a side effect of being imported; the root route imports that file.
*/
declare function registerSoftrFields(fields: SoftrFieldRegistry): void;
/**
* The shape of a field a query reads, by the alias the query holds it under. Throws when the app has
* not registered its fields: the generated `src/softr-fields.ts` is not imported.
*/
declare function fieldShape(query: {
datasourceId: string;
fields: Record<string, string>;
}, alias: string): FieldShape;
/**
* A value a query read, as the text a page shows it as, by the field's own type and options: money with
* its symbol, a date in the app's format, a choice or a linked record by its label, a rating out of its
* scale, a duration in hours and minutes, a checkbox as Yes or No. '' for a value the record does not
* hold. Several values read joined by a comma.
*/
declare function formatValue(query: {
datasourceId: string;
fields: Record<string, string>;
}, alias: string, value: unknown, formatting: Formatting): string;
/** `formatValue` for a shape in hand, such as one from `src/softr-fields.ts` or a `returnedField`. */
declare function formatField(shape: FieldShape, value: unknown, formatting: Formatting): string;
/** A duration, which the datasource holds in milliseconds, as hours and minutes; seconds only under an hour. */
declare function formatDuration(milliseconds: number): string;
//#endregion
export { FieldShape, SoftrFieldRegistry, fieldShape, formatDuration, formatField, formatValue, registerSoftrFields };