"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const operators_1 = require("rxjs/operators");
const logger_1 = require("../logger/logger");
const dynamo_rx_1 = require("./dynamo-rx");
const get_table_name_function_1 = require("./get-table-name.function");
const request_1 = require("./request");
const batch_write_single_table_request_1 = require("./request/batchwritesingletable/batch-write-single-table.request");
class DynamoStore {
    constructor(modelClazz) {
        this.modelClazz = modelClazz;
        this.logger = logger_1.createLogger('dynamo.DynamoStore', modelClazz);
        this.dynamoRx = new dynamo_rx_1.DynamoRx();
        this.tableName = get_table_name_function_1.getTableName(modelClazz);
        this.logger.debug('instance created');
    }
    get dynamoDB() {
        return this.dynamoRx.dynamoDB;
    }
    put(item) {
        return new request_1.PutRequest(this.dynamoRx, this.modelClazz, item);
    }
    get(partitionKey, sortKey) {
        return new request_1.GetRequest(this.dynamoRx, this.modelClazz, partitionKey, sortKey);
    }
    update(partitionKey, sortKey) {
        return new request_1.UpdateRequest(this.dynamoRx, this.modelClazz, partitionKey, sortKey);
    }
    delete(partitionKey, sortKey) {
        return new request_1.DeleteRequest(this.dynamoRx, this.modelClazz, partitionKey, sortKey);
    }
    scan() {
        return new request_1.ScanRequest(this.dynamoRx, this.modelClazz);
    }
    query() {
        return new request_1.QueryRequest(this.dynamoRx, this.modelClazz);
    }
    /**
     * This is a special implementation of BatchGetItem request, because it only supports one table,
     * if you wish to retrieve items from multiple tables
     * create an instance of BatchGetItemInput and use store.makeRequest with it.
     */
    batchGet(keys) {
        return new request_1.BatchGetSingleTableRequest(this.dynamoRx, this.modelClazz, keys);
    }
    /**
     * This is a special implementation of batchWriteItem request, because it only supports one table,
     * if you wish to write items to multiple tables
     * create an instance of BatchWriteItemInput and use store.makeRequest with it.
     */
    batchWrite() {
        return new batch_write_single_table_request_1.BatchWriteSingleTableRequest(this.dynamoRx, this.modelClazz);
    }
    transactGet(keys) {
        return new request_1.TransactGetSingleTableRequest(this.dynamoRx, this.modelClazz, keys);
    }
    makeRequest(operation, params) {
        this.logger.debug('request', params);
        return this.dynamoRx.makeRequest(operation, params).pipe(operators_1.tap(response => this.logger.debug('response', response)));
    }
}
exports.DynamoStore = DynamoStore;
//# sourceMappingURL=dynamo-store.js.map