Socket
Socket
Sign inDemoInstall

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.7.1 to 14.8.0

92

dist/binders/bindPool.js

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

var _connectionMethods = require("../connectionMethods");
var _utilities = require("../utilities");
var _factories = require("../factories");

@@ -30,48 +26,62 @@

const bindPool = (parentLog, pool, clientConfiguration) => {
return {
any: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.any.bind(null, parentLog, pool, clientConfiguration)),
anyFirst: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.anyFirst.bind(null, parentLog, pool, clientConfiguration)),
connect: async connectionRoutine => {
const connection = await pool.connect();
const poolId = getPoolId(parentLog);
const connectionId = (0, _utilities.createUlid)();
const connectionLog = parentLog.child({
connectionId
});
const connectionContext = {
connectionId,
log: connectionLog,
poolId
};
const boundConnection = (0, _bindPoolConnection.default)(connectionLog, pool, connection, clientConfiguration);
const connect = async connectionRoutine => {
const connection = await pool.connect();
const poolId = getPoolId(parentLog);
const connectionId = connection.connection.slonik.connectionId;
const connectionLog = parentLog.child({
connectionId
});
const connectionContext = {
connectionId,
log: connectionLog,
poolId
};
const boundConnection = (0, _bindPoolConnection.default)(connectionLog, pool, connection, clientConfiguration);
for (const interceptor of clientConfiguration.interceptors) {
if (interceptor.afterPoolConnection) {
await interceptor.afterPoolConnection(connectionContext, boundConnection);
}
}
let result;
try {
result = await connectionRoutine(boundConnection);
} finally {
for (const interceptor of clientConfiguration.interceptors) {
if (interceptor.afterPoolConnection) {
await interceptor.afterPoolConnection(connectionContext, boundConnection);
if (interceptor.beforePoolConnectionRelease) {
await interceptor.beforePoolConnectionRelease(connectionContext, boundConnection);
}
}
let result;
await connection.release();
}
try {
result = await connectionRoutine(boundConnection);
} finally {
for (const interceptor of clientConfiguration.interceptors) {
if (interceptor.beforePoolConnectionRelease) {
await interceptor.beforePoolConnectionRelease(connectionContext, boundConnection);
}
}
return result;
};
await connection.release();
const mapConnection = targetMethodName => {
return query => {
if (typeof query === 'string') {
throw new TypeError('Query must be constructed using `sql` tagged template literal.');
}
return result;
},
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)),
return connect(connection => {
return connection[targetMethodName](query);
});
};
};
return {
any: mapConnection('any'),
anyFirst: mapConnection('anyFirst'),
connect,
many: mapConnection('many'),
manyFirst: mapConnection('manyFirst'),
maybeOne: mapConnection('maybeOne'),
maybeOneFirst: mapConnection('maybeOneFirst'),
one: mapConnection('one'),
oneFirst: mapConnection('oneFirst'),
query: mapConnection('query'),
transaction: async handler => {

@@ -78,0 +88,0 @@ return (0, _factories.createPoolTransaction)(parentLog, pool, clientConfiguration, handler);

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

const getTransactionId = log => {
const poolId = log.getContext().transactionId;
const transactionId = log.getContext().transactionId;
if (typeof poolId !== 'string' && typeof poolId !== 'undefined') {
if (typeof transactionId !== 'string' && typeof transactionId !== 'undefined') {
throw new TypeError('Unexpected state.');
}
return poolId;
return transactionId;
};

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

@@ -38,2 +38,5 @@ "use strict";

pool.on('connect', client => {
client.connection.slonik = {
connectionId: (0, _utilities.createUlid)()
};
client.on('notice', notice => {

@@ -40,0 +43,0 @@ poolLog.info({

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

stackTrace = context.stackTrace.filter(callSite => {
// Hide internal call sites.
// Hide the internal call sites.
return callSite.fileName !== null && !callSite.fileName.includes('slonik') && !callSite.fileName.includes('next_tick');

@@ -43,0 +43,0 @@ }).map(callSite => {

@@ -97,3 +97,3 @@ {

},
"version": "14.7.1"
"version": "14.8.0"
}

@@ -8,20 +8,6 @@ // @flow

InternalDatabasePoolType,
LoggerType
LoggerType,
TaggedTemplateLiteralInvocationType
} from '../types';
import {
any,
anyFirst,
many,
manyFirst,
maybeOne,
maybeOneFirst,
one,
oneFirst,
query
} from '../connectionMethods';
import {
createUlid,
mapTaggedTemplateLiteralInvocation
} from '../utilities';
import {
createPoolTransaction

@@ -46,53 +32,67 @@ } from '../factories';

): DatabasePoolType => {
return {
any: mapTaggedTemplateLiteralInvocation(any.bind(null, parentLog, pool, clientConfiguration)),
anyFirst: mapTaggedTemplateLiteralInvocation(anyFirst.bind(null, parentLog, pool, clientConfiguration)),
connect: async (connectionRoutine) => {
const connection: InternalDatabaseConnectionType = await pool.connect();
const connect = async (connectionRoutine) => {
const connection: InternalDatabaseConnectionType = await pool.connect();
const poolId = getPoolId(parentLog);
const poolId = getPoolId(parentLog);
const connectionId = createUlid();
const connectionId = connection.connection.slonik.connectionId;
const connectionLog = parentLog.child({
connectionId
});
const connectionLog = parentLog.child({
connectionId
});
const connectionContext = {
connectionId,
log: connectionLog,
poolId
};
const connectionContext = {
connectionId,
log: connectionLog,
poolId
};
const boundConnection = bindPoolConnection(connectionLog, pool, connection, clientConfiguration);
const boundConnection = bindPoolConnection(connectionLog, pool, connection, clientConfiguration);
for (const interceptor of clientConfiguration.interceptors) {
if (interceptor.afterPoolConnection) {
await interceptor.afterPoolConnection(connectionContext, boundConnection);
}
}
let result;
try {
result = await connectionRoutine(boundConnection);
} finally {
for (const interceptor of clientConfiguration.interceptors) {
if (interceptor.afterPoolConnection) {
await interceptor.afterPoolConnection(connectionContext, boundConnection);
if (interceptor.beforePoolConnectionRelease) {
await interceptor.beforePoolConnectionRelease(connectionContext, boundConnection);
}
}
let result;
await connection.release();
}
try {
result = await connectionRoutine(boundConnection);
} finally {
for (const interceptor of clientConfiguration.interceptors) {
if (interceptor.beforePoolConnectionRelease) {
await interceptor.beforePoolConnectionRelease(connectionContext, boundConnection);
}
}
return result;
};
await connection.release();
const mapConnection = (targetMethodName: string) => {
return (query: TaggedTemplateLiteralInvocationType) => {
if (typeof query === 'string') {
throw new TypeError('Query must be constructed using `sql` tagged template literal.');
}
return result;
},
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)),
return connect((connection) => {
return connection[targetMethodName](query);
});
};
};
return {
any: mapConnection('any'),
anyFirst: mapConnection('anyFirst'),
connect,
many: mapConnection('many'),
manyFirst: mapConnection('manyFirst'),
maybeOne: mapConnection('maybeOne'),
maybeOneFirst: mapConnection('maybeOneFirst'),
one: mapConnection('one'),
oneFirst: mapConnection('oneFirst'),
query: mapConnection('query'),
transaction: async (handler) => {

@@ -99,0 +99,0 @@ return createPoolTransaction(parentLog, pool, clientConfiguration, handler);

@@ -46,9 +46,9 @@ // @flow

const getTransactionId = (log: LoggerType): string | void => {
const poolId = log.getContext().transactionId;
const transactionId = log.getContext().transactionId;
if (typeof poolId !== 'string' && typeof poolId !== 'undefined') {
if (typeof transactionId !== 'string' && typeof transactionId !== 'undefined') {
throw new TypeError('Unexpected state.');
}
return poolId;
return transactionId;
};

@@ -55,0 +55,0 @@

@@ -40,2 +40,6 @@ // @flow

pool.on('connect', (client) => {
client.connection.slonik = {
connectionId: createUlid()
};
client.on('notice', (notice) => {

@@ -42,0 +46,0 @@ poolLog.info({

@@ -39,3 +39,3 @@ // @flow

.filter((callSite) => {
// Hide internal call sites.
// Hide the internal call sites.
return callSite.fileName !== null && !callSite.fileName.includes('slonik') && !callSite.fileName.includes('next_tick');

@@ -42,0 +42,0 @@ })

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