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

slonik

Package Overview
Dependencies
Maintainers
1
Versions
395
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slonik - npm Package Compare versions

Comparing version 14.14.1 to 14.14.2

30

dist/binders/bindPool.js

@@ -16,22 +16,4 @@ "use strict";

const getPoolId = log => {
const poolId = log.getContext().poolId;
if (typeof poolId !== 'string') {
throw new TypeError('Unexpected state.');
}
return poolId;
};
const bindPool = (parentLog, pool, clientConfiguration) => {
const poolId = getPoolId(parentLog);
const internalConnect = async (connectionRoutine, query = null) => {
if (!pool.typeParserSetupPromise) {
pool.typeParserSetupPromise = (0, _routines.setupTypeParsers)(pool, clientConfiguration.typeParsers);
}
await pool.typeParserSetupPromise;
for (const interceptor of clientConfiguration.interceptors) {

@@ -41,3 +23,3 @@ if (interceptor.beforePoolConnection) {

log: parentLog,
poolId,
poolId: pool.slonik.poolId,
query

@@ -53,2 +35,8 @@ });

const connection = await pool.connect();
if (!connection.connection.slonik.typeParserSetupPromise) {
connection.connection.slonik.typeParserSetupPromise = (0, _routines.setupTypeParsers)(connection, clientConfiguration.typeParsers);
}
await connection.connection.slonik.typeParserSetupPromise;
const connectionId = connection.connection.slonik.connectionId;

@@ -61,5 +49,5 @@ const connectionLog = parentLog.child({

log: connectionLog,
poolId
poolId: pool.slonik.poolId
};
const boundConnection = (0, _bindPoolConnection.default)(connectionLog, pool, connection, clientConfiguration);
const boundConnection = (0, _bindPoolConnection.default)(connectionLog, connection, clientConfiguration);

@@ -66,0 +54,0 @@ try {

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

const bindPoolConnection = (parentLog, pool, connection, clientConfiguration) => {
const bindPoolConnection = (parentLog, connection, clientConfiguration) => {
return {
any: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.any.bind(null, parentLog, pool, clientConfiguration)),
anyFirst: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.anyFirst.bind(null, parentLog, pool, clientConfiguration)),
many: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.many.bind(null, parentLog, pool, clientConfiguration)),
manyFirst: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.manyFirst.bind(null, parentLog, pool, clientConfiguration)),
maybeOne: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.maybeOne.bind(null, parentLog, pool, clientConfiguration)),
maybeOneFirst: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.maybeOneFirst.bind(null, parentLog, pool, clientConfiguration)),
one: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.one.bind(null, parentLog, pool, clientConfiguration)),
oneFirst: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.oneFirst.bind(null, parentLog, pool, clientConfiguration)),
query: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.query.bind(null, parentLog, pool, clientConfiguration)),
any: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.any.bind(null, parentLog, connection, clientConfiguration)),
anyFirst: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.anyFirst.bind(null, parentLog, connection, clientConfiguration)),
many: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.many.bind(null, parentLog, connection, clientConfiguration)),
manyFirst: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.manyFirst.bind(null, parentLog, connection, clientConfiguration)),
maybeOne: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.maybeOne.bind(null, parentLog, connection, clientConfiguration)),
maybeOneFirst: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.maybeOneFirst.bind(null, parentLog, connection, clientConfiguration)),
one: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.one.bind(null, parentLog, connection, clientConfiguration)),
oneFirst: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.oneFirst.bind(null, parentLog, connection, clientConfiguration)),
query: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.query.bind(null, parentLog, connection, clientConfiguration)),
transaction: async handler => {
return (0, _connectionMethods.transaction)(parentLog, pool, clientConfiguration, handler);
return (0, _connectionMethods.transaction)(parentLog, connection, clientConfiguration, handler);
}

@@ -27,0 +27,0 @@ };

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

