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.25 to 0.0.26

xapp-dynamo-service-0.0.25.tgz

29

dist/service/DynamoService.d.ts

@@ -21,14 +21,10 @@ import { DynamoDB } from "aws-sdk";

}
export interface Set {
[key: string]: any;
export declare type Set<T> = Partial<T>;
export declare type Remove<T> = (keyof T)[];
export declare type Append<T> = Partial<T>;
export interface UpdateBody<T> {
set?: Set<T>;
remove?: Remove<T>;
append?: Append<T>;
}
export interface UpdateBody {
set?: {
[key: string]: any;
};
remove?: string[];
append?: {
[key: string]: any[];
};
}
export declare type UpdateReturnType = DynamoDB.DocumentClient.ReturnValue;

@@ -39,6 +35,13 @@ export declare class DynamoService {

put(table: string, obj: DynamoDB.DocumentClient.PutItemInputAttributeMap): Promise<DynamoDB.DocumentClient.PutItemOutput>;
update<T>(table: string, key: DynamoDB.DocumentClient.Key, update: UpdateBody, returns?: UpdateReturnType): Promise<void> | Promise<T> | Promise<Partial<T>>;
update<T>(table: string, key: DynamoDB.DocumentClient.Key, update: UpdateBody<T>): Promise<void>;
update<T>(table: string, key: DynamoDB.DocumentClient.Key, update: UpdateBody<T>, returns: "NONE"): Promise<void>;
update<T>(table: string, key: DynamoDB.DocumentClient.Key, update: UpdateBody<T>, returns: "UPDATED_OLD" | "UPDATED_NEW"): Promise<Partial<T>>;
update<T>(table: string, key: DynamoDB.DocumentClient.Key, update: UpdateBody<T>, returns: "ALL_OLD" | "ALL_NEW"): Promise<T>;
update<T>(table: string, key: DynamoDB.DocumentClient.Key, update: UpdateBody<T>, returns: string): Promise<void>;
get<T>(table: string, key: DynamoDB.DocumentClient.Key): Promise<T>;
query<T>(table: string, myParams: QueryParams): Promise<QueryResult<T>>;
get<T, P extends keyof T>(table: string, key: DynamoDB.DocumentClient.Key, projection: P | P[]): Promise<Pick<T, P>>;
query<T, P extends keyof T>(table: string, myParams: QueryParams): Promise<QueryResult<T>>;
query<T, P extends keyof T>(table: string, myParams: QueryParams, projection: P | P[]): Promise<QueryResult<Pick<T, P>>>;
scan<T>(table: string, myParams: ScanParams): Promise<ScanResult<T>>;
scan<T, P extends keyof T>(table: string, myParams: ScanParams, projection: P | P[]): Promise<ScanResult<Pick<T, P>>>;
}

@@ -21,10 +21,8 @@ "use strict";

}
get(table, key) {
const params = {
TableName: table,
Key: key
};
return this.db.get(params).promise().then((item) => { return item.Item; });
get(TableName, Key, projection) {
const params = Object.assign({ TableName,
Key }, getProjectionExpression(projection));
return this.db.get(params).promise().then((item) => { console.log(item); return item.Item; });
}
query(table, myParams) {
query(table, myParams, projection) {
const params = {

@@ -34,2 +32,7 @@ TableName: table

addIfExists(params, myParams, ["KeyConditionExpression", "FilterExpression", "ExpressionAttributeNames", "ExpressionAttributeValues"]);
if (projection) {
const proj = getProjectionExpression(projection);
params.ExpressionAttributeNames = Object.assign({}, proj.ExpressionAttributeNames, params.ExpressionAttributeNames);
params.ProjectionExpression = proj.ProjectionExpression;
}
return this.db.query(params).promise().then((item) => {

@@ -42,3 +45,3 @@ return {

}
scan(table, myParams) {
scan(table, myParams, projection) {
const params = {

@@ -48,2 +51,9 @@ TableName: table,

addIfExists(params, myParams, ["FilterExpression", "ExpressionAttributeNames", "ExpressionAttributeValues"]);
if (projection) {
const proj = getProjectionExpression(projection);
params.ExpressionAttributeNames = Object.assign({}, proj.ExpressionAttributeNames, params.ExpressionAttributeNames);
params.ProjectionExpression = proj.ProjectionExpression;
}
console.log(myParams);
console.log(params);
return this.db.scan(params).promise().then((item) => {

@@ -82,3 +92,3 @@ return {

let setAliasMap;
let setExpression = undefined;
let setExpression;
const { set, append, remove } = body;

@@ -90,6 +100,6 @@ if (Object_1.objHasAttrs(set)) {

let index = 0;
for (let key in set) {
for (const key in set) {
if (set.hasOwnProperty(key)) {
const alias = "#" + key;
const name = ":__u_a__" + ++index;
const name = ":a" + ++index;
setExpression += alias + " = " + name + ",";

@@ -106,9 +116,9 @@ setValues[name] = set[key];

let index = 0;
for (let key in append) {
for (const key in append) {
if (append.hasOwnProperty(key)) {
const alias = "#append" + key;
const name = ":__u_c__" + ++index;
setExpression += alias + " = list_append(if_not_exists(" + alias + ",:empty_list)," + name + "),";
const name = ":c" + ++index;
setExpression += alias + " = list_append(if_not_exists(" + alias + ", :append_empty_list)," + name + "),";
setValues[name] = append[key];
setValues[":empty_list"] = [];
setValues[":append_empty_list"] = [];
setAliasMap[alias] = key;

@@ -121,3 +131,3 @@ }

setAliasMap = setAliasMap || {};
setExpression = (setExpression) ? setExpression.substr(0, setExpression.length - 1) + " remove " : "remove ";
setExpression = setExpression ? setExpression.substr(0, setExpression.length - 1) + " remove " : "remove ";
remove.forEach((key) => {

@@ -139,3 +149,21 @@ const alias = "#" + key;

}
console.log(returnValue);
return returnValue;
}
function getProjectionExpression(projectionExpression) {
let ProjectionExpression = "";
let ExpressionAttributeNames = {};
if (!projectionExpression) {
return {};
}
const expression = [].concat(projectionExpression);
expression.forEach((value, index) => {
const key = "#proj" + index;
ExpressionAttributeNames[key] = value;
ProjectionExpression += key;
if (index < expression.length - 1) {
ProjectionExpression += ",";
}
});
return { ProjectionExpression, ExpressionAttributeNames };
}

@@ -1,2 +0,2 @@

import { DynamoService, QueryParams, QueryResult, ScanParams, ScanResult, UpdateBody, UpdateReturnType } from "./DynamoService";
import { DynamoService, QueryParams, QueryResult, ScanParams, ScanResult, UpdateBody } from "./DynamoService";
export { DynamoService, QueryParams, QueryResult, ScanParams, ScanResult };

@@ -27,6 +27,13 @@ export declare type DynamoType = "S" | "N" | "M" | "L";

put<T>(obj: T): Promise<T>;
update<T>(key: Partial<T>, obj: UpdateBody, returnType?: UpdateReturnType): Promise<void>;
get<T>(key: Partial<T>): Promise<{}>;
update<T>(key: Partial<T>, obj: UpdateBody<T>): Promise<void>;
update<T>(key: Partial<T>, obj: UpdateBody<T>, returnType: "NONE"): Promise<void>;
update<T>(key: Partial<T>, obj: UpdateBody<T>, returnType: "UPDATED_OLD" | "UPDATED_NEW"): Promise<Partial<T>>;
update<T>(key: Partial<T>, obj: UpdateBody<T>, returnType: "ALL_OLD" | "ALL_NEW"): Promise<T>;
update<T>(key: Partial<T>, obj: UpdateBody<T>, returnType?: string): Promise<void>;
get<T>(key: Partial<T>): Promise<T>;
get<T, P extends keyof T>(key: Partial<T>, projection: P | P[]): Promise<Pick<T, P>>;
query<T>(params: QueryParams): Promise<QueryResult<T>>;
query<T, P extends keyof T>(params: QueryParams, projection: P | P[]): Promise<QueryResult<Pick<T, P>>>;
scan<T>(params: ScanParams): Promise<ScanResult<T>>;
scan<T, P extends keyof T>(params: ScanParams, projection: P | P[]): Promise<Pick<T, P>>;
}

@@ -54,12 +54,12 @@ "use strict";

}
get(key) {
return this.db.get(this.tableName, key);
get(key, projection) {
return this.db.get(this.tableName, key, projection);
}
query(params) {
return this.db.query(this.tableName, params);
query(params, projection) {
return this.db.query(this.tableName, params, projection);
}
scan(params) {
return this.db.scan(this.tableName, params);
scan(params, projection) {
return this.db.scan(this.tableName, params, projection);
}
}
exports.TableService = TableService;
{
"name": "@xapp/dynamo-service",
"version": "0.0.25",
"version": "0.0.26",
"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