import { Insertable, Selectable, Selection, Updateable } from 'kysely'; import { SelectableColumnTuple, SelectedRow, SelectionColumn } from '../lib/type-utils.js'; /** * Transformations to apply to values provided to and received from queries. * All transformations are optional. When no transformation is provided, the * value is passed through unchanged. * @typeParam DB Interface whose fields are table names defining tables. * @typeParam TB Name of the table. * @typeParam KeyColumns Tuple of the names of the table's key columns. * Defaults to `[]`, indicating no key columns. Supports up to 4 columns. * @typeParam SelectedColumns Columns to return from selection queries. * Defaults to `['*']`, returning all columns. May specify aliases. * @typeParam SelectedObject Type of objects returned by select queries. * @typeParam InsertedObject Type of objects inserted into the table. * @typeParam UpdatingObject Type of objects used to update rows of the table. * @typeParam Type of the count of the number of affected rows. * @typeParam InsertReturnColumns Columns to return from the table on insert * queries that return columns. `['*']` returns all columns; `[]` returns * none. May specify aliases. Defaults to `KeyColumns`. * @typeParam UpdateReturnColumns Columns to return from the table on update * queries that return columns. `['*']` returns all columns; `[]` returns * none and is the default. May specify aliases. * @typeParam InsertReturn Type returned from inserts. Defaults to an object * whose properties are the columns of `InsertReturnColumns`. * @typeParam UpdateReturn Type returned from updates. Defaults to an object * whose properties are the columns of `UpdateReturnColumns`. */ export interface TableMapperTransforms> | Readonly<[]> = [], SelectedColumns extends Readonly[]> | ['*'] = ['*'], SelectedObject = SelectedRow, InsertedObject = Insertable, UpdatingObject = Updateable, ReturnCount = bigint, InsertReturnColumns extends Readonly[]> | ['*'] = Readonly, UpdateReturnColumns extends Readonly[]> | ['*'] = [], InsertReturn = InsertReturnColumns extends ['*'] ? Selectable : Selection, UpdateReturn = UpdateReturnColumns extends ['*'] ? Selectable : Selection> extends CountTransform, InsertTransforms, SelectTransform, UpdateTransforms { } export interface CountTransform { /** * Transformation to apply to bigint count results indicating the number of * rows affected, before returning the count to the client. `count` is the * count returned by the query. */ countTransform?: (count: bigint) => ReturnCount; } export interface InsertTransforms[]> | ['*'], InsertReturn> { /** * Transformation to apply to inserted objects before insertion. `source` * is the object provided for insertion. Only the columns in `columns` will * actually be inserted, with `[*]` indicating all columns. */ insertTransform?: (source: InsertedObject, columns: Readonly<(keyof Insertable)[]> | ['*']) => Insertable; /** * Transformation to apply to column values returned from inserts before * returning values to the client. When inferring type parameters, specify * a type for the `source` parameter. `source` is the object that was provided * for insertion, and `returns` are the values returned from the insert. */ insertReturnTransform?: (source: InsertedObject, returns: InsertReturnColumns extends [] ? never : SelectedRow) => InsertReturn; } export interface SelectTransform[]> | ['*'], SelectedObject> { /** * Transformation to apply to selected objects after retrieval from the * database and before returning to the client. `row` is the selected * row, as returned by the Kysely query. */ selectTransform?: (row: SelectedRow) => SelectedObject; } export interface UpdateTransforms[]> | ['*'], UpdateReturn> { /** * Transformation to apply to objects provided for updating rows. `source` * is the object containing the values which which to update the table row. * Only the columns in `columns` will actually be updated, with `[*]` * indicating all columns. */ updateTransform?: (source: UpdatingObject, columns: Readonly<(keyof Updateable)[]> | ['*']) => Updateable; /** * Transformation to apply to column values returned from updates before * returning values to the client. When inferring type parameters, specify * a type for the `source` parameter. `source` is the object that contained * the valiues with which the table row was updated, and `returns` are the * values returned from the update. */ updateReturnTransform?: (source: UpdatingObject, returns: UpdateReturnColumns extends [] ? never : SelectedRow) => UpdateReturn; } //# sourceMappingURL=table-mapper-transforms.d.ts.map