Skip to content

Commit

Permalink
Integrate Changes
Browse files Browse the repository at this point in the history
Integrate Changes
  • Loading branch information
gabrielforster authored Apr 8, 2024
2 parents 5acc9fc + b475b64 commit e38747c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
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.3.0",
"version": "1.3.1",
"description": "Utils library for Javascript",
"keywords": [],
"author": {
Expand Down
17 changes: 13 additions & 4 deletions src/dao/dynamo/dao.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isObject } from '../../object'
import { error } from '../../error'
import type { DynamodbParams } from './types'
import type { DynamodbParams, ScanOutput } from './types'
import {
DynamoDBDocument,
GetCommand,
Expand All @@ -9,7 +9,8 @@ import {
PutCommand,
UpdateCommand,
DeleteCommand,
BatchWriteCommand
BatchWriteCommand,
ScanCommandInput
} from '@aws-sdk/lib-dynamodb'
import type {
GetCommandInput,
Expand All @@ -22,6 +23,7 @@ import type {
QueryCommandOutput
} from '@aws-sdk/lib-dynamodb'
import { DynamoDB, ScanCommand } from '@aws-sdk/client-dynamodb'
import { unmarshall } from '@aws-sdk/util-dynamodb'

const getOptions = () => {
if (process.env.IS_OFFLINE) return { region: 'localhost', endpoint: 'http://localhost:8000' }
Expand Down Expand Up @@ -65,9 +67,16 @@ const query = async <T>({
return items
}

const scan = async (params) => {
async function scan<T>(params: ScanCommandInput): Promise<ScanOutput<T>> {
const command = new ScanCommand(params)
return documentInstance.send(command)
const result = await documentInstance.send(command)

const Items = result.Items?.map(item => unmarshall(item)) as T[] | undefined

return {
Items,
LastEvaluatedKey: result.LastEvaluatedKey
}
}

const getAll = async ({ params, list, fields = [] }: { params: DynamodbParams, list: object[], fields?: string[] }) => {
Expand Down
4 changes: 4 additions & 0 deletions src/dao/dynamo/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AttributeValue } from '@aws-sdk/client-dynamodb'

export enum ConditionsExpressions {
EQUAL = '=',
NOT_EQUAL = '<>',
Expand Down Expand Up @@ -27,3 +29,5 @@ export interface DynamodbParams {
export interface DynamodbResponseBatch {
UnprocessedItems: object
}

export type ScanOutput<T> = { Items: T[] | undefined, LastEvaluatedKey: Record<string, AttributeValue> | undefined }

0 comments on commit e38747c

Please sign in to comment.