dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
100 lines (99 loc) • 4.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EntityRepository = void 0;
const accessPattern_js_1 = require("../../../entity/actions/accessPattern/accessPattern.js");
const index_js_1 = require("../../../entity/actions/batchDelete/index.js");
const index_js_2 = require("../../../entity/actions/batchGet/index.js");
const index_js_3 = require("../../../entity/actions/batchPut/index.js");
const index_js_4 = require("../../../entity/actions/delete/index.js");
const index_js_5 = require("../../../entity/actions/format/index.js");
const index_js_6 = require("../../../entity/actions/get/index.js");
const index_js_7 = require("../../../entity/actions/parse/index.js");
const index_js_8 = require("../../../entity/actions/parseCondition/index.js");
const index_js_9 = require("../../../entity/actions/parsePaths/index.js");
const index_js_10 = require("../../../entity/actions/put/index.js");
const index_js_11 = require("../../../entity/actions/transactCheck/index.js");
const index_js_12 = require("../../../entity/actions/transactDelete/index.js");
const index_js_13 = require("../../../entity/actions/transactGet/index.js");
const index_js_14 = require("../../../entity/actions/transactPut/index.js");
const index_js_15 = require("../../../entity/actions/transactUpdate/index.js");
const index_js_16 = require("../../../entity/actions/transactWrite/index.js");
const index_js_17 = require("../../../entity/actions/update/index.js");
const index_js_18 = require("../../../entity/actions/updateAttributes/index.js");
const index_js_19 = require("../../../entity/index.js");
const index_js_20 = require("../../../table/actions/query/index.js");
const index_js_21 = require("../../../table/actions/scan/index.js");
class EntityRepository extends index_js_19.EntityAction {
async put(item, options = {}) {
return new index_js_10.PutItemCommand(this.entity, item, options).send();
}
async get(key, options = {}) {
return new index_js_6.GetItemCommand(this.entity, key, options).send();
}
async update(item, options = {}) {
return new index_js_17.UpdateItemCommand(this.entity, item, options).send();
}
async updateAttributes(item, options = {}) {
return new index_js_18.UpdateAttributesCommand(this.entity, item, options).send();
}
async delete(key, options = {}) {
return new index_js_4.DeleteItemCommand(this.entity, key, options).send();
}
async scan(options = {}) {
return new index_js_21.ScanCommand(this.entity.table, [this.entity], options).send();
}
async query(query, options = {}) {
return new index_js_20.QueryCommand(this.entity.table, [this.entity], query, options).send();
}
batchGet(key) {
return new index_js_2.BatchGetRequest(this.entity, key);
}
batchPut(item) {
return new index_js_3.BatchPutRequest(this.entity, item);
}
batchDelete(key) {
return new index_js_1.BatchDeleteRequest(this.entity, key);
}
static executeTransactGet(...transactions) {
return (0, index_js_13.execute)(...transactions);
}
transactGet(key, options = {}) {
return new index_js_13.GetTransaction(this.entity, key, options);
}
static executeTransactWrite(...transactions) {
return (0, index_js_16.execute)(...transactions);
}
transactPut(item, options = {}) {
return new index_js_14.PutTransaction(this.entity, item, options);
}
transactUpdate(item, options = {}) {
return new index_js_15.UpdateTransaction(this.entity, item, options);
}
transactDelete(key, options = {}) {
return new index_js_12.DeleteTransaction(this.entity, key, options);
}
transactCheck(key, condition, options = {}) {
return new index_js_11.ConditionCheck(this.entity, key, condition, options);
}
accessPattern(schema, pattern, options = {}) {
return new accessPattern_js_1.AccessPattern(this.entity, schema,
/**
* @debt v3 "put query in a 'query' key so it's not polluted by the options"
*/
pattern, options);
}
parse(item, options = {}) {
return new index_js_7.EntityParser(this.entity).parse(item, options);
}
parseCondition(condition, options = {}) {
return new index_js_8.EntityConditionParser(this.entity).parse(condition, options);
}
parsePaths(attributes, options = {}) {
return new index_js_9.EntityPathParser(this.entity).parse(attributes, options);
}
format(item, options = {}) {
return new index_js_5.EntityFormatter(this.entity).format(item, options);
}
}
exports.EntityRepository = EntityRepository;
EntityRepository.actionName = 'repository';