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 11.1.0 to 11.2.0

18

dist/binders/bindPool.js

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

const connection = await pool.connect();
const bindedConnection = (0, _bindPoolConnection.default)(parentLog, pool, connection, clientConfiguration);
const boundConnection = (0, _bindPoolConnection.default)(parentLog, pool, connection, clientConfiguration);
if (clientConfiguration.onConnect) {
await clientConfiguration.onConnect(bindedConnection);
await clientConfiguration.onConnect(boundConnection);
}

@@ -34,9 +34,15 @@

try {
result = await connectionRoutine(bindedConnection);
} catch (error) {
result = await connectionRoutine(boundConnection);
} finally {
const interceptors = clientConfiguration && clientConfiguration.interceptors || [];
for (const interceptor of interceptors) {
if (interceptor.beforePoolConnectionRelease) {
await interceptor.beforePoolConnectionRelease(boundConnection);
}
}
await connection.release();
throw error;
}
await connection.release();
return result;

@@ -43,0 +49,0 @@ },

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

let ended = false;
const bindConnection = {
const boundConnection = {
any: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.any.bind(null, parentLog, connection, clientConfiguration)),

@@ -23,2 +23,10 @@ anyFirst: (0, _utilities.mapTaggedTemplateLiteralInvocation)(_connectionMethods.anyFirst.bind(null, parentLog, connection, clientConfiguration)),

const interceptors = clientConfiguration && clientConfiguration.interceptors || [];
for (const interceptor of interceptors) {
if (interceptor.beforeConnectionEnd) {
await interceptor.beforeConnectionEnd(boundConnection);
}
}
await connection.release();

@@ -39,3 +47,3 @@ ended = pool.end();

};
return bindConnection;
return boundConnection;
};

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

@@ -95,3 +95,3 @@ {

},
"version": "11.1.0"
"version": "11.2.0"
}

@@ -43,2 +43,4 @@ <a name="slonik"></a>

* [`beforeQuery`](#slonik-interceptors-beforequery)
* [`beforeConnectionEnd`](#slonik-interceptors-beforeconnectionend)
* [`beforePoolConnectionRelease`](#slonik-interceptors-beforepoolconnectionrelease)
* [`afterQuery`](#slonik-interceptors-afterquery)

@@ -218,4 +220,6 @@ * [Built-in interceptors](#slonik-built-in-interceptors)

type InterceptorType = {|
+beforeQuery?: (query: QueryType) => Promise<QueryResultType<QueryResultRowType>> | QueryResultType<QueryResultRowType> | MaybePromiseType<void>,
+afterQuery?: (query: QueryType, result: QueryResultType<QueryResultRowType>) => MaybePromiseType<QueryResultType<QueryResultRowType>>
+afterQuery?: (query: QueryType, result: QueryResultType<QueryResultRowType>) => MaybePromiseType<QueryResultType<QueryResultRowType>>,
+beforeConnectionEnd?: (connection: DatabaseSingleConnectionType) => MaybePromiseType<void>,
+beforePoolConnectionRelease?: (connection: DatabasePoolConnectionType) => MaybePromiseType<void>,
+beforeQuery?: (query: QueryType) => Promise<QueryResultType<QueryResultRowType>> | QueryResultType<QueryResultRowType> | MaybePromiseType<void>
|};

@@ -242,4 +246,6 @@

* beforeQuery
* afterQuery
* `beforeQuery`
* `beforeConnectionEnd`
* `beforePoolConnectionRelease`
* `afterQuery`

@@ -251,10 +257,39 @@ Interceptors are executed in the order they are added.

`beforeQuery` is the first interceptor function executed.
`beforeQuery` is the first interceptor function executed in the query execution cycle.
This function can optionally return a direct result of the query which will cause the actual query never to be executed.
<a name="slonik-interceptors-beforeconnectionend"></a>
### <code>beforeConnectionEnd</code>
`beforeConnectionEnd` is executed before a connection is explicitly ended, e.g.
```js
const connection = await createConnection('postgres://');
// Interceptor is executed here. ↓
connection.end();
```
<a name="slonik-interceptors-beforepoolconnectionrelease"></a>
### <code>beforePoolConnectionRelease</code>
`beforePoolConnectionRelease` is executed before connection is released back to the connection pool, e.g.
```js
const pool = await createPool('postgres://');
pool.connect(async () => {
await 1;
// Interceptor is executed here. ↓
});
```
<a name="slonik-interceptors-afterquery"></a>
### <code>afterQuery</code>
`afterQuery` is the last interceptor function executed.
`afterQuery` is the last interceptor function executed in the query execution cycle.

@@ -261,0 +296,0 @@ This function must return the result of the query, which will be passed down to the client.

@@ -38,6 +38,6 @@ // @flow

const bindedConnection = bindPoolConnection(parentLog, pool, connection, clientConfiguration);
const boundConnection = bindPoolConnection(parentLog, pool, connection, clientConfiguration);
if (clientConfiguration.onConnect) {
await clientConfiguration.onConnect(bindedConnection);
await clientConfiguration.onConnect(boundConnection);
}

@@ -48,11 +48,15 @@

try {
result = await connectionRoutine(bindedConnection);
} catch (error) {
result = await connectionRoutine(boundConnection);
} finally {
const interceptors = clientConfiguration && clientConfiguration.interceptors || [];
for (const interceptor of interceptors) {
if (interceptor.beforePoolConnectionRelease) {
await interceptor.beforePoolConnectionRelease(boundConnection);
}
}
await connection.release();
throw error;
}
await connection.release();
return result;

@@ -59,0 +63,0 @@ },

@@ -34,3 +34,3 @@ // @flow

const bindConnection = {
const boundConnection = {
any: mapTaggedTemplateLiteralInvocation(any.bind(null, parentLog, connection, clientConfiguration)),

@@ -43,2 +43,10 @@ anyFirst: mapTaggedTemplateLiteralInvocation(anyFirst.bind(null, parentLog, connection, clientConfiguration)),

const interceptors = clientConfiguration && clientConfiguration.interceptors || [];
for (const interceptor of interceptors) {
if (interceptor.beforeConnectionEnd) {
await interceptor.beforeConnectionEnd(boundConnection);
}
}
await connection.release();

@@ -62,3 +70,3 @@

return bindConnection;
return boundConnection;
};

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

export type InterceptorType = {|
+beforeQuery?: (query: QueryType) => Promise<QueryResultType<QueryResultRowType>> | QueryResultType<QueryResultRowType> | MaybePromiseType<void>,
+afterQuery?: (query: QueryType, result: QueryResultType<QueryResultRowType>) => MaybePromiseType<QueryResultType<QueryResultRowType>>
+afterQuery?: (query: QueryType, result: QueryResultType<QueryResultRowType>) => MaybePromiseType<QueryResultType<QueryResultRowType>>,
+beforeConnectionEnd?: (connection: DatabaseSingleConnectionType) => MaybePromiseType<void>,
+beforePoolConnectionRelease?: (connection: DatabasePoolConnectionType) => MaybePromiseType<void>,
+beforeQuery?: (query: QueryType) => Promise<QueryResultType<QueryResultRowType>> | QueryResultType<QueryResultRowType> | MaybePromiseType<void>
|};

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