Skip to content

Commit

Permalink
Integrate Changes
Browse files Browse the repository at this point in the history
Integrate Changes
  • Loading branch information
marcofeliponi authored Feb 21, 2024
2 parents 12d8f9a + e1a6aca commit 9a6388a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"simplificamais"
],
"conventionalCommits.scopes": [
"lambda"
"lambda",
"dynamodb-dao"
]
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adapcon-utils-js",
"version": "1.1.4",
"version": "1.1.5",
"description": "Utils library for Javascript",
"keywords": [],
"author": {
Expand Down
20 changes: 12 additions & 8 deletions src/dao/dynamo/dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const get = async ({
const query = async <T>({
params, fields = [], _items = [], stopOnLimit = false
}: { params: { Limit?: number } & QueryCommandInput, fields?: string[], _items?: Array<Record<string, any>>, stopOnLimit?: boolean }): Promise<Array<Record<string, T>>> => {
const command = new QueryCommand({ ...params, ...mountProjectionExpression({ fields }) })
const command = new QueryCommand({ ...params, ...mountProjectionExpression({ fields, expressionAttributeNames: params.ExpressionAttributeNames }) })
const { Items = [], LastEvaluatedKey } = await documentInstance.send(command)

const items = [..._items, ...Items]
Expand Down Expand Up @@ -92,14 +92,14 @@ const getAll = async ({ params, list, fields = [] }: { params: DynamodbParams, l
}

const command = new BatchGetCommand(opts)
const response = await documentInstance.send(command)
return response[params.TableName]
const { Responses } = await documentInstance.send(command)
return Responses?.[params.TableName]
}))

return data.reduce((acc: any, i) => acc.concat(i), [])
}

const put = async ({ params }: { params: PutCommandInput}): Promise<object> => {
const put = async ({ params }: { params: PutCommandInput }): Promise<object> => {
try {
const command = new PutCommand(params)
await documentInstance.send(command)
Expand All @@ -112,7 +112,7 @@ const put = async ({ params }: { params: PutCommandInput}): Promise<object> => {
}
}

const update = async ({ params }: { params: UpdateCommandInput}): Promise<any> => {
const update = async ({ params }: { params: UpdateCommandInput }): Promise<any> => {
try {
const command = new UpdateCommand(params)
return await documentInstance.send(command)
Expand All @@ -122,7 +122,7 @@ const update = async ({ params }: { params: UpdateCommandInput}): Promise<any> =
}
}

const deleteOne = async ({ params }: { params: DeleteCommandInput}): Promise<Record<string, any> | undefined> => {
const deleteOne = async ({ params }: { params: DeleteCommandInput }): Promise<Record<string, any> | undefined> => {
try {
const command = new DeleteCommand(params)
await documentInstance.send(command)
Expand Down Expand Up @@ -328,10 +328,14 @@ const dynamicFilters = ({
}
}

const mountProjectionExpression = ({ fields = [], options }: { fields?: string[], options?: DynamodbParams }): object => {
const mountProjectionExpression = ({ fields = [], expressionAttributeNames, options }: {
fields?: string[]
expressionAttributeNames?: QueryCommandInput['ExpressionAttributeNames']
options?: DynamodbParams
}): object => {
if (fields.length > 0) {
const ProjectionExpression = fields.map((_, index) => `#Projection_${index}`).join(',')
const { ExpressionAttributeNames = {} } = options ?? {}
const { ExpressionAttributeNames = expressionAttributeNames ?? {} } = options ?? {}

fields.forEach((i, index) => {
ExpressionAttributeNames[`#Projection_${index}`] = i
Expand Down

0 comments on commit 9a6388a

Please sign in to comment.