UNPKG

instantdb-react-ui

Version:

Customizable react components for InstantDB (forms/lists/etc.)

51 lines 3.05 kB
import { DataAttrDef, InstaQLResult, LinkAttrDef } from '@instantdb/react'; import { DeepKeys, DeepValue, FieldApi, FormApi } from '@tanstack/react-form'; import { z, ZodTypeAny } from 'zod'; import { IDBFieldMeta, IDBSchemaType } from '../form/use-idb-form'; interface IDBZodSchema { /** The zod schema for the attribute */ zodSchema: ZodTypeAny; } interface IDBZodSchemaOptional { zodSchema?: ZodTypeAny; } /** Add a zod transform to an attribute definition in an instant schema */ export type IDBZodAttr = DataAttrDef<any, any> & IDBZodSchema; export declare const addZod: <T extends DataAttrDef<any, any>>(input: T, zodSchema: ZodTypeAny) => T & { zodSchema: z.ZodTypeAny; }; /** Zod schema for any Instant entity - requires an id field but allows any other properties */ export declare const generateZodEntitySchema: (message?: string) => z.ZodObject<{ id: z.ZodString; }, "passthrough", z.ZodTypeAny, z.objectOutputType<{ id: z.ZodString; }, z.ZodTypeAny, "passthrough">, z.objectInputType<{ id: z.ZodString; }, z.ZodTypeAny, "passthrough">>; export type IDBZodLink = LinkAttrDef<any, any> & IDBZodSchemaOptional; /** Make an IDB link required with zod in the schema */ export declare const makeLinkRequired: <T extends IDBZodLink>(input: T, message?: string) => void; /** Get all entity names from the schema */ export declare const getEntityNames: <T extends { entities: Record<string, unknown>; }>(schema: T) => { [K in keyof T["entities"]]: K; }; /** Get all fields for a specific entity */ export declare const getEntityFields: <TSchema extends { entities: Record<string, { attrs: Record<string, unknown>; }>; }, TEntity extends string>(schema: TSchema, entityName: TEntity & keyof TSchema["entities"]) => { [P in keyof TSchema["entities"][TEntity]["attrs"]]: P; }; /** Get readable error message for field. Returns null if the field hasn't been touched */ export declare const getErrorMessageForField: (field: FieldApi<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any>) => string | null; /** A slightly more permissive version of ExtractIDBEntityType for use with custom components */ export type IDBExtractFormDataType<TSchema extends IDBSchemaType, TQuery extends Record<string, any>, TEntity extends keyof InstaQLResult<TSchema, TQuery>> = NonNullable<InstaQLResult<TSchema, TQuery>[TEntity]> extends (infer U)[] ? U : never; /** Get a field type from a tanstack form */ export type IDBExtractFieldType<TFormData, TFieldName extends DeepKeys<TFormData>, TFieldValue extends DeepValue<TFormData, TFieldName> = DeepValue<TFormData, TFieldName>> = FieldApi<TFormData, TFieldName, TFieldValue, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> & { state: { meta: IDBFieldMeta<TFieldValue>; }; }; /** Extract the form type for a form data type */ export type IDBExtractFormType<TFormData> = FormApi<TFormData, any, any, any, any, any, any, any, any, any>; export {}; //# sourceMappingURL=utils.d.ts.map