import { NodePgDatabase } from "drizzle-orm/node-postgres"; import { CollectionConfig, Properties, Property, ResolvedRelation, type ResolvedVia } from "@rebasepro/types"; import { PostgresCollectionRegistry } from "./collections/PostgresCollectionRegistry"; /** * Data transformation utilities for converting between frontend and database formats. */ /** * Typed result from `serializeDataToServer`. * Replaces the hidden `__inverseRelationUpdates` / `__joinPathRelationUpdates` * dunder-property mutation pattern with explicit, typed state management. */ export interface SerializedEntityData { /** Scalar column values ready for INSERT/UPDATE. */ scalarData: Record; /** * Inverse relation updates that must be applied to target tables. * * No address here: the row being written does not know its own. These are * applied by `PersistService`, which addresses them with the id it holds — * the one it was given for an update, or the one the INSERT returned — and * that is the authority. This item used to carry a `currentId` derived from * the *input* values, which nothing ever read. */ inverseRelationUpdates: Array<{ relationKey: string; relation: ResolvedRelation; newValue: unknown; }>; /** JoinPath relation updates that require multi-hop writes. */ joinPathRelationUpdates: Array<{ relationKey: string; relation: ResolvedVia; newTargetId: string | number | null; }>; } /** * Helper function to sanitize and convert dates to ISO strings */ export declare function sanitizeAndConvertDates(obj: unknown): unknown; /** * Transform relations for database storage (relation objects to IDs) */ export declare function serializeDataToServer>(row: M, properties: Properties, collection?: CollectionConfig, registry?: PostgresCollectionRegistry): SerializedEntityData; /** * Serialize a single property value for database storage. * * `propertyKey` is only ever used to phrase errors and warnings. Without it the * one trace a bad value left was `Expected array value for array property, got * string` — no collection, no property, no value, which in the log of a * thousand-row import names nothing at all. */ export declare function serializePropertyToServer(value: unknown, property: Property, propertyKey?: string): unknown; /** * Transform IDs back to relation objects for frontend */ export declare function parseDataFromServer>(data: M, collection: CollectionConfig, db?: NodePgDatabase>, registry?: PostgresCollectionRegistry): Promise; export declare function parsePropertyFromServer(value: unknown, property: Property, collection: CollectionConfig, propertyKey?: string): unknown; /** * Lightweight value normalization for db.query results. * Only handles type coercion (dates, numbers, NaN) and property filtering. * Does NOT query the database for relations — those are already resolved * by Drizzle's relational query API. * * Use this instead of `parseDataFromServer` when processing results from * `db.query.findFirst/findMany` which return pre-hydrated relation data. */ export declare function normalizeDbValues>(data: M, collection: CollectionConfig): M;