node-aws-utils
Advanced tools
Comparing version 1.6.0 to 1.7.0
@@ -1,5 +0,7 @@ | ||
import { ReturningResultAsync } from 'node-result'; | ||
import { DynamoDB } from 'aws-sdk'; | ||
import type { TResultAsync } from 'node-result'; | ||
import type { DynamoDB } from 'aws-sdk'; | ||
export declare class DynamoDocumentClient { | ||
static get(client: DynamoDB.DocumentClient, tableName: DynamoDB.DocumentClient.TableName, where: DynamoDB.DocumentClient.Key): ReturningResultAsync<DynamoDB.DocumentClient.AttributeMap | null, Error>; | ||
static get(client: DynamoDB.DocumentClient, tableName: DynamoDB.DocumentClient.TableName, where: DynamoDB.DocumentClient.Key, options?: { | ||
fields?: string[]; | ||
}): TResultAsync<DynamoDB.DocumentClient.AttributeMap | null, Error>; | ||
static getFromIndex(client: DynamoDB.DocumentClient, tableName: DynamoDB.DocumentClient.TableName, indexName: DynamoDB.DocumentClient.IndexName, where: { | ||
@@ -14,6 +16,6 @@ pk: { | ||
}; | ||
}): ReturningResultAsync<DynamoDB.DocumentClient.ItemList | null, Error>; | ||
}): TResultAsync<DynamoDB.DocumentClient.ItemList | null, Error>; | ||
static update(client: DynamoDB.DocumentClient, tableName: DynamoDB.DocumentClient.TableName, where: DynamoDB.DocumentClient.Key, data: { | ||
[key: string]: unknown; | ||
}): ReturningResultAsync<DynamoDB.DocumentClient.AttributeMap, Error>; | ||
}): TResultAsync<DynamoDB.DocumentClient.AttributeMap, Error>; | ||
} |
@@ -12,3 +12,3 @@ "use strict"; | ||
class DynamoDocumentClient { | ||
static async get(client, tableName, where) { | ||
static async get(client, tableName, where, options = {}) { | ||
const params = { | ||
@@ -18,4 +18,6 @@ TableName: tableName, | ||
}; | ||
if (options.fields) | ||
params.ProjectionExpression = options.fields.join(','); | ||
const { Item } = await client.get(params).promise(); | ||
return node_result_1.ResultOk(Item || null); | ||
return node_result_1.ok(Item || null); | ||
} | ||
@@ -40,3 +42,3 @@ static async getFromIndex(client, tableName, indexName, where) { | ||
const { Items } = await client.query(params).promise(); | ||
return node_result_1.ResultOk(Items || null); | ||
return node_result_1.ok(Items || null); | ||
} | ||
@@ -53,33 +55,30 @@ static async update(client, tableName, where, data) { | ||
if (keys.length > 0) { | ||
for (const key of keys) { | ||
if (data[key] !== void 0) { | ||
attributes[key] = { | ||
Action: 'PUT', | ||
Value: data[key] | ||
}; | ||
} | ||
else { | ||
attributes[key] = { | ||
Action: 'DELETE' | ||
}; | ||
} | ||
} | ||
keys.forEach((key) => { | ||
attributes[key] = | ||
data[key] !== void 0 | ||
? { | ||
Action: 'PUT', | ||
Value: data[key] | ||
} | ||
: { | ||
Action: 'DELETE' | ||
}; | ||
}); | ||
params.AttributeUpdates = attributes; | ||
const { Attributes } = await client.update(params).promise(); | ||
if (Attributes) { | ||
return node_result_1.ResultOk(Attributes); | ||
} | ||
if (Attributes) | ||
return node_result_1.ok(Attributes); | ||
} | ||
return node_result_1.ResultOk({}); | ||
return node_result_1.ok({}); | ||
} | ||
} | ||
__decorate([ | ||
node_result_1.tryCatchWrapperAsync | ||
node_result_1.tryCatchAsync | ||
], DynamoDocumentClient, "get", null); | ||
__decorate([ | ||
node_result_1.tryCatchWrapperAsync | ||
node_result_1.tryCatchAsync | ||
], DynamoDocumentClient, "getFromIndex", null); | ||
__decorate([ | ||
node_result_1.tryCatchWrapperAsync | ||
node_result_1.tryCatchAsync | ||
], DynamoDocumentClient, "update", null); | ||
exports.DynamoDocumentClient = DynamoDocumentClient; |
{ | ||
"name": "node-aws-utils", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"description": "aws utils", | ||
@@ -32,8 +32,8 @@ "keywords": [ | ||
"aws-sdk": "^2.822.0", | ||
"node-result": "^10.1.0" | ||
"node-result": "^12.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^14.14.20", | ||
"@typescript-eslint/eslint-plugin": "^4.12.0", | ||
"@typescript-eslint/parser": "^4.12.0", | ||
"@typescript-eslint/eslint-plugin": "^4.21.0", | ||
"@typescript-eslint/parser": "^4.21.0", | ||
"eslint": "^7.17.0", | ||
@@ -43,4 +43,4 @@ "husky": "^5.2.0", | ||
"prettier": "^2.2.1", | ||
"typescript": "^4.1.3" | ||
"typescript": "^4.2.4" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7561
100
+ Addednode-result@12.1.0(transitive)
- Removednode-result@10.1.0(transitive)
- Removednode-result-error@1.3.0(transitive)
Updatednode-result@^12.0.0