import type { Accountability, SchemaOverview } from '@db-studio/types'; import type { Knex } from 'knex'; import type { Helpers } from '../database/helpers/index.js'; import type { AbstractServiceOptions, ActionEventParams, Item, MutationOptions, PrimaryKey } from '../types/index.js'; type Action = 'create' | 'read' | 'update'; type Transformers = { [type: string]: (context: { action: Action; value: any; payload: Partial; accountability: Accountability | null; specials: string[]; helpers: Helpers; }) => Promise; }; /** * Process a given payload for a collection to ensure the special fields (hash, uuid, date etc) are * handled correctly. */ export declare class PayloadService { accountability: Accountability | null; knex: Knex; helpers: Helpers; collection: string; schema: SchemaOverview; constructor(collection: string, options: AbstractServiceOptions); transformers: Transformers; processValues(action: Action, payloads: Partial[]): Promise[]>; processValues(action: Action, payload: Partial): Promise>; processAggregates(payload: Partial[]): void; processField(field: SchemaOverview['collections'][string]['fields'][string], payload: Partial, action: Action, accountability: Accountability | null): Promise; /** * Native geometries are stored in custom binary format. We need to insert them with * the function st_geomfromtext. For this to work, that function call must not be * escaped. It's therefore placed as a Knex.Raw object in the payload. Thus the need * to check if the value is a raw instance before stringifying it in the next step. */ processGeometries>[]>(payloads: T, action: Action): T; /** * Knex returns `datetime` and `date` columns as Date.. This is wrong for date / datetime, as those * shouldn't return with time / timezone info respectively */ processDates(payloads: Partial>[], action: Action): Partial>[]; /** * Recursively save/update all nested related Any-to-One items */ processA2O(data: Partial, opts?: MutationOptions): Promise<{ payload: Partial; revisions: PrimaryKey[]; nestedActionEvents: ActionEventParams[]; }>; /** * Save/update all nested related m2o items inside the payload */ processM2O(data: Partial, opts?: MutationOptions): Promise<{ payload: Partial; revisions: PrimaryKey[]; nestedActionEvents: ActionEventParams[]; }>; /** * Recursively save/update all nested related o2m items */ processO2M(data: Partial, parent: PrimaryKey, opts?: MutationOptions): Promise<{ revisions: PrimaryKey[]; nestedActionEvents: ActionEventParams[]; }>; /** * Transforms the input partial payload to match the output structure, to have consistency * between delta and data */ prepareDelta(data: Partial): Promise; } export {};