return taggedQuery => {
if (transactionDepth !== connection.slonik.transactionDepth) {
if (transactionDepth !== connection.connection.slonik.transactionDepth) {
return Promise.reject(new Error('Cannot run a query using parent transaction.'));

@@ -19,0 +19,0 @@ }

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

try {
connection.slonik.transactionDepth = newTransactionDepth;
connection.connection.slonik.transactionDepth = newTransactionDepth;
const result = await handler((0, _binders.bindTransactionConnection)(log, connection, clientConfiguration, newTransactionDepth));

@@ -35,3 +35,3 @@ return result;

} finally {
connection.slonik.transactionDepth = newTransactionDepth - 1;
connection.connection.slonik.transactionDepth = newTransactionDepth - 1;
}

@@ -38,0 +38,0 @@ };

@@ -17,7 +17,7 @@ "use strict";

const transaction = async (parentLog, connection, clientConfiguration, handler) => {
if (connection.slonik.transactionDepth !== null) {
if (connection.connection.slonik.transactionDepth !== null) {
throw new Error('Cannot use the same connection to start a new transaction before completing the last transaction.');
}
connection.slonik.transactionDepth = 0;
connection.connection.slonik.transactionDepth = 0;
await connection.query('START TRANSACTION');

@@ -29,3 +29,3 @@ const log = parentLog.child({

try {
const result = await handler((0, _binders.bindTransactionConnection)(log, connection, clientConfiguration, connection.slonik.transactionDepth));
const result = await handler((0, _binders.bindTransactionConnection)(log, connection, clientConfiguration, connection.connection.slonik.transactionDepth));
await connection.query('COMMIT');

@@ -40,3 +40,3 @@ return result;

} finally {
connection.slonik.transactionDepth = null;
connection.connection.slonik.transactionDepth = null;
}

@@ -43,0 +43,0 @@ };

@@ -26,5 +26,6 @@ "use strict";

const clientConfiguration = (0, _createClientConfiguration.default)(clientUserConfiguration);
const poolId = (0, _utilities.createUlid)();
const poolLog = _Logger.default.child({
poolId: (0, _utilities.createUlid)()
poolId
});

@@ -34,3 +35,3 @@

pool.slonik = {
typeParserSetupPromise: null
poolId
};

@@ -44,3 +45,5 @@ pool.on('error', error => {

client.connection.slonik = {
connectionId: (0, _utilities.createUlid)()
connectionId: (0, _utilities.createUlid)(),
transactionDepth: null,
typeParserSetupPromise: null
};

@@ -47,0 +50,0 @@ client.on('notice', notice => {

@@ -8,14 +8,69 @@ "use strict";

var _routines = require("../routines");
var _connectionMethods = require("../connectionMethods");
var _binders = require("../binders");
const createPoolTransaction = async (parentLog, pool, clientConfiguration, handler) => {
parentLog.debug('allocating a new connection to execute the transaction');
const transactionConnection = await pool.connect();
for (const interceptor of clientConfiguration.interceptors) {
if (interceptor.beforePoolConnection) {
const maybeNewPool = await interceptor.beforePoolConnection({
log: parentLog,
poolId: pool.slonik.poolId,
query: null
});
if (maybeNewPool) {
return maybeNewPool.transaction(handler);
}
}
}
const connection = await pool.connect();
if (!connection.connection.slonik.typeParserSetupPromise) {
connection.connection.slonik.typeParserSetupPromise = (0, _routines.setupTypeParsers)(connection, clientConfiguration.typeParsers);
}
await connection.connection.slonik.typeParserSetupPromise;
const connectionId = connection.connection.slonik.connectionId;
const connectionLog = parentLog.child({
connectionId
});
const connectionContext = {
connectionId,
log: connectionLog,
poolId: pool.slonik.poolId
};
const boundConnection = (0, _binders.bindPoolConnection)(connectionLog, connection, clientConfiguration);
try {
for (const interceptor of clientConfiguration.interceptors) {
if (interceptor.afterPoolConnection) {
await interceptor.afterPoolConnection(connectionContext, boundConnection);
}
}
} catch (error) {
await connection.release();
throw error;
}
let result;
try {
result = await (0, _connectionMethods.transaction)(parentLog, transactionConnection, clientConfiguration, handler);
result = await (0, _connectionMethods.transaction)(connectionLog, connection, clientConfiguration, handler);
} catch (error) {
await connection.release();
throw error;
}
try {
for (const interceptor of clientConfiguration.interceptors) {
if (interceptor.beforePoolConnectionRelease) {
await interceptor.beforePoolConnectionRelease(connectionContext, boundConnection);
}
}
} finally {
parentLog.debug('releasing the connection that was earlier secured to execute a transaction');
await transactionConnection.release();
await connection.release();
}

@@ -22,0 +77,0 @@

@@ -98,3 +98,3 @@ {

},
"version": "14.14.1"
"version": "14.14.2"
}

@@ -19,12 +19,2 @@ // @flow

const getPoolId = (log: LoggerType): string => {
const poolId = log.getContext().poolId;
if (typeof poolId !== 'string') {
throw new TypeError('Unexpected state.');
}
return poolId;
};
export default (

@@ -35,11 +25,3 @@ parentLog: LoggerType,

): DatabasePoolType => {
const poolId = getPoolId(parentLog);
const internalConnect = async (connectionRoutine, query = null) => {
if (!pool.typeParserSetupPromise) {
pool.typeParserSetupPromise = setupTypeParsers(pool, clientConfiguration.typeParsers);
}
await pool.typeParserSetupPromise;
for (const interceptor of clientConfiguration.interceptors) {

@@ -49,3 +31,3 @@ if (interceptor.beforePoolConnection) {

log: parentLog,
poolId,
poolId: pool.slonik.poolId,
query

@@ -62,2 +44,8 @@ });

if (!connection.connection.slonik.typeParserSetupPromise) {
connection.connection.slonik.typeParserSetupPromise = setupTypeParsers(connection, clientConfiguration.typeParsers);
}
await connection.connection.slonik.typeParserSetupPromise;
const connectionId = connection.connection.slonik.connectionId;

@@ -72,6 +60,6 @@

log: connectionLog,
poolId
poolId: pool.slonik.poolId
};
const boundConnection = bindPoolConnection(connectionLog, pool, connection, clientConfiguration);
const boundConnection = bindPoolConnection(connectionLog, connection, clientConfiguration);

@@ -78,0 +66,0 @@ try {

@@ -11,3 +11,2 @@ // @flow

InternalDatabaseConnectionType,
InternalDatabasePoolType,
LoggerType

@@ -30,3 +29,2 @@ } from '../types';

parentLog: LoggerType,
pool: InternalDatabasePoolType,
connection: InternalDatabaseConnectionType,

@@ -36,15 +34,15 @@ clientConfiguration: ClientConfigurationType

return {
any: mapTaggedTemplateLiteralInvocation(any.bind(null, parentLog, pool, clientConfiguration)),
anyFirst: mapTaggedTemplateLiteralInvocation(anyFirst.bind(null, parentLog, pool, clientConfiguration)),
many: mapTaggedTemplateLiteralInvocation(many.bind(null, parentLog, pool, clientConfiguration)),
manyFirst: mapTaggedTemplateLiteralInvocation(manyFirst.bind(null, parentLog, pool, clientConfiguration)),
maybeOne: mapTaggedTemplateLiteralInvocation(maybeOne.bind(null, parentLog, pool, clientConfiguration)),
maybeOneFirst: mapTaggedTemplateLiteralInvocation(maybeOneFirst.bind(null, parentLog, pool, clientConfiguration)),
one: mapTaggedTemplateLiteralInvocation(one.bind(null, parentLog, pool, clientConfiguration)),
oneFirst: mapTaggedTemplateLiteralInvocation(oneFirst.bind(null, parentLog, pool, clientConfiguration)),
query: mapTaggedTemplateLiteralInvocation(query.bind(null, parentLog, pool, clientConfiguration)),
any: mapTaggedTemplateLiteralInvocation(any.bind(null, parentLog, connection, clientConfiguration)),
anyFirst: mapTaggedTemplateLiteralInvocation(anyFirst.bind(null, parentLog, connection, clientConfiguration)),
many: mapTaggedTemplateLiteralInvocation(many.bind(null, parentLog, connection, clientConfiguration)),
manyFirst: mapTaggedTemplateLiteralInvocation(manyFirst.bind(null, parentLog, connection, clientConfiguration)),
maybeOne: mapTaggedTemplateLiteralInvocation(maybeOne.bind(null, parentLog, connection, clientConfiguration)),
maybeOneFirst: mapTaggedTemplateLiteralInvocation(maybeOneFirst.bind(null, parentLog, connection, clientConfiguration)),
one: mapTaggedTemplateLiteralInvocation(one.bind(null, parentLog, connection, clientConfiguration)),
oneFirst: mapTaggedTemplateLiteralInvocation(oneFirst.bind(null, parentLog, connection, clientConfiguration)),
query: mapTaggedTemplateLiteralInvocation(query.bind(null, parentLog, connection, clientConfiguration)),
transaction: async (handler: TransactionFunctionType) => {
return transaction(parentLog, pool, clientConfiguration, handler);
return transaction(parentLog, connection, clientConfiguration, handler);
}
};
};

@@ -37,3 +37,3 @@ // @flow

return (taggedQuery: TaggedTemplateLiteralInvocationType) => {
if (transactionDepth !== connection.slonik.transactionDepth) {
if (transactionDepth !== connection.connection.slonik.transactionDepth) {
return Promise.reject(new Error('Cannot run a query using parent transaction.'));

@@ -40,0 +40,0 @@ }

@@ -24,3 +24,3 @@ // @flow

try {
connection.slonik.transactionDepth = newTransactionDepth;
connection.connection.slonik.transactionDepth = newTransactionDepth;

@@ -39,3 +39,3 @@ const result = await handler(bindTransactionConnection(log, connection, clientConfiguration, newTransactionDepth));

} finally {
connection.slonik.transactionDepth = newTransactionDepth - 1;
connection.connection.slonik.transactionDepth = newTransactionDepth - 1;
}

@@ -42,0 +42,0 @@ };

@@ -15,7 +15,7 @@ // @flow

const transaction: InternalTransactionFunctionType = async (parentLog, connection, clientConfiguration, handler) => {
if (connection.slonik.transactionDepth !== null) {
if (connection.connection.slonik.transactionDepth !== null) {
throw new Error('Cannot use the same connection to start a new transaction before completing the last transaction.');
}
connection.slonik.transactionDepth = 0;
connection.connection.slonik.transactionDepth = 0;

@@ -29,3 +29,3 @@ await connection.query('START TRANSACTION');

try {
const result = await handler(bindTransactionConnection(log, connection, clientConfiguration, connection.slonik.transactionDepth));
const result = await handler(bindTransactionConnection(log, connection, clientConfiguration, connection.connection.slonik.transactionDepth));

@@ -44,3 +44,3 @@ await connection.query('COMMIT');

} finally {
connection.slonik.transactionDepth = null;
connection.connection.slonik.transactionDepth = null;
}

@@ -47,0 +47,0 @@ };

@@ -27,4 +27,6 @@ // @flow

const poolId = createUlid();
const poolLog = Logger.child({
poolId: createUlid()
poolId
});

@@ -35,3 +37,3 @@

pool.slonik = {
typeParserSetupPromise: null
poolId
};

@@ -47,3 +49,5 @@

client.connection.slonik = {
connectionId: createUlid()
connectionId: createUlid(),
transactionDepth: null,
typeParserSetupPromise: null
};

@@ -50,0 +54,0 @@

@@ -11,4 +11,10 @@ // @flow

import {
setupTypeParsers
} from '../routines';
import {
transaction
} from '../connectionMethods';
import {
bindPoolConnection
} from '../binders';

@@ -21,17 +27,71 @@ export default async (

): Promise<*> => {
parentLog.debug('allocating a new connection to execute the transaction');
for (const interceptor of clientConfiguration.interceptors) {
if (interceptor.beforePoolConnection) {
const maybeNewPool = await interceptor.beforePoolConnection({
log: parentLog,
poolId: pool.slonik.poolId,
query: null
});
const transactionConnection: InternalDatabaseConnectionType = await pool.connect();
if (maybeNewPool) {
return maybeNewPool.transaction(handler);
}
}
}
const connection: InternalDatabaseConnectionType = await pool.connect();
if (!connection.connection.slonik.typeParserSetupPromise) {
connection.connection.slonik.typeParserSetupPromise = setupTypeParsers(connection, clientConfiguration.typeParsers);
}
await connection.connection.slonik.typeParserSetupPromise;
const connectionId = connection.connection.slonik.connectionId;
const connectionLog = parentLog.child({
connectionId
});
const connectionContext = {
connectionId,
log: connectionLog,
poolId: pool.slonik.poolId
};
const boundConnection = bindPoolConnection(connectionLog, connection, clientConfiguration);
try {
for (const interceptor of clientConfiguration.interceptors) {
if (interceptor.afterPoolConnection) {
await interceptor.afterPoolConnection(connectionContext, boundConnection);
}
}
} catch (error) {
await connection.release();
throw error;
}
let result;
try {
result = await transaction(parentLog, transactionConnection, clientConfiguration, handler);
} finally {
parentLog.debug('releasing the connection that was earlier secured to execute a transaction');
result = await transaction(connectionLog, connection, clientConfiguration, handler);
} catch (error) {
await connection.release();
await transactionConnection.release();
throw error;
}
try {
for (const interceptor of clientConfiguration.interceptors) {
if (interceptor.beforePoolConnectionRelease) {
await interceptor.beforePoolConnectionRelease(connectionContext, boundConnection);
}
}
} finally {
await connection.release();
}
return result;
};

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

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