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

electrodb

Package Overview
Dependencies
Maintainers
1
Versions
163
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electrodb - npm Package Compare versions

Comparing version 0.10.1 to 0.10.2

2

package.json
{
"name": "electrodb",
"version": "0.10.1",
"version": "0.10.2",
"description": "A library to more easily create and interact with multiple entities and heretical relationships in dynamodb",

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

@@ -6,10 +6,19 @@ const { QueryTypes, MethodTypes } = require("./types");

function batchAction(action, type, entity, state, payload) {
state.query.method = type;
for (let facets of payload) {
let batchState = action(entity, state.batch.create(), facets);
state.batch.push(batchState);
if (state.error !== null) {
return state;
}
return state;
try {
state.query.method = type;
for (let facets of payload) {
let batchState = action(entity, state.batch.create(), facets);
if (batchState.error !== null) {
throw batchState.error;
}
state.batch.push(batchState);
}
return state;
} catch(err) {
state.error = err;
return state;
}
}

@@ -26,8 +35,16 @@

action(entity, state, collection = "", facets /* istanbul ignore next */ = {}) {
state.query.keys.pk = entity._expectFacets(facets, state.query.facets.pk);
entity._expectFacets(facets, Object.keys(facets), `"query" facets`);
state.query.collection = collection;
state.query.method = MethodTypes.query;
state.query.type = QueryTypes.collection;
return state;
if (state.error !== null) {
return state;
}
try {
state.query.keys.pk = entity._expectFacets(facets, state.query.facets.pk);
entity._expectFacets(facets, Object.keys(facets), `"query" facets`);
state.query.collection = collection;
state.query.method = MethodTypes.query;
state.query.type = QueryTypes.collection;
return state;
} catch(err) {
state.error = err;
return state;
}
},

@@ -39,4 +56,12 @@ children: ["params", "go", "page"],

action(entity, state) {
state.query.method = MethodTypes.scan;
return state;
if (state.error !== null) {
return state;
}
try {
state.query.method = MethodTypes.scan;
return state;
} catch(err) {
state.error = err;
return state;
}
},

@@ -49,16 +74,24 @@ children: ["params", "go", "page"],

action(entity, state, facets = {}) {
state.query.keys.pk = entity._expectFacets(facets, state.query.facets.pk);
state.query.method = MethodTypes.get;
state.query.type = QueryTypes.eq;
if (state.hasSortKey) {
let queryFacets = entity._buildQueryFacets(
facets,
state.query.facets.sk,
);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
if (state.error !== null) {
return state;
}
return state;
try {
state.query.keys.pk = entity._expectFacets(facets, state.query.facets.pk);
state.query.method = MethodTypes.get;
state.query.type = QueryTypes.eq;
if (state.hasSortKey) {
let queryFacets = entity._buildQueryFacets(
facets,
state.query.facets.sk,
);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
}
return state;
} catch(err) {
state.error = err;
return state;
}
},

@@ -81,16 +114,24 @@ children: ["params", "go"],

action(entity, state, facets = {}) {
state.query.keys.pk = entity._expectFacets(facets, state.query.facets.pk);
state.query.method = MethodTypes.delete;
state.query.type = QueryTypes.eq;
if (state.hasSortKey) {
let queryFacets = entity._buildQueryFacets(
facets,
state.query.facets.sk,
);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
if (state.error !== null) {
return state;
}
return state;
try {
state.query.keys.pk = entity._expectFacets(facets, state.query.facets.pk);
state.query.method = MethodTypes.delete;
state.query.type = QueryTypes.eq;
if (state.hasSortKey) {
let queryFacets = entity._buildQueryFacets(
facets,
state.query.facets.sk,
);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
}
return state;
} catch(err) {
state.error = err;
return state;
}
},

@@ -103,19 +144,26 @@ children: ["params", "go"],

action(entity, state, payload) {
let record = entity.model.schema.checkCreate({ ...payload });
state.query.keys.pk = entity._expectFacets(record, state.query.facets.pk);
state.query.method = MethodTypes.put;
state.query.type = QueryTypes.eq;
if (state.hasSortKey) {
let queryFacets = entity._buildQueryFacets(
record,
state.query.facets.sk,
);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
if (state.error !== null) {
return state;
}
state.query.put.data = Object.assign({}, record);
return state;
try {
let record = entity.model.schema.checkCreate({...payload});
state.query.keys.pk = entity._expectFacets(record, state.query.facets.pk);
state.query.method = MethodTypes.put;
state.query.type = QueryTypes.eq;
if (state.hasSortKey) {
let queryFacets = entity._buildQueryFacets(
record,
state.query.facets.sk,
);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
}
state.query.put.data = Object.assign({}, record);
return state;
} catch(err) {
state.error = err;
return state;
}
},

@@ -132,18 +180,26 @@ children: ["params", "go"],

action(entity, state, payload) {
let record = entity.model.schema.checkCreate({ ...payload });
state.query.keys.pk = entity._expectFacets(record, state.query.facets.pk);
state.query.method = MethodTypes.put;
state.query.type = QueryTypes.eq;
if (state.hasSortKey) {
let queryFacets = entity._buildQueryFacets(
record,
state.query.facets.sk,
);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
if (state.error !== null) {
return state;
}
state.query.put.data = Object.assign({}, record);
return state;
try {
let record = entity.model.schema.checkCreate({...payload});
state.query.keys.pk = entity._expectFacets(record, state.query.facets.pk);
state.query.method = MethodTypes.put;
state.query.type = QueryTypes.eq;
if (state.hasSortKey) {
let queryFacets = entity._buildQueryFacets(
record,
state.query.facets.sk,
);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
}
state.query.put.data = Object.assign({}, record);
return state;
} catch(err) {
state.error = err;
return state;
}
},

@@ -155,18 +211,26 @@ children: ["params", "go"],

action(entity, state, facets) {
state.query.keys.pk = entity._expectFacets(facets, state.query.facets.pk);
state.query.method = MethodTypes.update;
state.query.type = QueryTypes.eq;
if (state.hasSortKey) {
let queryFacets = entity._buildQueryFacets(
facets,
state.query.facets.sk,
);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
if (state.error !== null) {
return state;
}
return state;
try {
state.query.keys.pk = entity._expectFacets(facets, state.query.facets.pk);
state.query.method = MethodTypes.update;
state.query.type = QueryTypes.eq;
if (state.hasSortKey) {
let queryFacets = entity._buildQueryFacets(
facets,
state.query.facets.sk,
);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
}
return state;
} catch(err) {
state.error = err;
return state;
}
},
children: ["set", "append", "remove", "add", "subtract", ],
children: ["set", "append", "remove", "add", "subtract"],
},

@@ -176,16 +240,24 @@ update: {

action(entity, state, facets) {
state.query.keys.pk = entity._expectFacets(facets, state.query.facets.pk);
state.query.method = MethodTypes.update;
state.query.type = QueryTypes.eq;
if (state.hasSortKey) {
let queryFacets = entity._buildQueryFacets(
facets,
state.query.facets.sk,
);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
if (state.error !== null) {
return state;
}
return state;
try {
state.query.keys.pk = entity._expectFacets(facets, state.query.facets.pk);
state.query.method = MethodTypes.update;
state.query.type = QueryTypes.eq;
if (state.hasSortKey) {
let queryFacets = entity._buildQueryFacets(
facets,
state.query.facets.sk,
);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
}
return state;
} catch(err) {
state.error = err;
return state;
}
},

@@ -197,9 +269,17 @@ children: ["set", "append", "remove", "add", "subtract"],

action(entity, state, data) {
let record = entity.model.schema.checkUpdate({ ...data });
state.query.update.set = Object.assign(
{},
state.query.update.set,
record,
);
return state;
if (state.error !== null) {
return state;
}
try {
let record = entity.model.schema.checkUpdate({...data});
state.query.update.set = Object.assign(
{},
state.query.update.set,
record,
);
return state;
} catch(err) {
state.error = err;
return state;
}
},

@@ -244,14 +324,22 @@ children: ["set", "go", "params"],

action(entity, state, facets, options = {}) {
state.query.keys.pk = entity._expectFacets(facets, state.query.facets.pk);
entity._expectFacets(facets, Object.keys(facets), `"query" facets`);
state.query.method = MethodTypes.query;
state.query.type = QueryTypes.is;
if (state.query.facets.sk) {
let queryFacets = entity._buildQueryFacets(facets, state.query.facets.sk);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
if (state.error !== null) {
return state;
}
return state;
try {
state.query.keys.pk = entity._expectFacets(facets, state.query.facets.pk);
entity._expectFacets(facets, Object.keys(facets), `"query" facets`);
state.query.method = MethodTypes.query;
state.query.type = QueryTypes.is;
if (state.query.facets.sk) {
let queryFacets = entity._buildQueryFacets(facets, state.query.facets.sk);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
}
return state;
} catch(err) {
state.error = err;
return state;
}
},

@@ -263,30 +351,38 @@ children: ["between", "gte", "gt", "lte", "lt", "begins", "params", "go", "page"],

action(entity, state, startingFacets = {}, endingFacets = {}) {
entity._expectFacets(
startingFacets,
Object.keys(startingFacets),
`"between" facets`,
);
entity._expectFacets(
endingFacets,
Object.keys(endingFacets),
`"and" facets`,
);
state.query.type = QueryTypes.between;
let queryEndingFacets = entity._buildQueryFacets(
endingFacets,
state.query.facets.sk,
);
let queryStartingFacets = entity._buildQueryFacets(
startingFacets,
state.query.facets.sk,
);
state.query.keys.sk.push({
type: QueryTypes.and,
facets: queryEndingFacets,
});
state.query.keys.sk.push({
type: QueryTypes.between,
facets: queryStartingFacets,
});
return state;
if (state.error !== null) {
return state;
}
try {
entity._expectFacets(
startingFacets,
Object.keys(startingFacets),
`"between" facets`,
);
entity._expectFacets(
endingFacets,
Object.keys(endingFacets),
`"and" facets`,
);
state.query.type = QueryTypes.between;
let queryEndingFacets = entity._buildQueryFacets(
endingFacets,
state.query.facets.sk,
);
let queryStartingFacets = entity._buildQueryFacets(
startingFacets,
state.query.facets.sk,
);
state.query.keys.sk.push({
type: QueryTypes.and,
facets: queryEndingFacets,
});
state.query.keys.sk.push({
type: QueryTypes.between,
facets: queryStartingFacets,
});
return state;
} catch(err) {
state.error = err;
return state;
}
},

@@ -298,10 +394,18 @@ children: ["go", "params", "page"],

action(entity, state, facets = {}) {
entity._expectFacets(facets, Object.keys(facets), `"gt" facets`);
state.query.type = QueryTypes.begins;
let queryFacets = entity._buildQueryFacets(facets, state.query.facets.sk);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
return state;
if (state.error !== null) {
return state;
}
try {
entity._expectFacets(facets, Object.keys(facets), `"gt" facets`);
state.query.type = QueryTypes.begins;
let queryFacets = entity._buildQueryFacets(facets, state.query.facets.sk);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
return state;
} catch(err) {
state.error = err;
return state;
}
},

@@ -313,10 +417,18 @@ children: ["go", "params", "page"],

action(entity, state, facets = {}) {
entity._expectFacets(facets, Object.keys(facets), `"gt" facets`);
state.query.type = QueryTypes.gt;
let queryFacets = entity._buildQueryFacets(facets, state.query.facets.sk);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
return state;
if (state.error !== null) {
return state;
}
try {
entity._expectFacets(facets, Object.keys(facets), `"gt" facets`);
state.query.type = QueryTypes.gt;
let queryFacets = entity._buildQueryFacets(facets, state.query.facets.sk);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
return state;
} catch(err) {
state.error = err;
return state;
}
},

@@ -328,10 +440,18 @@ children: ["go", "params", "page"],

action(entity, state, facets = {}) {
entity._expectFacets(facets, Object.keys(facets), `"gte" facets`);
state.query.type = QueryTypes.gte;
let queryFacets = entity._buildQueryFacets(facets, state.query.facets.sk);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
return state;
if (state.error !== null) {
return state;
}
try {
entity._expectFacets(facets, Object.keys(facets), `"gte" facets`);
state.query.type = QueryTypes.gte;
let queryFacets = entity._buildQueryFacets(facets, state.query.facets.sk);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
return state;
} catch(err) {
state.error = err;
return state;
}
},

@@ -343,10 +463,18 @@ children: ["go", "params", "page"],

action(entity, state, facets = {}) {
entity._expectFacets(facets, Object.keys(facets), `"lt" facets`);
state.query.type = QueryTypes.lt;
let queryFacets = entity._buildQueryFacets(facets, state.query.facets.sk);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
return state;
if (state.error !== null) {
return state;
}
try {
entity._expectFacets(facets, Object.keys(facets), `"lt" facets`);
state.query.type = QueryTypes.lt;
let queryFacets = entity._buildQueryFacets(facets, state.query.facets.sk);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
return state;
} catch(err) {
state.error = err;
return state;
}
},

@@ -358,10 +486,18 @@ children: ["go", "params", "page"],

action(entity, state, facets = {}) {
entity._expectFacets(facets, Object.keys(facets), `"lte" facets`);
state.query.type = QueryTypes.lte;
let queryFacets = entity._buildQueryFacets(facets, state.query.facets.sk);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
return state;
if (state.error !== null) {
return state;
}
try {
entity._expectFacets(facets, Object.keys(facets), `"lte" facets`);
state.query.type = QueryTypes.lte;
let queryFacets = entity._buildQueryFacets(facets, state.query.facets.sk);
state.query.keys.sk.push({
type: state.query.type,
facets: queryFacets,
});
return state;
} catch(err) {
state.error = err;
return state;
}
},

@@ -373,13 +509,22 @@ children: ["go", "params", "page"],

action(entity, state, options = {}) {
if (!v.isStringHasLength(options.table) && !v.isStringHasLength(entity._getTableName())) {
throw new e.ElectroError(e.ErrorCodes.MissingTable, `Table name not defined. Table names must be either defined on the model, instance configuration, or as a query option.`);
if (state.error !== null) {
throw state.error;
}
if (state.query.method === MethodTypes.query) {
return entity._queryParams(state, options);
} else if(state.query.method === MethodTypes.batchWrite) {
return entity._batchWriteParams(state, options);
} else if (state.query.method === MethodTypes.batchGet) {
return entity._batchGetParams(state, options);
} else {
return entity._params(state, options);
try {
if (!v.isStringHasLength(options.table) && !v.isStringHasLength(entity._getTableName())) {
throw new e.ElectroError(e.ErrorCodes.MissingTable, `Table name not defined. Table names must be either defined on the model, instance configuration, or as a query option.`);
}
let results;
if (state.query.method === MethodTypes.query) {
results = entity._queryParams(state, options);
} else if (state.query.method === MethodTypes.batchWrite) {
results = entity._batchWriteParams(state, options);
} else if (state.query.method === MethodTypes.batchGet) {
results = entity._batchGetParams(state, options);
} else {
results = entity._params(state, options);
}
return results;
} catch(err) {
throw err;
}

@@ -392,8 +537,15 @@ },

action(entity, state, options = {}) {
if (entity.client === undefined) {
throw new e.ElectroError(e.ErrorCodes.NoClientDefined, "No client defined on model");
if (state.error !== null) {
return Promise.reject(state.error);
}
let params = clauses.params.action(entity, state, options);
let {config} = entity._applyParameterOptions({}, state.query.options, options);
return entity.go(state.query.method, params, config);
try {
if (entity.client === undefined) {
throw new e.ElectroError(e.ErrorCodes.NoClientDefined, "No client defined on model");
}
let params = clauses.params.action(entity, state, options);
let {config} = entity._applyParameterOptions({}, state.query.options, options);
return entity.go(state.query.method, params, config);
} catch(err) {
return Promise.reject(err);
}
},

@@ -405,9 +557,16 @@ children: [],

action(entity, state, page = null, options = {}) {
options.page = page;
options.pager = true;
if (entity.client === undefined) {
throw new e.ElectroError(e.ErrorCodes.NoClientDefined, "No client defined on model");
if (state.error !== null) {
return Promise.reject(state.error);
}
let params = clauses.params.action(entity, state, options);
return entity.go(state.query.method, params, options);
try {
options.page = page;
options.pager = true;
if (entity.client === undefined) {
throw new e.ElectroError(e.ErrorCodes.NoClientDefined, "No client defined on model");
}
let params = clauses.params.action(entity, state, options);
return entity.go(state.query.method, params, options);
} catch(err) {
return Promise.reject(err);
}
},

@@ -420,2 +579,3 @@ children: []

return {
error: null,
query: {

@@ -422,0 +582,0 @@ index: index,

@@ -64,3 +64,3 @@ "use strict";

for (let facet of Object.keys(facets)) {
if (attr[facet]) {
if (attr[facet] !== undefined && facets[facet] !== undefined) {
eqFilters.push(attr[facet].eq(facets[facet]));

@@ -77,3 +77,3 @@ }

for (let facet of Object.keys(facets)) {
if (attr[facet]) {
if (attr[facet] !== undefined && facets[facet] !== undefined) {
eqFilters.push(attr[facet].eq(facets[facet]));

@@ -334,3 +334,3 @@ }

if (config.raw) {
if (config.raw && !config.pager) {
if (response.TableName) {

@@ -342,2 +342,4 @@ // a VERY hacky way to deal with PUTs

}
} else if (config.raw && config.pager) {
return [response.LastEvaluatedKey || null, response];
} else {

@@ -365,3 +367,3 @@ let data = {};

let nextPage = response.LastEvaluatedKey || null;
if (!config.raw && !config.lastEvaluatedKeyRaw) {
if (!config.lastEvaluatedKeyRaw) {
nextPage = this._formatReturnPager(index, nextPage, results[results.length - 1]);

@@ -1407,3 +1409,3 @@ }

_getCollectionSk(collection) {
if (typeof collection && collection.length) {
if (typeof collection === "string" && collection.length) {
return `$${collection}`.toLowerCase();

@@ -1410,0 +1412,0 @@ } else {

@@ -142,11 +142,27 @@ const e = require("./errors");

_cleanUpExpression(value) {
if (typeof value === "string" && value.length > 0) {
return value.replace(/\n|\r/g, "").trim();
}
return ""
}
_isEmptyExpression(value) {
if (typeof value !== "string") {
throw new Error("Invalid expression value type. Expected type string.");
}
return !value.replace(/\n|\r|\w/g, "").trim();
}
_concatFilterExpression(existingExpression = "", newExpression = "") {
if (typeof existingExpression === "string" && existingExpression.length) {
existingExpression = existingExpression.replace(/\n|\r/g, "").trim();
newExpression = newExpression.replace(/\n|\r/g, "").trim();
existingExpression = this._cleanUpExpression(existingExpression);
newExpression = this._cleanUpExpression(newExpression);
let isEmpty = this._isEmptyExpression(newExpression);
if (isEmpty) {
return existingExpression;
}
let existingNeedsParens =
!existingExpression.startsWith("(") &&
!existingExpression.endsWith(")");
let newNeedsParens =
!newExpression.startsWith("(") && !newExpression.endsWith(")");
if (existingNeedsParens) {

@@ -153,0 +169,0 @@ existingExpression = `(${existingExpression})`;

@@ -75,6 +75,24 @@ const __is_clause__ = Symbol("IsWhereClause");

_cleanUpExpression(value) {
if (typeof value === "string" && value.length > 0) {
return value.replace(/\n|\r/g, "").trim();
}
return ""
}
_isEmptyExpression(value) {
if (typeof value !== "string") {
throw new Error("Invalid expression value type. Expected type string.");
}
return !value.replace(/\n|\r|\w/g, "").trim();
}
_concatFilterExpression(existingExpression = "", newExpression = "") {
if (typeof existingExpression === "string" && existingExpression.length) {
existingExpression = existingExpression.replace(/\n|\r/g, "").trim();
newExpression = newExpression.replace(/\n|\r/g, "").trim();
if (typeof existingExpression === "string" && existingExpression.length > 0) {
existingExpression = this._cleanUpExpression(existingExpression);
newExpression = this._cleanUpExpression(newExpression);
let isEmpty = this._isEmptyExpression(newExpression);
if (isEmpty) {
return existingExpression;
}
let existingNeedsParens = !existingExpression.startsWith("(") && !existingExpression.endsWith(")");

@@ -81,0 +99,0 @@ if (existingNeedsParens) {

Sorry, the diff of this file is too big to display

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