import type { Entity as BaseEntity } from "dynamodb-toolbox"; import type { BatchWriteItem, BatchWriteResult, IDeleteBatchItem, IPutBatchItem } from "../../utils/batch/types.js"; import type { GenericRecord } from "@webiny/api/types.js"; import type { TableDef } from "../../toolbox.js"; import type { ITableWriteBatch } from "../../utils/table/types.js"; import type { IPutParamsItem, put } from "../../utils/put.js"; import { queryAll, queryAllClean, type QueryAllParams, queryOne, queryOneClean, type QueryOneParams } from "../../utils/query.js"; import type { get, getClean, GetRecordParamsKeys } from "../../utils/get.js"; import type { deleteItem, IDeleteItemKeys } from "../../utils/delete.js"; import type { batchReadAll, BatchReadItem } from "../../utils/batch/batchRead.js"; import type { IEntityWriteBatchParams } from "./EntityWriteBatch.js"; import type { IEntityReadBatchParams } from "./EntityReadBatch.js"; import { queryPerPage } from "../../utils/index.js"; export type IEntityQueryOneParams = Omit; export type IEntityQueryAllParams = Omit; export type IEntityQueryPerPageParams = Omit; export interface IEntityCreateEntityWriterParams extends Omit, "entity"> { } export interface IEntityCreateEntityReaderParams extends Omit { } export type IEntityPutResult = ReturnType; export type IEntityGetResult = ReturnType>; export type IEntityGetCleanResult = ReturnType>; export type IEntityDeleteResult = ReturnType; export type IEntityQueryOneResult = ReturnType>; export type IEntityQueryOneCleanResult = ReturnType>; export type IEntityQueryAllResult = ReturnType>; export type IEntityQueryAllCleanResult = ReturnType>; export type IEntityQueryPerPageResult = ReturnType>; export interface IEntity { readonly entity: BaseEntity; readonly name: string; readonly table: TableDef; createEntityReader(params?: IEntityCreateEntityReaderParams): IEntityReadBatch; createEntityWriter(params?: IEntityCreateEntityWriterParams): IEntityWriteBatch; createTableWriter(): ITableWriteBatch; put(item: IPutParamsItem): IEntityPutResult; get(keys: GetRecordParamsKeys): IEntityGetResult; getClean(keys: GetRecordParamsKeys): IEntityGetCleanResult; delete(keys: IDeleteItemKeys): IEntityDeleteResult; queryOne(params: IEntityQueryOneParams): IEntityQueryOneResult; queryOneClean(params: IEntityQueryOneParams): IEntityQueryOneCleanResult; queryAll(params: IEntityQueryAllParams): IEntityQueryAllResult; queryAllClean(params: IEntityQueryAllParams): IEntityQueryAllCleanResult; queryPerPage(params: IEntityQueryPerPageParams): IEntityQueryPerPageResult; } export interface IEntityWriteBatchBuilder { put>(item: IPutBatchItem): BatchWriteItem; delete(item: IDeleteBatchItem): BatchWriteItem; } export interface IEntityWriteBatch { readonly total: number; readonly items: BatchWriteItem[]; put(item: IPutBatchItem): void; delete(item: IDeleteBatchItem): void; execute(): Promise; combine(items: BatchWriteItem[]): ITableWriteBatch; } export interface IEntityReadBatchKey { PK: string; SK: string; } export interface IEntityReadBatch { readonly total: number; readonly items: BatchReadItem[]; get(input: IEntityReadBatchKey | IEntityReadBatchKey[]): void; execute(): ReturnType>; } export interface IEntityReadBatchBuilderGetResponse { Table: TableDef; Key: IEntityReadBatchKey; } export interface IEntityReadBatchBuilder { get(item: IEntityReadBatchKey): IEntityReadBatchBuilderGetResponse; }