UNPKG

dynamodb-toolbox

Version:

Lightweight and type-safe query builder for DynamoDB and TypeScript.

96 lines (95 loc) 4.46 kB
import { AccessPattern } from '../../../entity/actions/accessPattern/accessPattern.js'; import { BatchDeleteRequest } from '../../../entity/actions/batchDelete/index.js'; import { BatchGetRequest } from '../../../entity/actions/batchGet/index.js'; import { BatchPutRequest } from '../../../entity/actions/batchPut/index.js'; import { DeleteItemCommand } from '../../../entity/actions/delete/index.js'; import { EntityFormatter } from '../../../entity/actions/format/index.js'; import { GetItemCommand } from '../../../entity/actions/get/index.js'; import { EntityParser } from '../../../entity/actions/parse/index.js'; import { EntityConditionParser } from '../../../entity/actions/parseCondition/index.js'; import { EntityPathParser } from '../../../entity/actions/parsePaths/index.js'; import { PutItemCommand } from '../../../entity/actions/put/index.js'; import { ConditionCheck } from '../../../entity/actions/transactCheck/index.js'; import { DeleteTransaction } from '../../../entity/actions/transactDelete/index.js'; import { GetTransaction, execute as executeTransactGet } from '../../../entity/actions/transactGet/index.js'; import { PutTransaction } from '../../../entity/actions/transactPut/index.js'; import { UpdateTransaction } from '../../../entity/actions/transactUpdate/index.js'; import { execute as executeTransactWrite } from '../../../entity/actions/transactWrite/index.js'; import { UpdateItemCommand } from '../../../entity/actions/update/index.js'; import { UpdateAttributesCommand } from '../../../entity/actions/updateAttributes/index.js'; import { EntityAction } from '../../../entity/index.js'; import { QueryCommand } from '../../../table/actions/query/index.js'; import { ScanCommand } from '../../../table/actions/scan/index.js'; export class EntityRepository extends EntityAction { async put(item, options = {}) { return new PutItemCommand(this.entity, item, options).send(); } async get(key, options = {}) { return new GetItemCommand(this.entity, key, options).send(); } async update(item, options = {}) { return new UpdateItemCommand(this.entity, item, options).send(); } async updateAttributes(item, options = {}) { return new UpdateAttributesCommand(this.entity, item, options).send(); } async delete(key, options = {}) { return new DeleteItemCommand(this.entity, key, options).send(); } async scan(options = {}) { return new ScanCommand(this.entity.table, [this.entity], options).send(); } async query(query, options = {}) { return new QueryCommand(this.entity.table, [this.entity], query, options).send(); } batchGet(key) { return new BatchGetRequest(this.entity, key); } batchPut(item) { return new BatchPutRequest(this.entity, item); } batchDelete(key) { return new BatchDeleteRequest(this.entity, key); } static executeTransactGet(...transactions) { return executeTransactGet(...transactions); } transactGet(key, options = {}) { return new GetTransaction(this.entity, key, options); } static executeTransactWrite(...transactions) { return executeTransactWrite(...transactions); } transactPut(item, options = {}) { return new PutTransaction(this.entity, item, options); } transactUpdate(item, options = {}) { return new UpdateTransaction(this.entity, item, options); } transactDelete(key, options = {}) { return new DeleteTransaction(this.entity, key, options); } transactCheck(key, condition, options = {}) { return new ConditionCheck(this.entity, key, condition, options); } accessPattern(schema, pattern, options = {}) { return new 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 EntityParser(this.entity).parse(item, options); } parseCondition(condition, options = {}) { return new EntityConditionParser(this.entity).parse(condition, options); } parsePaths(attributes, options = {}) { return new EntityPathParser(this.entity).parse(attributes, options); } format(item, options = {}) { return new EntityFormatter(this.entity).format(item, options); } } EntityRepository.actionName = 'repository';