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

@qrvey/data-persistence

Package Overview
Dependencies
Maintainers
0
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.5.0-bundled to 0.5.0

dist/esm/chunk-6MOAJFFY.mjs

2

dist/cjs/services/crud.service.js

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

async getCrudServiceInstance() {
const crudService = await crudFactory_service_1.CrudFactory.databaseClientService(this.crudSchema);
const crudService = await crudFactory_service_1.CrudFactory.databaseClientService(this.crudSchema, this.poolClient);
return crudService;

@@ -25,0 +25,0 @@ }

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CrudFactory = void 0;
const cruds_1 = require("./cruds/");
class CrudFactory {
static databaseClientService(crudSchema) {
static async databaseClientService(crudSchema, poolClient) {
var _a;
const isMultiPlatformMode = ((_a = process.env.PLATFORM_TYPE) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'container';
if (isMultiPlatformMode)
return new cruds_1.PostgreSqlCrudService(crudSchema);
return new cruds_1.DynamoDbCrudService(crudSchema);
let DatabaseCrudService;
if (isMultiPlatformMode) {
const module = await Promise.resolve().then(() => __importStar(require('./cruds/postgresql/postgreSqlCrud.service')));
DatabaseCrudService = module.PostgreSqlCrudService;
}
else {
const module = await Promise.resolve().then(() => __importStar(require('./cruds/dynamodb/dynamoDbCrud.service')));
DatabaseCrudService = module.DynamoDbCrudService;
}
return new DatabaseCrudService(crudSchema, poolClient);
}

@@ -13,0 +42,0 @@ }

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

Object.defineProperty(exports, "__esModule", { value: true });
const pg_format_1 = require("@scaleleap/pg-format");
const pg_format_1 = __importDefault(require("pg-format"));
const query_service_1 = __importDefault(require("./query.service"));

@@ -43,3 +43,3 @@ const constants_1 = require("../../../utils/constants");

var _a;
const formattedValue = (0, pg_format_1.literal)(value);
const formattedValue = pg_format_1.default.literal(value);
operator = operator

@@ -52,3 +52,3 @@ ? operator.toUpperCase()

let property;
const filterProperty = (0, pg_format_1.ident)(attribute);
const filterProperty = pg_format_1.default.ident(attribute);
const columnExists = !!this.crudSchema.columns[attribute];

@@ -71,3 +71,3 @@ const columnType = columnExists && ((_a = this.crudSchema.columns[attribute]) === null || _a === void 0 ? void 0 : _a.type);

const formattedValues = Array.isArray(value)
? value.map(pg_format_1.literal)
? value.map(pg_format_1.default.literal)
: [formattedValue];

@@ -83,3 +83,3 @@ return `${property} ${postgresOperator} (${formattedValues.join(', ')})`;

if (operator === constants_1.FilterOperator.NOT_EQUAL && value !== null) {
return `(${property} ${postgresOperator} ${(0, pg_format_1.literal)(value)} OR ${property} IS NULL)`;
return `(${property} ${postgresOperator} ${pg_format_1.default.literal(value)} OR ${property} IS NULL)`;
}

@@ -106,3 +106,3 @@ if (operator === constants_1.FilterOperator.NOT_EXIST ||

const wildcardValue = this.getWildcardValue(operator, value);
return `${property} ${postgresOperator} ${(0, pg_format_1.literal)(wildcardValue)}`;
return `${property} ${postgresOperator} ${pg_format_1.default.literal(wildcardValue)}`;
}

@@ -150,3 +150,3 @@ buildFilterClause(filters, logicOperator) {

formatOrderByItem(sort) {
return `${(0, pg_format_1.ident)(sort.column)} ${sort.direction || constants_1.SORT_DIRECTIONS.ASC}`;
return `${pg_format_1.default.ident(sort.column)} ${sort.direction || constants_1.SORT_DIRECTIONS.ASC}`;
}

@@ -187,3 +187,3 @@ buildOrderByClause(querySorting) {

const values = data.map((item) => keys.map((key) => this.formatValue(item[key])));
const query = (0, pg_format_1.format)(`INSERT INTO ${(0, pg_format_1.ident)(this.dbSchema)}.${(0, pg_format_1.ident)(this.tableName)} (%I) VALUES %L RETURNING *;`, keys, values);
const query = (0, pg_format_1.default)(`INSERT INTO ${pg_format_1.default.ident(this.dbSchema)}.${pg_format_1.default.ident(this.tableName)} (%I) VALUES %L RETURNING *;`, keys, values);
return this.runQuery(query);

@@ -235,3 +235,3 @@ }

async findCommand(options = {}) {
let query = `SELECT ${this.getSelectClause(options.aggregateFunction, options.fields)} FROM ${(0, pg_format_1.ident)(this.dbSchema)}.${(0, pg_format_1.ident)(this.tableName)}`;
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);

@@ -264,10 +264,10 @@ if (!options.aggregateFunction) {

else {
return (0, pg_format_1.literal)(value);
return pg_format_1.default.literal(value);
}
}
async updateCommand(filters, data) {
let query = `UPDATE ${(0, pg_format_1.ident)(this.dbSchema)}.${(0, pg_format_1.ident)(this.tableName)} SET`;
let query = `UPDATE ${pg_format_1.default.ident(this.dbSchema)}.${pg_format_1.default.ident(this.tableName)} SET`;
const updateClauses = Object.entries(data).map(([key, value]) => {
const dbValue = (0, pg_format_1.literal)(this.formatValue(value));
return `${(0, pg_format_1.ident)(key)} = ${dbValue}`;
const dbValue = pg_format_1.default.literal(this.formatValue(value));
return `${pg_format_1.default.ident(key)} = ${dbValue}`;
});

@@ -286,3 +286,3 @@ query += ` ${updateClauses.join(', ')}`;

async deleteCommand(filters, useFilterGroups = false) {
let query = `DELETE FROM ${(0, pg_format_1.ident)(this.dbSchema)}.${(0, pg_format_1.ident)(this.tableName)}`;
let query = `DELETE FROM ${pg_format_1.default.ident(this.dbSchema)}.${pg_format_1.default.ident(this.tableName)}`;
if (filters) {

@@ -305,3 +305,3 @@ query += ' WHERE ';

filters, actions, options = {}) {
let query = `UPDATE ${(0, pg_format_1.ident)(this.dbSchema)}.${(0, pg_format_1.ident)(this.tableName)} SET`;
let query = `UPDATE ${pg_format_1.default.ident(this.dbSchema)}.${pg_format_1.default.ident(this.tableName)} SET`;
const set = actions.SET || [];

@@ -349,7 +349,7 @@ const add = actions.ADD || [];

case 'array':
formattedValue = (0, pg_format_1.literal)(value);
formattedValue = pg_format_1.default.literal(value);
expValue = `ARRAY[${formattedValue}]`;
break;
default:
formattedValue = (0, pg_format_1.literal)(value);
formattedValue = pg_format_1.default.literal(value);
expValue = formattedValue;

@@ -359,3 +359,3 @@ break;

this.crudSchema.columns;
updateClauses.push(`${(0, pg_format_1.ident)(path)} = ${expValue}`);
updateClauses.push(`${pg_format_1.default.ident(path)} = ${expValue}`);
}

@@ -382,6 +382,6 @@ });

const jsonExpr = this.buildJSONBExpression(queryFunction.value.jsonExpression, 'jsonb_insert');
updateClauses.push(`${(0, pg_format_1.ident)(queryFunction.path)} = ${jsonExpr}`);
updateClauses.push(`${pg_format_1.default.ident(queryFunction.path)} = ${jsonExpr}`);
}
else {
updateClauses.push(`${(0, pg_format_1.ident)(queryFunction.path)} = ${queryFunction.value}`);
updateClauses.push(`${pg_format_1.default.ident(queryFunction.path)} = ${queryFunction.value}`);
}

@@ -388,0 +388,0 @@ });

