UNPKG

@mbc-cqrs-serverless/core

Version:
68 lines (67 loc) 2.24 kB
import { DynamoDbService } from '../data-store/dynamodb.service'; import { CommandModel, CommandModuleOptions, DataListEntity, DataModel, DetailKey } from '../interfaces'; declare const TABLE_NAME: unique symbol; /** * Service for reading data from DynamoDB. * Provides query operations for the read side of CQRS. * * @example * ```typescript * @Injectable() * export class OrderService { * constructor( * @InjectDataService() private readonly dataService: DataService * ) {} * * async getOrder(pk: string, sk: string) { * return this.dataService.getItem({ pk, sk }); * } * } * ``` */ export declare class DataService { private readonly options; private readonly dynamoDbService; private logger; private [TABLE_NAME]; constructor(options: CommandModuleOptions, dynamoDbService: DynamoDbService); set tableName(name: string); get tableName(): string; /** * Publishes command data to the data table. * Updates or creates the data record based on the command. * * @param cmd - The command model to publish * @returns The published data model */ publish(cmd: CommandModel): Promise<DataModel>; /** * Retrieves a single item from the data table. * * @param key - The partition key and sort key * @returns The data model or undefined if not found */ getItem(key: DetailKey): Promise<DataModel>; /** * Lists items by partition key with optional filtering and pagination. * * @param pk - The partition key to query * @param opts - Optional query parameters * @param opts.sk - Sort key filter expression * @param opts.startFromSk - Start key for pagination * @param opts.limit - Maximum number of items to return * @param opts.order - Sort order ('asc' or 'desc') * @returns List of data entities with pagination info */ listItemsByPk(pk: string, opts?: { sk?: { skExpression: string; skAttributeValues: Record<string, string>; skAttributeNames?: Record<string, string>; }; startFromSk?: string; limit?: number; order?: 'asc' | 'desc'; }): Promise<DataListEntity>; } export {};