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 1.0.0-alpha.5 to 1.0.0-alpha.6

dist/service/TableService/__test__/TableService.test.d.ts

2

dist/service/TableService/index.d.ts

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

export * from "./NuTableService";
export * from "./TableService";

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

Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./NuTableService"));
__export(require("./TableService"));
import { DynamoDB } from "aws-sdk";
import { ConditionExpression, DynamoService, QueryParams, QueryResult, ScanParams, ScanResult, UpdateBody, UpdateReturnAllType, UpdateReturnNoneType, UpdateReturnType, UpdateReturnUpdatedType } from "../DynamoService";
import { KeySchema, TableSchema } from "../KeySchema";
import { TableSchemaBuilderProps } from "./SchemaBuilder/TableSchemaBuilder";
export { DynamoService, ConditionExpression, KeySchema, QueryParams, QueryResult, ScanParams, ScanResult, TableSchema, UpdateBody, UpdateReturnAllType, UpdateReturnNoneType, UpdateReturnUpdatedType, UpdateReturnType };
export declare const AWS_COLUMN_REGEX: RegExp;
export interface TableServiceProps {
trimUnknown?: boolean;
trimConstants?: boolean;
ignoreColumnsInGet?: RegExp | RegExp[];
export interface TableServiceProps extends TableSchemaBuilderProps {
}

@@ -20,5 +18,3 @@ export interface PutAllReturn<T> {

readonly tableSchema: TableSchema<T>;
private readonly props;
private readonly tableValidator;
private readonly tableSchemaConverter;
private readonly schemaBuilder;
private readonly primaryKey;

@@ -38,23 +34,18 @@ private readonly sortKey;

update(key: Partial<T>, obj: UpdateBody<T>, returnType: UpdateReturnAllType): Promise<T>;
update(key: Partial<T>, obj: UpdateBody<T>, returnType: UpdateReturnType): Promise<void> | Promise<Partial<T>> | Promise<T>;
update(key: Partial<T>, obj: UpdateBody<T>, conditionExpression: ConditionExpression, returnType: UpdateReturnAllType): Promise<T>;
update(key: Partial<T>, obj: UpdateBody<T>, conditionExpression: ConditionExpression, returnType: UpdateReturnType): Promise<void> | Promise<Partial<T>> | Promise<T>;
get<P extends keyof T>(key: Partial<T>): Promise<T>;
get<P extends keyof T>(key: Partial<T>[]): Promise<T[]>;
get<P extends keyof T>(key: Partial<T>, projection: P): Promise<Pick<T, P>>;
get<P extends keyof T>(key: Partial<T>, projection: P[]): Promise<Pick<T, P>>;
get<P extends keyof T>(key: Partial<T>[], projection: P): Promise<Pick<T, P>[]>;
get<P extends keyof T>(key: Partial<T>[], projection: P[]): Promise<Pick<T, P>[]>;
get<P extends keyof T>(key: Partial<T>, projection: string): Promise<Partial<T>>;
get<P extends keyof T>(key: Partial<T>, projection: string[]): Promise<Partial<T>>;
get<P extends keyof T>(key: Partial<T>[], projection: string): Promise<Partial<T>[]>;
get<P extends keyof T>(key: Partial<T>[], projection: string[]): Promise<Partial<T>[]>;
get<P extends keyof T>(key: Partial<T>, projection: P | P[]): Promise<Pick<T, P>>;
get<P extends keyof T>(key: Partial<T>[], projection: P | P[]): Promise<Pick<T, P>[]>;
get<P extends keyof T>(key: Partial<T>, projection: string | string[]): Promise<Partial<T>>;
get<P extends keyof T>(key: Partial<T>[], projection: string | string[]): Promise<Partial<T>[]>;
query(params: QueryParams): Promise<QueryResult<T>>;
query<P extends keyof T>(params: QueryParams, projection: P): Promise<QueryResult<Pick<T, P>>>;
query<P extends keyof T>(params: QueryParams, projection: P[]): Promise<QueryResult<Pick<T, P>>>;
query<P extends keyof T>(params: QueryParams, projection: P | P[]): Promise<QueryResult<Pick<T, P>>>;
query(params: QueryParams, projection: string): Promise<QueryResult<Partial<T>>>;
query(params: QueryParams, projection: string[]): Promise<QueryResult<Partial<T>>>;
scan(params: ScanParams): Promise<ScanResult<T>>;
scan<P extends keyof T>(params: ScanParams, projection: P): Promise<ScanResult<Pick<T, P>>>;
scan<P extends keyof T>(params: ScanParams, projection: P[]): Promise<ScanResult<Pick<T, P>>>;
scan(params: ScanParams, projection: string): Promise<ScanResult<Partial<T>>>;
scan(params: ScanParams, projection: string[]): Promise<ScanResult<Partial<T>>>;
scan<P extends keyof T>(params: ScanParams, projection: P | P[]): Promise<ScanResult<Pick<T, P>>>;
scan(params: ScanParams, projection: string | string[]): Promise<ScanResult<Partial<T>>>;
delete(key: Partial<T> | Partial<T>[]): Promise<void>;

@@ -64,2 +55,6 @@ private convertObjectsReturnedFromDynamo;

private validateAndConvertObjectToPutObject;
private validateAndConvertObjectToUpdateObject;
}
export declare class ValidationError extends Error {
constructor(msg: string[]);
}

@@ -6,4 +6,3 @@ "use strict";

exports.DynamoService = DynamoService_1.DynamoService;
const TableSchemaConverter_1 = require("./TableSchemaConverter");
const TableSchemaValidator_1 = require("./TableSchemaValidator");
const TableSchemaBuilder_1 = require("./SchemaBuilder/TableSchemaBuilder");
exports.AWS_COLUMN_REGEX = /^aws:.+/;

@@ -16,5 +15,3 @@ class TableService {

this.tableSchema = tableSchema;
this.props = props;
this.tableValidator = new TableSchemaValidator_1.TableSchemaValidator(tableSchema, tableName);
this.tableSchemaConverter = new TableSchemaConverter_1.TableSchemaConverter(tableSchema, props);
this.schemaBuilder = new TableSchemaBuilder_1.TableSchemaBuilder(tableSchema, Object.assign({}, props));
let primaryKeys = [];

@@ -41,3 +38,3 @@ let sortKeys = [];

return this.db.put(this.tableName, putObj, primaryExistsQuery.and(condition).query())
.then((res) => this.convertObjectsReturnedFromDynamo(putObj));
.then(() => this.convertObjectsReturnedFromDynamo(putObj));
}

@@ -48,11 +45,7 @@ putAll(obj) {

.then((unprocessed) => ({
unprocessed: unprocessed.map((u) => this.convertObjectsReturnedFromDynamo(u))
unprocessed: this.convertObjectsReturnedFromDynamo(unprocessed)
}));
}
update(key, obj, conditionExpression, returnType) {
const convertedUpdateObj = this.tableSchemaConverter.convertUpdateObj(obj, { trimConstants: this.props.trimConstants });
this.tableValidator.validateUpdateObj(convertedUpdateObj);
if (convertedUpdateObj.set) {
convertedUpdateObj.set = this.tableSchemaConverter.convertObjToDynamo(convertedUpdateObj.set);
}
const convertedUpdateObj = this.validateAndConvertObjectToUpdateObject(obj);
const dynamoKey = this.getKey(key);

@@ -67,3 +60,3 @@ return this.db

return this.db.get(this.tableName, realKey, realProjection)
.then(item => (item) ? this.convertObjectsReturnedFromDynamo(item) : item);
.then(item => this.convertObjectsReturnedFromDynamo(item));
}

@@ -85,3 +78,8 @@ query(params, projection) {

convertObjectsReturnedFromDynamo(objs) {
return this.tableSchemaConverter.convertObjFromDynamo(objs, { trimUnknown: this.props.trimUnknown, ignoreColumnsInGet: this.props.ignoreColumnsInGet });
if (objs) {
if (Array.isArray(objs)) {
return objs.map((o) => this.schemaBuilder.convertObjectFromSchema(o));
}
return this.schemaBuilder.convertObjectFromSchema(objs);
}
}

@@ -94,10 +92,27 @@ getKey(obj) {

}
return this.tableSchemaConverter.convertObjToDynamo(key);
return key;
}
validateAndConvertObjectToPutObject(obj) {
const newObj = this.tableSchemaConverter.convertObj(obj, { trimUnknown: this.props.trimUnknown });
this.tableValidator.validate(newObj);
return this.tableSchemaConverter.convertObjToDynamo(newObj);
const newObj = this.schemaBuilder.convertObjectToSchema(obj);
const errors = this.schemaBuilder.validateObjectAgainstSchema(newObj);
if (errors && errors.length > 0) {
throw new ValidationError(errors);
}
return newObj;
}
validateAndConvertObjectToUpdateObject(obj) {
const convertedUpdateObj = this.schemaBuilder.convertUpdateObjectToSchema(obj);
const errors = this.schemaBuilder.validateUpdateObjectAgainstSchema(convertedUpdateObj);
if (errors && errors.length > 0) {
throw new ValidationError(errors);
}
return convertedUpdateObj;
}
}
exports.TableService = TableService;
class ValidationError extends Error {
constructor(msg) {
super(`Errors: [ ${msg.join("\n")} ]`);
}
}
exports.ValidationError = ValidationError;
{
"name": "@xapp/dynamo-service",
"version": "1.0.0-alpha.5",
"version": "1.0.0-alpha.6",
"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