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 5.2.0 to 5.3.0

23

dist/errors.js

@@ -6,3 +6,3 @@ 'use strict';

});
exports.UniqueViolationError = exports.DataIntegrityError = exports.NotFoundError = undefined;
exports.UniqueViolationError = exports.DataIntegrityError = exports.NotFoundError = exports.SlonikError = undefined;

@@ -15,5 +15,8 @@ var _es6Error = require('es6-error');

class NotFoundError extends _es6Error2.default {
constructor(message = 'Resource not found.') {
super(message);
class SlonikError extends _es6Error2.default {}
exports.SlonikError = SlonikError;
class NotFoundError extends SlonikError {
constructor() {
super('Resource not found.');
}

@@ -23,7 +26,15 @@ }

exports.NotFoundError = NotFoundError;
class DataIntegrityError extends _es6Error2.default {}
class DataIntegrityError extends SlonikError {
constructor() {
super('Query returns an unexpected result.');
}
}
exports.DataIntegrityError = DataIntegrityError;
class UniqueViolationError extends _es6Error2.default {}
class UniqueViolationError extends SlonikError {
constructor() {
super('Query violates a unique constraint.');
}
}
exports.UniqueViolationError = UniqueViolationError;
//# sourceMappingURL=errors.js.map

@@ -6,3 +6,3 @@ 'use strict';

});
exports.sql = exports.createPool = exports.createConnection = exports.transaction = exports.anyFirst = exports.any = exports.manyFirst = exports.many = exports.maybeOneFirst = exports.oneFirst = exports.maybeOne = exports.one = exports.query = exports.NotFoundError = exports.UniqueViolationError = exports.DataIntegrityError = undefined;
exports.sql = exports.createPool = exports.createConnection = exports.transaction = exports.anyFirst = exports.any = exports.manyFirst = exports.many = exports.maybeOneFirst = exports.oneFirst = exports.maybeOne = exports.one = exports.query = exports.NotFoundError = exports.SlonikError = exports.UniqueViolationError = exports.DataIntegrityError = undefined;

@@ -23,2 +23,4 @@ var _pg = require('pg');

var _ulid = require('ulid');
var _errors = require('./errors');

@@ -38,2 +40,3 @@

exports.UniqueViolationError = _errors.UniqueViolationError;
exports.SlonikError = _errors.SlonikError;
exports.NotFoundError = _errors.NotFoundError;

@@ -63,3 +66,5 @@