@@ -14,4 +14,4 @@ "use strict";

class PostgreSqlCrudService extends postgreSqlClient_service_1.default {
constructor(tableSchema) {
super(tableSchema);
constructor(tableSchema, poolClient) {
super(tableSchema, poolClient);
this.tableSchema = tableSchema;

@@ -56,11 +56,7 @@ }

const inputDataArray = data.map((item) => this.prepareData(item));
return this.createCommand(inputDataArray).then((result) => {
var _a, _b;
const items = ((_a = result === null || result === void 0 ? void 0 : result.rows) === null || _a === void 0 ? void 0 : _a.map((row) => this.getItem(row))) || [];
return {
total: (_b = result.rowCount) !== null && _b !== void 0 ? _b : 0,
items,
unprocessedItems: [],
};
});
return this.createCommand(inputDataArray).then((result) => ({
unprocessedItems: result
.filter((r) => !r.success)
.map((r) => r.inputData),
}));
}

@@ -67,0 +63,0 @@ else {

@@ -17,5 +17,3 @@ import * as pg from 'pg';

interface ICreateMultipleResponse {
unprocessedItems?: Record<string, any>;
total?: number;
items?: any[];
unprocessedItems: Record<string, any>;
}

@@ -22,0 +20,0 @@

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

"main": "dist/cjs/index.js",
"version": "0.5.0-bundled",
"version": "0.5.0",
"license": "MIT",

@@ -31,10 +31,24 @@ "exports": {

"publish-package-dev": "yarn prepare-publish && yarn publish-codeartifact",
"publish-package": "yarn prepare-publish && npm publish --tag beta"
"publish-package": "yarn prepare-publish && npm publish"
},
"dependencies": {
"peerDependencies": {
"@aws-sdk/client-dynamodb": "3.x",
"@aws-sdk/lib-dynamodb": "3.x",
"@scaleleap/pg-format": "^1.0.0",
"pg": "8.11.4"
"pg": "8.11.4",
"pg-format": "1.0.4"
},
"peerDependenciesMeta": {
"@aws-sdk/client-dynamodb": {
"optional": true
},
"@aws-sdk/lib-dynamodb": {
"optional": true
},
"pg": {
"optional": true
},
"pg-format": {
"optional": true
}
},
"devDependencies": {

@@ -41,0 +55,0 @@ "@types/jest": "29.5.5",

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