Skip to content

Commit

Permalink
refactor string styles
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Mar 17, 2023
1 parent 612579b commit 156c850
Show file tree
Hide file tree
Showing 61 changed files with 3,070 additions and 3,115 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
],
"quotes": [
"error",
"backtick"
"single"
],
"semi": [
"error",
Expand Down
2 changes: 1 addition & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {assertOptions} = require(`assert-options`);
const {assertOptions} = require('assert-options');

// this to allow override options-related errors globally (for pg-promise)
global.pgPromiseAssert = assertOptions;
Expand Down
34 changes: 17 additions & 17 deletions lib/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
* Removal or modification of this copyright notice is prohibited.
*/

const {Events} = require(`./events`);
const {ColorConsole} = require(`./utils/color`);
const {Events} = require('./events');
const {ColorConsole} = require('./utils/color');

const npm = {
utils: require(`./utils`),
text: require(`./text`),
formatting: require(`./formatting`)
utils: require('./utils'),
text: require('./text'),
formatting: require('./formatting')
};

function poolConnect(ctx, db, config) {
Expand All @@ -36,7 +36,7 @@ function poolConnect(ctx, db, config) {
});
reject(err);
} else {
if (`$useCount` in client) {
if ('$useCount' in client) {
// Make sure useCount drops to 1, if it ever reaches maximum integer number;
// We do not drop it to zero, to avoid rerun of initialization queries that
// usually check for useCount === 0;
Expand All @@ -47,7 +47,7 @@ function poolConnect(ctx, db, config) {
client.$useCount = ++client.$useCount;
}
} else {
Object.defineProperty(client, `$useCount`, {
Object.defineProperty(client, '$useCount', {
value: 0,
configurable: false,
enumerable: false,
Expand All @@ -57,15 +57,15 @@ function poolConnect(ctx, db, config) {
}
setCtx(client, ctx);
const end = lockClientEnd(client);
client.on(`error`, onError);
client.on('error', onError);
resolve({
client,
useCount: client.$useCount,
release(kill) {
client.end = end;
client.release(kill || client.$connectionError);
Events.disconnect(ctx, client);
client.removeListener(`error`, onError);
client.removeListener('error', onError);
}
});
Events.connect(ctx, client, client.$useCount);
Expand All @@ -88,15 +88,15 @@ function directConnect(ctx, config) {
setSchema(client, ctx);
setCtx(client, ctx);
const end = lockClientEnd(client);
client.on(`error`, onError);
client.on('error', onError);
resolve({
client,
useCount: 0,
release() {
client.end = end;
const p = config.promise((res, rej) => client.end().then(res).catch(rej));
Events.disconnect(ctx, client);
client.removeListener(`error`, onError);
client.removeListener('error', onError);
return p;
}
});
Expand All @@ -113,7 +113,7 @@ function onError(err) {
const ctx = this.$ctx;
const cn = npm.utils.getSafeConnection(ctx.cn);
Events.error(ctx.options, err, {cn, dc: ctx.dc});
if (ctx.cnOptions && typeof ctx.cnOptions.onLost === `function` && !ctx.notified) {
if (ctx.cnOptions && typeof ctx.cnOptions.onLost === 'function' && !ctx.notified) {
try {
ctx.cnOptions.onLost.call(this, err, {
cn,
Expand Down Expand Up @@ -143,7 +143,7 @@ function lockClientEnd(client) {
}

function setCtx(client, ctx) {
Object.defineProperty(client, `$ctx`, {
Object.defineProperty(client, '$ctx', {
value: ctx,
writable: true
});
Expand All @@ -154,14 +154,14 @@ function setSchema(client, ctx) {
if (!s) {
return;
}
if (typeof s === `function`) {
if (typeof s === 'function') {
s = s.call(ctx.dc, ctx.dc);
}
if (Array.isArray(s)) {
s = s.filter(a => a && typeof a === `string`);
s = s.filter(a => a && typeof a === 'string');
}
if (typeof s === `string` || (Array.isArray(s) && s.length)) {
client.query(npm.formatting.as.format(`SET search_path TO $1:name`, [s]), err => {
if (typeof s === 'string' || (Array.isArray(s) && s.length)) {
client.query(npm.formatting.as.format('SET search_path TO $1:name', [s]), err => {
// istanbul ignore if;
if (err) {
// This is unlikely to ever happen, unless the connection is created faulty,
Expand Down
10 changes: 5 additions & 5 deletions lib/database-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
* Removal or modification of this copyright notice is prohibited.
*/

const {ColorConsole} = require(`./utils/color`);
const {ColorConsole} = require('./utils/color');

const npm = {
utils: require(`./utils`)
utils: require('./utils')
};

/**
Expand All @@ -26,7 +26,7 @@ class DatabasePool {
* @returns {{dbMap: {}, dbs: Array}}
*/
static get instance() {
const s = Symbol.for(`pgPromiseDatabasePool`);
const s = Symbol.for('pgPromiseDatabasePool');
let scope = global[s];
if (!scope) {
scope = {
Expand All @@ -50,7 +50,7 @@ class DatabasePool {
*/
static register(db) {
const cnKey = DatabasePool.createContextKey(db);
npm.utils.addReadProp(db, `$cnKey`, cnKey, true);
npm.utils.addReadProp(db, '$cnKey', cnKey, true);
const {dbMap, dbs} = DatabasePool.instance;
if (cnKey in dbMap) {
dbMap[cnKey]++;
Expand Down Expand Up @@ -101,7 +101,7 @@ class DatabasePool {
*/
static createContextKey(db) {
let cn = db.$cn;
if (typeof cn === `object`) {
if (typeof cn === 'object') {
const obj = {}, keys = Object.keys(cn).sort();
keys.forEach(name => {
obj[name] = cn[name];
Expand Down
74 changes: 37 additions & 37 deletions lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
* Removal or modification of this copyright notice is prohibited.
*/

const {Events} = require(`./events`);
const {assert} = require(`./assert`);
const {resultQuery, multiResultQuery, streamQuery} = require(`./special-query`);
const {ConnectionContext} = require(`./context`);
const {DatabasePool} = require(`./database-pool`);
const {queryResult} = require(`./query-result`);
const {Events} = require('./events');
const {assert} = require('./assert');
const {resultQuery, multiResultQuery, streamQuery} = require('./special-query');
const {ConnectionContext} = require('./context');
const {DatabasePool} = require('./database-pool');
const {queryResult} = require('./query-result');

const npm = {
utils: require(`./utils`),
pubUtils: require(`./utils/public`),
connect: require(`./connect`),
query: require(`./query`),
task: require(`./task`),
text: require(`./text`)
utils: require('./utils'),
pubUtils: require('./utils/public'),
connect: require('./connect'),
query: require('./query'),
task: require('./task'),
text: require('./text')
};

/**
Expand Down Expand Up @@ -123,7 +123,7 @@ function Database(cn, dc, config) {

const dbThis = this,
$p = config.promise,
poolConnection = typeof cn === `string` ? {connectionString: cn} : cn,
poolConnection = typeof cn === 'string' ? {connectionString: cn} : cn,
pool = new config.pgp.pg.Pool(poolConnection),
endMethod = pool.end;

Expand All @@ -135,7 +135,7 @@ function Database(cn, dc, config) {
return res;
};

pool.on(`error`, onError);
pool.on('error', onError);

/**
* @method Database#connect
Expand Down Expand Up @@ -373,7 +373,7 @@ function Database(cn, dc, config) {
* // call either resolve(data) or reject(reason) here
* });
*/
npm.utils.addReadProp(this, `$config`, config, true);
npm.utils.addReadProp(this, '$config', config, true);

/**
* @member {string|object} Database#$cn
Expand All @@ -385,7 +385,7 @@ function Database(cn, dc, config) {
*
* @see Database
*/
npm.utils.addReadProp(this, `$cn`, cn, true);
npm.utils.addReadProp(this, '$cn', cn, true);

/**
* @member {*} Database#$dc
Expand All @@ -397,7 +397,7 @@ function Database(cn, dc, config) {
*
* @see Database
*/
npm.utils.addReadProp(this, `$dc`, dc, true);
npm.utils.addReadProp(this, '$dc', dc, true);

/**
* @member {external:pg-pool} Database#$pool
Expand Down Expand Up @@ -428,7 +428,7 @@ function Database(cn, dc, config) {
* .finally(db.$pool.end); // shutting down the pool
*
*/
npm.utils.addReadProp(this, `$pool`, pool, true);
npm.utils.addReadProp(this, '$pool', pool, true);

/**
* @member {function} Database.$destroy
Expand All @@ -437,13 +437,13 @@ function Database(cn, dc, config) {
* @description
* Permanently shuts down the database object.
*/
npm.utils.addReadProp(this, `$destroy`, () => {
npm.utils.addReadProp(this, '$destroy', () => {
if (!destroyed) {
if (!pool.ending) {
endMethod.call(pool);
}
DatabasePool.unregister(dbThis);
pool.removeListener(`error`, onError);
pool.removeListener('error', onError);
destroyed = true;
}
}, true);
Expand All @@ -458,7 +458,7 @@ function Database(cn, dc, config) {

// Optional value-transformation helper:
function transform(value, cb, thisArg) {
return typeof cb === `function` ? value.then(data => cb.call(thisArg, data)) : value;
return typeof cb === 'function' ? value.then(data => cb.call(thisArg, data)) : value;
}

////////////////////////////////////////////////////
Expand Down Expand Up @@ -981,7 +981,7 @@ function Database(cn, dc, config) {
* {@link Database#proc proc}
*/
obj.func = function (funcName, values, qrm) {
return obj.query.call(this, {entity: funcName, type: `func`}, values, qrm);
return obj.query.call(this, {entity: funcName, type: 'func'}, values, qrm);
};

/**
Expand Down Expand Up @@ -1020,7 +1020,7 @@ function Database(cn, dc, config) {
obj.proc = function (procName, values, cb, thisArg) {
const v = obj.query.call(this, {
entity: procName,
type: `proc`
type: 'proc'
}, values, queryResult.one | queryResult.none);
return transform(v, cb, thisArg);
};
Expand Down Expand Up @@ -1289,7 +1289,7 @@ function Database(cn, dc, config) {
*/
obj.task = function () {
const args = npm.pubUtils.taskArgs(arguments);
assert(args.options, [`tag`]);
assert(args.options, ['tag']);
return taskProcessor.call(this, args, false);
};

Expand Down Expand Up @@ -1347,11 +1347,11 @@ function Database(cn, dc, config) {
*/
obj.taskIf = function () {
const args = npm.pubUtils.taskArgs(arguments);
assert(args.options, [`tag`, `cnd`]);
assert(args.options, ['tag', 'cnd']);
try {
let cnd = args.options.cnd;
if (`cnd` in args.options) {
cnd = typeof cnd === `function` ? cnd.call(obj, obj) : !!cnd;
if ('cnd' in args.options) {
cnd = typeof cnd === 'function' ? cnd.call(obj, obj) : !!cnd;
} else {
cnd = !obj.ctx; // create task, if it is the top level
}
Expand Down Expand Up @@ -1456,7 +1456,7 @@ function Database(cn, dc, config) {
*/
obj.tx = function () {
const args = npm.pubUtils.taskArgs(arguments);
assert(args.options, [`tag`, `mode`]);
assert(args.options, ['tag', 'mode']);
return taskProcessor.call(this, args, true);
};

Expand Down Expand Up @@ -1529,18 +1529,18 @@ function Database(cn, dc, config) {
*/
obj.txIf = function () {
const args = npm.pubUtils.taskArgs(arguments);
assert(args.options, [`tag`, `mode`, `cnd`, `reusable`]);
assert(args.options, ['tag', 'mode', 'cnd', 'reusable']);
try {
let cnd;
if (`cnd` in args.options) {
if ('cnd' in args.options) {
cnd = args.options.cnd;
cnd = typeof cnd === `function` ? cnd.call(obj, obj) : !!cnd;
cnd = typeof cnd === 'function' ? cnd.call(obj, obj) : !!cnd;
} else {
cnd = !obj.ctx || !obj.ctx.inTransaction;
}
args.options.cnd = cnd;
const reusable = args.options.reusable;
args.options.reusable = !cnd && obj.ctx && typeof reusable === `function` ? reusable.call(obj, obj) : !!reusable;
args.options.reusable = !cnd && obj.ctx && typeof reusable === 'function' ? reusable.call(obj, obj) : !!reusable;
} catch (e) {
return $p.reject(e);
}
Expand All @@ -1551,8 +1551,8 @@ function Database(cn, dc, config) {
// Resolves with result from the callback function;
function taskProcessor(params, isTX) {

if (typeof params.cb !== `function`) {
return $p.reject(new TypeError(`Callback function is required.`));
if (typeof params.cb !== 'function') {
return $p.reject(new TypeError('Callback function is required.'));
}

if (params.options.reusable) {
Expand All @@ -1577,7 +1577,7 @@ function Database(cn, dc, config) {

if (taskCtx.db) {
// reuse existing connection;
npm.utils.addReadProp(tsk.ctx, `useCount`, taskCtx.db.useCount);
npm.utils.addReadProp(tsk.ctx, 'useCount', taskCtx.db.useCount);
addServerVersion(tsk.ctx, taskCtx.db.client);
return config.$npm.task.execute(taskCtx, tsk, isTX, config);
}
Expand All @@ -1586,7 +1586,7 @@ function Database(cn, dc, config) {
return config.$npm.connect.pool(taskCtx, dbThis)
.then(db => {
taskCtx.connect(db);
npm.utils.addReadProp(tsk.ctx, `useCount`, db.useCount);
npm.utils.addReadProp(tsk.ctx, 'useCount', db.useCount);
addServerVersion(tsk.ctx, db.client);
return config.$npm.task.execute(taskCtx, tsk, isTX, config);
})
Expand All @@ -1604,7 +1604,7 @@ function Database(cn, dc, config) {
// Exclude else-case from coverage, because it can only occur with Native Bindings.
// istanbul ignore else
if (client.serverVersion) {
npm.utils.addReadProp(target, `serverVersion`, client.serverVersion);
npm.utils.addReadProp(target, 'serverVersion', client.serverVersion);
}
}

Expand Down
Loading

0 comments on commit 156c850

Please sign in to comment.