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

@qrvey/data-persistence

Package Overview
Dependencies
Maintainers
11
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@qrvey/data-persistence - npm Package Compare versions

Comparing version 0.0.2-4 to 0.0.2-4-rev-1

dist/cjs/types/aggregateFunction.type.js

6

dist/cjs/helpers/queryHelpers.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.METHOD_TO_QUERY = void 0;
exports.buildAggFunctionAlias = exports.METHOD_TO_QUERY = void 0;
var METHOD_TO_QUERY;

@@ -10,2 +10,6 @@ (function (METHOD_TO_QUERY) {

})(METHOD_TO_QUERY || (exports.METHOD_TO_QUERY = METHOD_TO_QUERY = {}));
function buildAggFunctionAlias(aggregateFunction) {
return `AGG_FN_${aggregateFunction}`;
}
exports.buildAggFunctionAlias = buildAggFunctionAlias;
//# sourceMappingURL=queryHelpers.js.map

@@ -40,2 +40,7 @@ "use strict";

}
findCount(options) {
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
const { pagination } = options, findAllOptions = __rest(options, ["pagination"]);
return this.crudService.findCount(findAllOptions);
}
buildFilter(attribute, value, operator = 'EQUAL', options = {}) {

@@ -42,0 +47,0 @@ return (0, crudHelpers_1.buildFilter)(attribute, value, operator, options);

80

dist/cjs/services/cruds/dynamodb/dynamoDbCrud.service.js

@@ -67,2 +67,44 @@ "use strict";

}
async fetchResults(command, limit = 100, useScan = false) {
var _a, _b, _c, _d, _e;
let results = [];
let LastEvaluatedKey = {};
do {
if (this.isNotEmptyObject(LastEvaluatedKey))
command.ExclusiveStartKey = LastEvaluatedKey;
const result = await (useScan
? this.dynamoDbClientService.scan(command)
: this.dynamoDbClientService.query(command));
command.Limit = ((_a = command.Limit) !== null && _a !== void 0 ? _a : 0) - ((_c = (_b = result.Items) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0);
const rows = (_d = result.Items) !== null && _d !== void 0 ? _d : [];
results = [...results, ...rows];
LastEvaluatedKey = (_e = result.LastEvaluatedKey) !== null && _e !== void 0 ? _e : {};
} while (results.length < limit &&
this.isNotEmptyObject(LastEvaluatedKey));
const lastEvaluatedKey = this.isNotEmptyObject(LastEvaluatedKey)
? this.encryptPaginationKey(LastEvaluatedKey)
: null;
return { items: results, lastEvaluatedKey };
}
applyPagination(query, pagination) {
if (pagination === null || pagination === void 0 ? void 0 : pagination.limit)
query.limit(pagination.limit);
if (pagination === null || pagination === void 0 ? void 0 : pagination.from)
query.startKey(this.decryptPaginationKey(pagination.from));
}
async findAll(options = {}, allResults = []) {
const { items, pagination } = await this.find(options);
allResults.push(...items);
if (pagination === null || pagination === void 0 ? void 0 : pagination.from)
await this.findAll(Object.assign(Object.assign({}, options), { pagination }), allResults);
return {
items: allResults,
pagination: null,
count: allResults.length,
};
}
async findCount(options = {}) {
const { items } = await this.find(options);
return items.length;
}
async findItem(options) {

@@ -138,40 +180,2 @@ var _a, _b, _c;

}
async fetchResults(command, limit = 100, useScan = false) {
var _a, _b, _c, _d, _e;
let results = [];
let LastEvaluatedKey = {};
do {
if (this.isNotEmptyObject(LastEvaluatedKey))
command.ExclusiveStartKey = LastEvaluatedKey;
const result = await (useScan
? this.dynamoDbClientService.scan(command)
: this.dynamoDbClientService.query(command));
command.Limit = ((_a = command.Limit) !== null && _a !== void 0 ? _a : 0) - ((_c = (_b = result.Items) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0);
const rows = (_d = result.Items) !== null && _d !== void 0 ? _d : [];
results = [...results, ...rows];
LastEvaluatedKey = (_e = result.LastEvaluatedKey) !== null && _e !== void 0 ? _e : {};
} while (results.length < limit &&
this.isNotEmptyObject(LastEvaluatedKey));
const lastEvaluatedKey = this.isNotEmptyObject(LastEvaluatedKey)
? this.encryptPaginationKey(LastEvaluatedKey)
: null;
return { items: results, lastEvaluatedKey };
}
applyPagination(query, pagination) {
if (pagination === null || pagination === void 0 ? void 0 : pagination.limit)
query.limit(pagination.limit);
if (pagination === null || pagination === void 0 ? void 0 : pagination.from)
query.startKey(this.decryptPaginationKey(pagination.from));
}
async findAll(options = {}, allResults = []) {
const { items, pagination } = await this.find(options);
allResults.push(...items);
if (pagination === null || pagination === void 0 ? void 0 : pagination.from)
await this.findAll(Object.assign(Object.assign({}, options), { pagination }), allResults);
return {
items: allResults,
pagination: null,
count: allResults.length,
};
}
async update(filters, data, { replace = false }) {

@@ -178,0 +182,0 @@ const savedRecord = await this.findItem({

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

get connectionString() {
return process.env.PG_CONNECTION_STRING;
return process.env.MULTIPLATFORM_PG_CONNECTION_STRING;
}

@@ -14,0 +14,0 @@ async getClient() {

@@ -12,2 +12,3 @@ "use strict";

const tableHelper_1 = require("../../../helpers/tableHelper");
const queryHelpers_1 = require("../../../helpers/queryHelpers");
class PostgresqlClientService extends query_service_1.default {

@@ -108,3 +109,5 @@ constructor(tableSchema) {

}
getSelectClause(fields) {
getSelectClause(aggregateFunction, fields = []) {
if (aggregateFunction)
return `${aggregateFunction}(1) ${(0, queryHelpers_1.buildAggFunctionAlias)(aggregateFunction)}`;
if (!(fields === null || fields === void 0 ? void 0 : fields.length))

@@ -114,7 +117,7 @@ return '*';

}
async findCommand(options) {
let query = `SELECT ${this.getSelectClause(options === null || options === void 0 ? void 0 : options.fields)} FROM ${pg_format_1.default.ident(this.dbSchema)}.${pg_format_1.default.ident(this.tableName)}`;
query = this.addFiltersToQuery(query, options === null || options === void 0 ? void 0 : options.filters);
query = this.addOrderByToQuery(query, options === null || options === void 0 ? void 0 : options.sorting);
query = this.addPaginationToQuery(query, options === null || options === void 0 ? void 0 : options.pagination);
async findCommand(options = {}) {
let query = `SELECT ${this.getSelectClause(options.aggregateFunction, options.fields)} FROM ${pg_format_1.default.ident(this.dbSchema)}.${pg_format_1.default.ident(this.tableName)}`;
query = this.addFiltersToQuery(query, options.filters);
query = this.addOrderByToQuery(query, options.sorting);
query = this.addPaginationToQuery(query, options.pagination);
return (await this.runQuery(query)).rows;

@@ -121,0 +124,0 @@ }

@@ -11,2 +11,4 @@ "use strict";

const tableHelper_1 = require("../../../helpers/tableHelper");
const constants_1 = require("../../../utils/constants");
const queryHelpers_1 = require("../../../helpers/queryHelpers");
class PostgreSqlCrudService extends postgreSqlClient_service_1.default {

@@ -51,14 +53,25 @@ constructor(tableSchema) {

}
find(findOptions) {
async processQueryResult(findOptions, omitPagination = false) {
const { pagination } = findOptions;
return this.findCommand(findOptions).then((items) => {
return { items, pagination, count: items.length };
});
const rows = await this.findCommand(findOptions);
const items = rows.map((row) => this.getItem(row));
const result = {
items,
pagination: omitPagination ? null : pagination,
count: items.length,
};
return result;
}
findAll(findOptions) {
return this.findCommand(findOptions).then((rows) => {
const items = rows.map((row) => this.getItem(row));
return { items, pagination: null, count: items.length };
});
async find(findOptions) {
return this.processQueryResult(findOptions);
}
async findAll(findOptions) {
return this.processQueryResult(findOptions, true);
}
async findCount(findOptions) {
const items = await this.findCommand(Object.assign(Object.assign({}, findOptions), { aggregateFunction: constants_1.AGGREGATE_FUNCTIONS.COUNT }));
const aggFunctionProperty = (0, queryHelpers_1.buildAggFunctionAlias)(constants_1.AGGREGATE_FUNCTIONS.COUNT);
const item = items.length ? items[0] : {};
return item[aggFunctionProperty] || 0;
}
async update(filters, data) {

@@ -65,0 +78,0 @@ const savedRecord = await this.findItem({ filters });

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

constructor(usePool) {
const connectionString = process.env.PG_CONNECTION_STRING || '';
const connectionString = process.env.MULTIPLATFORM_PG_CONNECTION_STRING || '';
if (!connectionString) {

@@ -12,0 +12,0 @@ throw new Error('PG_CONNECTION_STRING environment variable must be configured');

@@ -21,2 +21,3 @@ "use strict";

__exportStar(require("./connectionClosingMode.type"), exports);
__exportStar(require("./aggregateFunction.type"), exports);
//# sourceMappingURL=index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_PG_SCHEMA = exports.POSTGRES_FILTER_OPERATOR_MAP = exports.FilterOperator = exports.FILTER_LOGIC_OPERATORS = exports.CONNECTION_CLOSING_MODES = exports.SORT_DIRECTIONS = exports.DYNAMODB_OPERATORS = exports.FILTER_OPERATOR_MAP = void 0;
exports.AGGREGATE_FUNCTIONS = exports.DEFAULT_PG_SCHEMA = exports.POSTGRES_FILTER_OPERATOR_MAP = exports.FilterOperator = exports.FILTER_LOGIC_OPERATORS = exports.CONNECTION_CLOSING_MODES = exports.SORT_DIRECTIONS = exports.DYNAMODB_OPERATORS = exports.FILTER_OPERATOR_MAP = void 0;
exports.FILTER_OPERATOR_MAP = {

@@ -68,2 +68,6 @@ CONTAINS: 'contains',

exports.DEFAULT_PG_SCHEMA = 'public';
var AGGREGATE_FUNCTIONS;
(function (AGGREGATE_FUNCTIONS) {
AGGREGATE_FUNCTIONS["COUNT"] = "COUNT";
})(AGGREGATE_FUNCTIONS || (exports.AGGREGATE_FUNCTIONS = AGGREGATE_FUNCTIONS = {}));
//# sourceMappingURL=constants.js.map

@@ -26,2 +26,3 @@ interface IFilter {

filters?: IFilter[] | ICompoundFilter;
aggregateFunction?: AggregateFunction;
sorting?: ISorting[];

@@ -38,2 +39,3 @@ pagination?: IFindPagination;

pagination?: IFindPagination | null;
count: number;
}

@@ -49,2 +51,5 @@

}
declare enum AGGREGATE_FUNCTIONS {
COUNT = "COUNT"
}

@@ -70,2 +75,5 @@ declare const VALID_SORT_DIRECTIONS: SORT_DIRECTIONS[];

declare const VALID_AGGREGATE_FUNCTIONS: AGGREGATE_FUNCTIONS[];
type AggregateFunction = (typeof VALID_AGGREGATE_FUNCTIONS)[number];
interface ISorting {

@@ -92,2 +100,3 @@ column: string;

findAll(options: IFindOptions): Promise<IFindResult<T>>;
findCount(options: IFindOptions): Promise<number>;
buildFilter(attribute: string, value: string, operator?: string, options?: {}): {

@@ -94,0 +103,0 @@ attribute: string;

@@ -5,3 +5,3 @@ {

"main": "dist/cjs/index.js",
"version": "0.0.2-4",
"version": "0.0.2-4-rev-1",
"license": "MIT",

@@ -8,0 +8,0 @@ "exports": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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