Skip to content

Commit

Permalink
take PR feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Aribart committed Jan 26, 2024
1 parent 003564b commit 839391a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 29 deletions.
16 changes: 8 additions & 8 deletions src/v1/operations/transactions/deleteItem/operation.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'
import type { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'

import type { EntityV2 } from 'v1/entity'
import { DynamoDBToolboxError } from 'v1/errors'
import { KeyInput } from 'v1/operations/types'
import type { KeyInput } from 'v1/operations/types'

import { $entity, EntityOperation } from '../../class'
import type { DeleteItemTransactionOptions } from './options'
import { transactDeleteItemParams, TransactDeleteItemParams } from './transactDeleteItemParams'
import { WriteItemTransaction } from '../types'
import type { WriteItemTransaction } from '../types'

export const $key = Symbol('$key')
export type $key = typeof $key
Expand All @@ -21,12 +21,12 @@ export class DeleteItemTransaction<
>
extends EntityOperation<ENTITY>
implements WriteItemTransaction<ENTITY, 'Delete'> {
static operationName = 'transactDelete' as const
static operationName = 'transactDelete' as const;

private [$key]?: KeyInput<ENTITY>
public key: (keyInput: KeyInput<ENTITY>) => DeleteItemTransaction<ENTITY>
public [$options]: OPTIONS
public options: <NEXT_OPTIONS extends DeleteItemTransactionOptions<ENTITY>>(
[$key]?: KeyInput<ENTITY>
key: (keyInput: KeyInput<ENTITY>) => DeleteItemTransaction<ENTITY>;
[$options]: OPTIONS
options: <NEXT_OPTIONS extends DeleteItemTransactionOptions<ENTITY>>(
nextOptions: NEXT_OPTIONS
) => DeleteItemTransaction<ENTITY, NEXT_OPTIONS>

Expand Down
14 changes: 7 additions & 7 deletions src/v1/operations/transactions/putItem/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { DynamoDBToolboxError } from 'v1/errors'

import { $entity, EntityOperation } from '../../class'
import type { PutItemInput } from '../../putItem/types'
import { WriteItemTransaction } from '../types'
import type { WriteItemTransaction } from '../types'
import { transactPutItemParams, TransactPutItemParams } from './transactPutItemParams'
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'
import type { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'
import type { PutItemTransactionOptions } from './options'

export const $item = Symbol('$item')
Expand All @@ -21,12 +21,12 @@ export class PutItemTransaction<
>
extends EntityOperation<ENTITY>
implements WriteItemTransaction<ENTITY, 'Put'> {
static operationName = 'transactPut' as const
static operationName = 'transactPut' as const;

private [$item]?: PutItemInput<ENTITY>
public item: (nextItem: PutItemInput<ENTITY>) => PutItemTransaction<ENTITY>
public [$options]: OPTIONS
public options: <NEXT_OPTIONS extends PutItemTransactionOptions<ENTITY>>(
[$item]?: PutItemInput<ENTITY>
item: (nextItem: PutItemInput<ENTITY>) => PutItemTransaction<ENTITY>;
[$options]: OPTIONS
options: <NEXT_OPTIONS extends PutItemTransactionOptions<ENTITY>>(
nextOptions: NEXT_OPTIONS
) => PutItemTransaction<ENTITY, NEXT_OPTIONS>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const parseEntityPutTransactionInput: EntityPutCommandInputParser = (enti
operationName: 'put'
})

const clonedInput = parser.next() // cloned
parser.next(clonedInput) // linked
parser.next() // cloned
parser.next() // linked

return parser
}
16 changes: 8 additions & 8 deletions src/v1/operations/transactions/updateItem/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { DynamoDBToolboxError } from 'v1/errors'

import { $entity, EntityOperation } from '../../class'
import type { UpdateItemInput } from '../../updateItem/types'
import { WriteItemTransaction } from '../types'
import type { WriteItemTransaction } from '../types'
import { transactUpdateItemParams, TransactUpdateItemParams } from './transactUpdateItemParams'
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'
import type { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'
import type { UpdateItemTransactionOptions } from './options'

export const $item = Symbol('$item')
Expand All @@ -21,12 +21,12 @@ export class UpdateItemTransaction<
>
extends EntityOperation<ENTITY>
implements WriteItemTransaction<ENTITY, 'Update'> {
static operationName = 'transactUpdate' as const
static operationName = 'transactUpdate' as const;

private [$item]?: UpdateItemInput<ENTITY>
public item: (nextItem: UpdateItemInput<ENTITY>) => UpdateItemTransaction<ENTITY>
public [$options]: OPTIONS
public options: <NEXT_OPTIONS extends UpdateItemTransactionOptions<ENTITY>>(
[$item]?: UpdateItemInput<ENTITY>
item: (nextItem: UpdateItemInput<ENTITY>) => UpdateItemTransaction<ENTITY>;
[$options]: OPTIONS
options: <NEXT_OPTIONS extends UpdateItemTransactionOptions<ENTITY>>(
nextOptions: NEXT_OPTIONS
) => UpdateItemTransaction<ENTITY, NEXT_OPTIONS>

Expand All @@ -41,7 +41,7 @@ export class UpdateItemTransaction<

params = (): TransactUpdateItemParams => {
if (!this[$item]) {
throw new DynamoDBToolboxError('operations.incompleteCommand', {
throw new DynamoDBToolboxError('operations.incompleteOperation', {
message: 'UpdateItemTransaction incomplete: Missing "item" property'
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import { parseCondition } from 'v1/operations/expression/condition/parse'

import { rejectExtraOptions } from 'v1/operations/utils/parseOptions/rejectExtraOptions'

import { UpdateItemTransactionOptions } from '../options'
import type { UpdateItemTransactionOptions } from '../options'
import type { TransactUpdateItemParams } from './transactUpdateItemParams'

type TransactionOptions = Omit<TransactUpdateItemParams, 'TableName' | 'Key' | 'UpdateExpression'>

export const parseUpdateItemTransactionOptions = <ENTITY extends EntityV2>(
entity: ENTITY,
putItemTransactionOptions: UpdateItemTransactionOptions<ENTITY>
updateItemTransactionOptions: UpdateItemTransactionOptions<ENTITY>
): TransactionOptions => {
const transactionOptions: TransactionOptions = {}

const { condition, ...extraOptions } = putItemTransactionOptions
const { condition, ...extraOptions } = updateItemTransactionOptions
rejectExtraOptions(extraOptions)

if (condition !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const parseEntityUpdateTransactionInput: EntityUpdateCommandInputParser =
parseExtension: parseUpdateExtension
})

parser.next() // linked
parser.next() // cloned

return parser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,7 @@ describe('update transaction', () => {
const invalidCall = () => TestEntity.build(UpdateItemTransaction).params()

expect(invalidCall).toThrow(DynamoDBToolboxError)
expect(invalidCall).toThrow(expect.objectContaining({ code: 'operations.incompleteCommand' }))
expect(invalidCall).toThrow(expect.objectContaining({ code: 'operations.incompleteOperation' }))
})

it('transformed key/attribute (partial - 1)', () => {
Expand Down

0 comments on commit 839391a

Please sign in to comment.