Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@xapp/dynamo-service

Package Overview
Dependencies
Maintainers
5
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xapp/dynamo-service - npm Package Compare versions

Comparing version 0.0.105 to 0.0.106

xapp-dynamo-service-0.0.105.tgz

5

dist/service/DynamoService.d.ts

@@ -38,2 +38,3 @@ import { DynamoDB } from "aws-sdk";

export declare type Append<T> = Partial<T>;
export declare type Interceptor<T> = (obj: T) => T;
export interface UpdateBody<T> {

@@ -50,3 +51,7 @@ set?: Set<T>;

readonly db: DynamoDB.DocumentClient;
private readonly putInterceptors;
private readonly updateInterceptors;
constructor(db: ConstructorDB);
addPutInterceptor<T>(interceptor: Interceptor<T>): void;
addUpdateInterceptor<T>(interceptor: Interceptor<UpdateBody<T>>): void;
put(TableName: string, obj: DynamoDB.DocumentClient.PutItemInputAttributeMap): Promise<DynamoDB.DocumentClient.PutItemOutput>;

@@ -53,0 +58,0 @@ put(TableName: string, obj: DynamoDB.DocumentClient.PutItemInputAttributeMap, condition: ConditionExpression): Promise<DynamoDB.DocumentClient.PutItemOutput>;

41

dist/service/DynamoService.js

@@ -21,6 +21,21 @@ "use strict";

this.db = getDb(db);
this.putInterceptors = [];
this.updateInterceptors = [];
}
addPutInterceptor(interceptor) {
if (!interceptor) {
throw new Error("Put interceptor can not be undefined.");
}
this.putInterceptors.push(interceptor);
}
addUpdateInterceptor(interceptor) {
if (!interceptor) {
throw new Error("Update interceptor can not be undefined.");
}
this.updateInterceptors.push(interceptor);
}
put(TableName, obj, condition = {}) {
if (Array.isArray(obj)) {
return this.batchWrites(TableName, createPutBatchWriteRequests(obj), condition).then(unprocessed => {
const putObjs = interceptObj(this.putInterceptors, obj);
if (Array.isArray(putObjs)) {
return this.batchWrites(TableName, createPutBatchWriteRequests(putObjs), condition).then(unprocessed => {
const unProcessedItems = [];

@@ -33,8 +48,9 @@ for (let u of unprocessed) {

}
const params = Object.assign({ TableName, Item: obj }, condition);
const params = Object.assign({ TableName, Item: putObjs }, condition);
return this.db.put(params).promise();
}
update(table, key, update, conditionOrReturns = {}, returns = "NONE") {
const newUpdate = transferUndefinedToRemove(update);
newUpdate.set = removeUndefinedAndBlanks(update.set);
let newUpdate = interceptObj(this.updateInterceptors, update);
newUpdate = transferUndefinedToRemove(newUpdate);
newUpdate.set = removeUndefinedAndBlanks(newUpdate.set);
const updateExpression = getUpdateParameters(newUpdate);

@@ -165,2 +181,15 @@ const conditionExpression = (typeof conditionOrReturns === "object") ? conditionOrReturns : {};

exports.DynamoService = DynamoService;
function interceptObj(interceptors, obj) {
return Array.isArray(obj) ? obj.map(o => intercept(interceptors, o)) : intercept(interceptors, obj);
}
function intercept(interceptors, obj) {
let returnObj = obj;
for (const interceptor of interceptors) {
returnObj = interceptor(returnObj);
}
if (returnObj === undefined) {
throw new Error("Interceptors must return an object.");
}
return returnObj;
}
function createPutBatchWriteRequests(objs) {

@@ -220,3 +249,3 @@ if (Array.isArray(objs)) {

else {
throw new ValidationError_1.ValidationError("Could not construct DynamoService. Bad input.");
throw new ValidationError_1.ValidationError("Could not construct DynamoService. Bad input.");
}

@@ -223,0 +252,0 @@ }

2

package.json
{
"name": "@xapp/dynamo-service",
"version": "0.0.105",
"version": "0.0.106",
"description": "A dynamo help class which will help maintain data integrity.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc