dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
38 lines (37 loc) • 1.46 kB
JavaScript
import { EntityParser } from '../../../../entity/actions/parse/index.js';
import { EntityAction } from '../../../../entity/index.js';
import { DynamoDBToolboxError } from '../../../../errors/index.js';
import { $key, $options } from './constants.js';
import { parseOptions } from './options.js';
export class GetTransaction extends EntityAction {
constructor(entity, key, options = {}) {
super(entity);
this[$key] = key;
this[$options] = options;
}
key(nextKey) {
return new GetTransaction(this.entity, nextKey, this[$options]);
}
options(nextOptions) {
return new GetTransaction(this.entity, this[$key], typeof nextOptions === 'function' ? nextOptions(this[$options]) : nextOptions);
}
params() {
var _a;
if (!this[$key]) {
throw new DynamoDBToolboxError('actions.incompleteAction', {
message: 'GetTransaction incomplete: Missing "key" property'
});
}
const options = this[$options];
const { key } = this.entity.build(EntityParser).parse(this[$key], { mode: 'key' });
const awsOptions = parseOptions(this.entity, options);
return {
Get: {
TableName: (_a = options.tableName) !== null && _a !== void 0 ? _a : this.entity.table.getName(),
Key: key,
...awsOptions
}
};
}
}
GetTransaction.actionName = 'transactGet';