const query = exports.query = async (connection, rawSql, values) => {
const ulid = (0, _ulid.factory)((0, _ulid.detectPrng)(true));
const query = exports.query = async (connection, rawSql, values, queryId) => {
const strippedSql = (0, _utilities.stripComments)(rawSql);

@@ -95,4 +100,9 @@

} catch (error) {
log.error({
error: (0, _serializeError2.default)(error),
queryId
}, 'query produced an error');
if (error.code === '23505') {
throw new _errors.UniqueViolationError(error.message);
throw new _errors.UniqueViolationError();
}

@@ -107,2 +117,3 @@

executionTime: (0, _prettyHrtime2.default)(end),
queryId,
rowCount,

@@ -130,8 +141,12 @@ sql: strippedSql

*/
const one = exports.one = async (connection, clientConfiguration, rawSql, values) => {
const one = exports.one = async (connection, clientConfiguration, rawSql, values, queryId = ulid()) => {
const {
rows
} = await query(connection, rawSql, values);
} = await query(connection, rawSql, values, queryId);
if (rows.length === 0) {
log.error({
queryId
}, 'NotFoundError');
const ConfigurableNotFoundError = clientConfiguration.errors && clientConfiguration.errors.NotFoundError ? clientConfiguration.errors.NotFoundError : _errors.NotFoundError;

@@ -143,2 +158,6 @@

if (rows.length > 1) {
log.error({
queryId
}, 'DataIntegrityError');
throw new _errors.DataIntegrityError();

@@ -155,6 +174,6 @@ }

*/
const maybeOne = exports.maybeOne = async (connection, clientConfiguration, rawSql, values) => {
const maybeOne = exports.maybeOne = async (connection, clientConfiguration, rawSql, values, queryId = ulid()) => {
const {
rows
} = await query(connection, rawSql, values);
} = await query(connection, rawSql, values, queryId);

@@ -166,2 +185,6 @@ if (rows.length === 0) {

if (rows.length > 1) {
log.error({
queryId
}, 'DataIntegrityError');
throw new _errors.DataIntegrityError();

@@ -180,4 +203,4 @@ }

*/
const oneFirst = exports.oneFirst = async (connection, clientConfiguration, rawSql, values) => {
const row = await one(connection, clientConfiguration, rawSql, values);
const oneFirst = exports.oneFirst = async (connection, clientConfiguration, rawSql, values, queryId = ulid()) => {
const row = await one(connection, clientConfiguration, rawSql, values, queryId);

@@ -187,2 +210,6 @@ const keys = Object.keys(row);

if (keys.length !== 1) {
log.error({
queryId
}, 'DataIntegrityError');
throw new _errors.DataIntegrityError();

@@ -200,4 +227,4 @@ }

*/
const maybeOneFirst = exports.maybeOneFirst = async (connection, clientConfiguration, rawSql, values) => {
const row = await maybeOne(connection, clientConfiguration, rawSql, values);
const maybeOneFirst = exports.maybeOneFirst = async (connection, clientConfiguration, rawSql, values, queryId = ulid()) => {
const row = await maybeOne(connection, clientConfiguration, rawSql, values, queryId);

@@ -211,2 +238,6 @@ if (!row) {

if (keys.length !== 1) {
log.error({
queryId
}, 'DataIntegrityError');
throw new _errors.DataIntegrityError();

@@ -223,8 +254,12 @@ }

*/
const many = exports.many = async (connection, clientConfiguration, rawSql, values) => {
const many = exports.many = async (connection, clientConfiguration, rawSql, values, queryId = ulid()) => {
const {
rows
} = await query(connection, rawSql, values);
} = await query(connection, rawSql, values, queryId);
if (rows.length === 0) {
log.error({
queryId
}, 'NotFoundError');
const ConfigurableNotFoundError = clientConfiguration.errors && clientConfiguration.errors.NotFoundError ? clientConfiguration.errors.NotFoundError : _errors.NotFoundError;

@@ -238,6 +273,10 @@

const manyFirst = exports.manyFirst = async (connection, clientConfigurationType, rawSql, values) => {
const rows = await many(connection, clientConfigurationType, rawSql, values);
const manyFirst = exports.manyFirst = async (connection, clientConfigurationType, rawSql, values, queryId = ulid()) => {
const rows = await many(connection, clientConfigurationType, rawSql, values, queryId);
if (rows.length === 0) {
log.error({
queryId
}, 'DataIntegrityError');
throw new _errors.DataIntegrityError();

@@ -249,2 +288,6 @@ }

if (keys.length !== 1) {
log.error({
queryId
}, 'DataIntegrityError');
throw new _errors.DataIntegrityError();

@@ -256,2 +299,6 @@ }

if (typeof firstColumnName !== 'string') {
log.error({
queryId
}, 'DataIntegrityError');
throw new _errors.DataIntegrityError();

@@ -268,6 +315,6 @@ }

*/
const any = exports.any = async (connection, clientConfiguration, rawSql, values) => {
const any = exports.any = async (connection, clientConfiguration, rawSql, values, queryId = ulid()) => {
const {
rows
} = await query(connection, rawSql, values);
} = await query(connection, rawSql, values, queryId);

@@ -277,4 +324,4 @@ return rows;

const anyFirst = exports.anyFirst = async (connection, clientConfigurationType, rawSql, values) => {
const rows = await any(connection, clientConfigurationType, rawSql, values);
const anyFirst = exports.anyFirst = async (connection, clientConfigurationType, rawSql, values, queryId = ulid()) => {
const rows = await any(connection, clientConfigurationType, rawSql, values, queryId);

@@ -288,2 +335,6 @@ if (rows.length === 0) {

if (keys.length !== 1) {
log.error({
queryId
}, 'DataIntegrityError');
throw new _errors.DataIntegrityError();

@@ -295,2 +346,6 @@ }

if (typeof firstColumnName !== 'string') {
log.error({
queryId
}, 'DataIntegrityError');
throw new _errors.DataIntegrityError();

@@ -297,0 +352,0 @@ }

@@ -1,1 +0,1 @@

{"author":{"email":"gajus@gajus.com","name":"Gajus Kuizinas","url":"http://gajus.com"},"ava":{"babel":"inherit","require":["babel-register"]},"dependencies":{"ajv":"^5.3.0","array-flatten":"^2.1.1","boolean":"^0.1.3","es6-error":"^4.0.2","pg":"^7.4.0","pg-connection-string":"^2.0.0","pretty-hrtime":"^1.0.3","roarr":"^2.0.2","serialize-error":"^2.1.0"},"description":"A PostgreSQL client with strict types and assertions.","devDependencies":{"ava":"^0.23.0","babel-cli":"^6.26.0","babel-plugin-istanbul":"^4.1.5","babel-plugin-transform-flow-strip-types":"^6.22.0","babel-plugin-transform-object-rest-spread":"^6.26.0","babel-preset-env":"^1.6.1","babel-register":"^6.26.0","coveralls":"^3.0.0","eslint":"^4.10.0","eslint-config-canonical":"^9.3.1","flow-bin":"^0.58.0","flow-copy-source":"^1.2.1","husky":"^0.14.3","nyc":"^11.3.0","semantic-release":"^8.2.0","sinon":"^4.1.2"},"engines":{"node":">=8.0"},"keywords":["postgresql","promise","types"],"license":"BSD-3-Clause","main":"./dist/index.js","name":"slonik","nyc":{"include":["src/**/*.js"],"instrument":false,"reporter":["text-lcov"],"require":["babel-register"],"sourceMap":false},"repository":{"type":"git","url":"https://github.com/gajus/slonik"},"scripts":{"build":"rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps && flow-copy-source src dist","lint":"eslint ./src ./test && flow","precommit":"npm run lint && npm run test","test":"ava --verbose"},"version":"5.2.0"}
{"author":{"email":"gajus@gajus.com","name":"Gajus Kuizinas","url":"http://gajus.com"},"ava":{"babel":"inherit","require":["babel-register"]},"dependencies":{"ajv":"^5.3.0","array-flatten":"^2.1.1","boolean":"^0.1.3","es6-error":"^4.0.2","pg":"^7.4.0","pg-connection-string":"^2.0.0","pretty-hrtime":"^1.0.3","roarr":"^2.0.2","serialize-error":"^2.1.0","ulid":"^2.3.0"},"description":"A PostgreSQL client with strict types, detail logging and assertions.","devDependencies":{"ava":"^0.23.0","babel-cli":"^6.26.0","babel-plugin-istanbul":"^4.1.5","babel-plugin-transform-flow-strip-types":"^6.22.0","babel-plugin-transform-object-rest-spread":"^6.26.0","babel-preset-env":"^1.6.1","babel-register":"^6.26.0","coveralls":"^3.0.0","eslint":"^4.10.0","eslint-config-canonical":"^9.3.1","flow-bin":"^0.58.0","flow-copy-source":"^1.2.1","husky":"^0.14.3","nyc":"^11.3.0","semantic-release":"^8.2.0","sinon":"^4.1.2"},"engines":{"node":">=8.0"},"keywords":["postgresql","promise","types"],"license":"BSD-3-Clause","main":"./dist/index.js","name":"slonik","nyc":{"include":["src/**/*.js"],"instrument":false,"reporter":["text-lcov"],"require":["babel-register"],"sourceMap":false},"repository":{"type":"git","url":"https://github.com/gajus/slonik"},"scripts":{"build":"rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps && flow-copy-source src dist","lint":"eslint ./src ./test && flow","precommit":"npm run lint && npm run test","test":"ava --verbose"},"version":"5.3.0"}

@@ -9,3 +9,3 @@ # Slonik

A PostgreSQL client with strict types and assertions.
A PostgreSQL client with strict types, detail logging and assertions.

@@ -411,2 +411,19 @@ * [Usage](#usage)

All Slonik errors extend from `SlonikError`, i.e. You can catch Slonik specific errors using the following logic.
```js
import {
SlonikError
} from 'slonik';
try {
await query();
} catch (error) {
if (error instanceof SlonikError) {
// This error is thrown by Slonik.
}
}
```
### Handling `NotFoundError`

@@ -413,0 +430,0 @@

@@ -5,10 +5,20 @@ // @flow

export class NotFoundError extends ExtendableError {
constructor (message: string = 'Resource not found.') {
super(message);
export class SlonikError extends ExtendableError {}
export class NotFoundError extends SlonikError {
constructor () {
super('Resource not found.');
}
}
export class DataIntegrityError extends ExtendableError {}
export class DataIntegrityError extends SlonikError {
constructor () {
super('Query returns an unexpected result.');
}
}
export class UniqueViolationError extends ExtendableError {}
export class UniqueViolationError extends SlonikError {
constructor () {
super('Query violates a unique constraint.');
}
}

@@ -12,5 +12,10 @@ // @flow

import {
factory as ulidFactory,
detectPrng
} from 'ulid';
import {
DataIntegrityError,
UniqueViolationError,
NotFoundError
NotFoundError,
SlonikError,
UniqueViolationError
} from './errors';

@@ -57,2 +62,3 @@ import {

UniqueViolationError,
SlonikError,
NotFoundError

@@ -82,3 +88,5 @@ };

export const query: InternalQueryType<*> = async (connection, rawSql, values) => {
const ulid = ulidFactory(detectPrng(true));
export const query: InternalQueryType<*> = async (connection, rawSql, values, queryId) => {
const strippedSql = stripComments(rawSql);

@@ -114,4 +122,9 @@

} catch (error) {
log.error({
error: serializeError(error),
queryId
}, 'query produced an error');
if (error.code === '23505') {
throw new UniqueViolationError(error.message);
throw new UniqueViolationError();
}

@@ -126,2 +139,3 @@

executionTime: prettyHrtime(end),
queryId,
rowCount,

@@ -149,8 +163,12 @@ sql: strippedSql

*/
export const one: InternalQueryOneType = async (connection, clientConfiguration, rawSql, values) => {
export const one: InternalQueryOneType = async (connection, clientConfiguration, rawSql, values, queryId = ulid()) => {
const {
rows
} = await query(connection, rawSql, values);
} = await query(connection, rawSql, values, queryId);
if (rows.length === 0) {
log.error({
queryId
}, 'NotFoundError');
const ConfigurableNotFoundError = clientConfiguration.errors && clientConfiguration.errors.NotFoundError ? clientConfiguration.errors.NotFoundError : NotFoundError;

@@ -162,2 +180,6 @@

if (rows.length > 1) {
log.error({
queryId
}, 'DataIntegrityError');
throw new DataIntegrityError();

@@ -174,6 +196,6 @@ }

*/
export const maybeOne: InternalQueryMaybeOneType = async (connection, clientConfiguration, rawSql, values) => {
export const maybeOne: InternalQueryMaybeOneType = async (connection, clientConfiguration, rawSql, values, queryId = ulid()) => {
const {
rows
} = await query(connection, rawSql, values);
} = await query(connection, rawSql, values, queryId);

@@ -185,2 +207,6 @@ if (rows.length === 0) {

if (rows.length > 1) {
log.error({
queryId
}, 'DataIntegrityError');
throw new DataIntegrityError();

@@ -199,4 +225,4 @@ }

*/
export const oneFirst: InternalQueryOneFirstType = async (connection, clientConfiguration, rawSql, values) => {
const row = await one(connection, clientConfiguration, rawSql, values);
export const oneFirst: InternalQueryOneFirstType = async (connection, clientConfiguration, rawSql, values, queryId = ulid()) => {
const row = await one(connection, clientConfiguration, rawSql, values, queryId);

@@ -206,2 +232,6 @@ const keys = Object.keys(row);

if (keys.length !== 1) {
log.error({
queryId
}, 'DataIntegrityError');
throw new DataIntegrityError();

@@ -219,4 +249,4 @@ }

*/
export const maybeOneFirst: InternalQueryMaybeOneFirstType = async (connection, clientConfiguration, rawSql, values) => {
const row = await maybeOne(connection, clientConfiguration, rawSql, values);
export const maybeOneFirst: InternalQueryMaybeOneFirstType = async (connection, clientConfiguration, rawSql, values, queryId = ulid()) => {
const row = await maybeOne(connection, clientConfiguration, rawSql, values, queryId);

@@ -230,2 +260,6 @@ if (!row) {

if (keys.length !== 1) {
log.error({
queryId
}, 'DataIntegrityError');
throw new DataIntegrityError();

@@ -242,8 +276,12 @@ }

*/
export const many: InternalQueryManyType = async (connection, clientConfiguration, rawSql, values) => {
export const many: InternalQueryManyType = async (connection, clientConfiguration, rawSql, values, queryId = ulid()) => {
const {
rows
} = await query(connection, rawSql, values);
} = await query(connection, rawSql, values, queryId);
if (rows.length === 0) {
log.error({
queryId
}, 'NotFoundError');
const ConfigurableNotFoundError = clientConfiguration.errors && clientConfiguration.errors.NotFoundError ? clientConfiguration.errors.NotFoundError : NotFoundError;

@@ -257,6 +295,10 @@

export const manyFirst: InternalQueryManyFirstType = async (connection, clientConfigurationType, rawSql, values) => {
const rows = await many(connection, clientConfigurationType, rawSql, values);
export const manyFirst: InternalQueryManyFirstType = async (connection, clientConfigurationType, rawSql, values, queryId = ulid()) => {
const rows = await many(connection, clientConfigurationType, rawSql, values, queryId);
if (rows.length === 0) {
log.error({
queryId
}, 'DataIntegrityError');
throw new DataIntegrityError();

@@ -268,2 +310,6 @@ }

if (keys.length !== 1) {
log.error({
queryId
}, 'DataIntegrityError');
throw new DataIntegrityError();

@@ -275,2 +321,6 @@ }

if (typeof firstColumnName !== 'string') {
log.error({
queryId
}, 'DataIntegrityError');
throw new DataIntegrityError();

@@ -287,6 +337,6 @@ }

*/
export const any: InternalQueryAnyType = async (connection, clientConfiguration, rawSql, values) => {
export const any: InternalQueryAnyType = async (connection, clientConfiguration, rawSql, values, queryId = ulid()) => {
const {
rows
} = await query(connection, rawSql, values);
} = await query(connection, rawSql, values, queryId);

@@ -296,4 +346,4 @@ return rows;

export const anyFirst: InternalQueryAnyFirstType = async (connection, clientConfigurationType, rawSql, values) => {
const rows = await any(connection, clientConfigurationType, rawSql, values);
export const anyFirst: InternalQueryAnyFirstType = async (connection, clientConfigurationType, rawSql, values, queryId = ulid()) => {
const rows = await any(connection, clientConfigurationType, rawSql, values, queryId);

@@ -307,2 +357,6 @@ if (rows.length === 0) {

if (keys.length !== 1) {
log.error({
queryId
}, 'DataIntegrityError');
throw new DataIntegrityError();

@@ -314,2 +368,6 @@ }

if (typeof firstColumnName !== 'string') {
log.error({
queryId
}, 'DataIntegrityError');
throw new DataIntegrityError();

@@ -316,0 +374,0 @@ }

@@ -113,3 +113,4 @@ // @flow

sql: string,
values?: DatabaseQueryValuesType
values?: DatabaseQueryValuesType,
queryId?: string
) => Promise<$ReadOnlyArray<QueryResultRowType>>;

@@ -121,3 +122,4 @@

sql: string,
values?: DatabaseQueryValuesType
values?: DatabaseQueryValuesType,
queryId?: string
) => Promise<$ReadOnlyArray<QueryResultRowColumnType>>;

@@ -129,3 +131,4 @@

sql: string,
values?: DatabaseQueryValuesType
values?: DatabaseQueryValuesType,
queryId?: string
) => Promise<$ReadOnlyArray<QueryResultRowType>>;

@@ -137,3 +140,4 @@

sql: string,
values?: DatabaseQueryValuesType
values?: DatabaseQueryValuesType,
queryId?: string
) => Promise<$ReadOnlyArray<QueryResultRowColumnType>>;

@@ -145,3 +149,4 @@

sql: string,
values?: DatabaseQueryValuesType
values?: DatabaseQueryValuesType,
queryId?: string
) => Promise<QueryResultRowColumnType | null>;

@@ -153,3 +158,4 @@

sql: string,
values?: DatabaseQueryValuesType
values?: DatabaseQueryValuesType,
queryId?: string
) => Promise<QueryResultRowType | null>;

@@ -161,3 +167,4 @@

sql: string,
values?: DatabaseQueryValuesType
values?: DatabaseQueryValuesType,
queryId?: string
) => Promise<QueryResultRowColumnType>;

@@ -169,3 +176,4 @@

sql: string,
values?: DatabaseQueryValuesType
values?: DatabaseQueryValuesType,
queryId?: string
) => Promise<QueryResultRowType>;

@@ -177,3 +185,3 @@

export type InternalQueryType<T: QueryResultRowType> = (connection: InternalDatabaseConnectionType, sql: string, values?: DatabaseQueryValuesType) => Promise<QueryResultType<T>>;
export type InternalQueryType<T: QueryResultRowType> = (connection: InternalDatabaseConnectionType, sql: string, values?: DatabaseQueryValuesType, queryId?: string) => Promise<QueryResultType<T>>;

@@ -180,0 +188,0 @@ export type QueryAnyFirstType<T: QueryResultRowColumnType> = (sql: string | TaggledTemplateLiteralInvocationType, values?: DatabaseQueryValuesType) => Promise<$ReadOnlyArray<T>>;

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