node-aws-utils
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -1,8 +0,8 @@ | ||
import { ResultOK, ResultFAIL } from "node-result"; | ||
import { DynamoDB } from "aws-sdk"; | ||
import { ResultOK, ResultFAIL } from 'node-result'; | ||
import { DynamoDB } from 'aws-sdk'; | ||
export declare class DynamoDocumentClient { | ||
static get(client: DynamoDB.DocumentClient, tableName: DynamoDB.DocumentClient.TableName, where: DynamoDB.DocumentClient.Key): Promise<ResultOK<DynamoDB.DocumentClient.AttributeMap | null> | ResultFAIL<Error>>; | ||
static update(client: DynamoDB.DocumentClient, tableName: DynamoDB.DocumentClient.TableName, where: DynamoDB.DocumentClient.Key, data: { | ||
[key: string]: any; | ||
[key: string]: unknown; | ||
}): Promise<ResultOK<DynamoDB.DocumentClient.AttributeMap> | ResultFAIL<Error>>; | ||
} |
@@ -25,3 +25,3 @@ "use strict"; | ||
AttributeUpdates: {}, | ||
ReturnValues: 'UPDATED_NEW', | ||
ReturnValues: 'UPDATED_NEW' | ||
}; | ||
@@ -35,3 +35,3 @@ const keys = Object.keys(data); | ||
for (const key of keys) { | ||
if (!!data[key]) { | ||
if (data[key]) { | ||
params.AttributeUpdates[key] = { | ||
@@ -44,3 +44,3 @@ Action: 'PUT', | ||
params.AttributeUpdates[key] = { | ||
Action: 'DELETE', | ||
Action: 'DELETE' | ||
}; | ||
@@ -47,0 +47,0 @@ } |
{ | ||
"name": "node-aws-utils", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "aws utils", | ||
@@ -15,19 +15,31 @@ "keywords": [ | ||
"repository": "github:WatchDG/node-aws-utils", | ||
"private": false, | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"lib/**/*" | ||
], | ||
"scripts": { | ||
"preversion": "npm run build", | ||
"version": "npm run build", | ||
"prepublishOnly": "npm run build", | ||
"prepare": "npm run build", | ||
"build": "npx tsc" | ||
"fmt": "npx prettier --write \"src/**/*.ts\"", | ||
"lint": "eslint --ext=ts src", | ||
"build": "npx tsc", | ||
"_postinstall": "husky install", | ||
"prepublishOnly": "pinst --disable", | ||
"prepare": "npm run lint && npm run build", | ||
"postpublish": "pinst --enable" | ||
}, | ||
"dependencies": { | ||
"aws-sdk": "^2.822.0", | ||
"node-result": "^5.5.0" | ||
"node-result": "^6.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^14.14.20", | ||
"@typescript-eslint/eslint-plugin": "^4.12.0", | ||
"@typescript-eslint/parser": "^4.12.0", | ||
"eslint": "^7.17.0", | ||
"husky": "^5.0.6", | ||
"pinst": "^2.1.1", | ||
"prettier": "^2.2.1", | ||
"typescript": "^4.1.3" | ||
} | ||
} |
@@ -1,1 +0,52 @@ | ||
# node-aws-utils | ||
# node-aws-utils | ||
## install dependencies | ||
```shell | ||
yarn install | ||
# or | ||
npm install | ||
``` | ||
## build | ||
```shell | ||
yarn run build | ||
# or | ||
npm run build | ||
``` | ||
## Dynamo | ||
### get item | ||
```ts | ||
import {DynamoDB} from "aws-sdk"; | ||
import {DynamoDocumentClient} from "node-aws-utils"; | ||
(async () => { | ||
const tableName = 'store'; | ||
const where = {id: 1}; | ||
const dynamo = new DynamoDB.DocumentClient(); | ||
const storeData = (await DynamoDocumentClient.get(dynamo, tableName, where)).unwrap(); | ||
console.log(storeData); | ||
// object or null | ||
})(); | ||
``` | ||
### put or update item | ||
```ts | ||
import {DynamoDB} from "aws-sdk"; | ||
import {DynamoDocumentClient} from "node-aws-utils"; | ||
(async () => { | ||
const tableName = 'store'; | ||
const where = {id: 1}; | ||
const data = {email: 'user@store.com'}; | ||
const dynamo = new DynamoDB.DocumentClient(); | ||
const updatedData = (await DynamoDocumentClient.update(dynamo, tableName, where, data)).unwrap(); | ||
console.log(updatedData); | ||
// object or empty object | ||
})(); | ||
``` |
52
6154
8
5
66
+ Addednode-result@6.2.0(transitive)
- Removednode-result@5.6.0(transitive)
Updatednode-result@^6.0.1