Update to NPM version
This commit is contained in:
101
ProjectSourceCode/node_modules/pg-minify/README.md
generated
vendored
Normal file
101
ProjectSourceCode/node_modules/pg-minify/README.md
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
pg-minify
|
||||
=========
|
||||
|
||||
Minifies PostgreSQL scripts, reducing the IO usage.
|
||||
|
||||
[](https://travis-ci.org/vitaly-t/pg-minify)
|
||||
[](https://coveralls.io/r/vitaly-t/pg-minify?branch=master)
|
||||
[](https://gitter.im/vitaly-t/pg-minify?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
|
||||
**Features:**
|
||||
|
||||
* Removes `/*multi-line*/` (including nested) and `--single-line` comments
|
||||
* Preserves special/copyright multi-line comments that start with `/*!`
|
||||
* Concatenates multi-line strings into a single line with `\n`
|
||||
* Fixes multi-line text, prefixing it with `E` where needed
|
||||
* Removes redundant line gaps: line breaks, tabs and spaces
|
||||
* Provides basic parsing and error detection for invalid SQL
|
||||
* Flattens the resulting script into a single line
|
||||
* Optionally, compresses SQL for minimum space
|
||||
|
||||
## Installing
|
||||
|
||||
```
|
||||
$ npm install pg-minify
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const minify = require('pg-minify');
|
||||
|
||||
const sql = 'SELECT 1; -- comments';
|
||||
|
||||
minify(sql); //=> SELECT 1;
|
||||
```
|
||||
|
||||
with compression (removes all unnecessary spaces):
|
||||
|
||||
```js
|
||||
const sql = 'SELECT * FROM "table" WHERE col = 123; -- comments';
|
||||
|
||||
minify(sql, {compress: true});
|
||||
//=> SELECT*FROM"table"WHERE col=123;
|
||||
```
|
||||
|
||||
The library's distribution includes [TypeScript] declarations.
|
||||
|
||||
## Error Handling
|
||||
|
||||
[SQLParsingError] is thrown on failed SQL parsing:
|
||||
|
||||
```js
|
||||
try {
|
||||
minify('SELECT \'1');
|
||||
} catch (error) {
|
||||
// error is minify.SQLParsingError instance
|
||||
// error.message:
|
||||
// Error parsing SQL at {line:1,col:8}: Unclosed text block.
|
||||
}
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### minify(sql, [options]) ⇒ String
|
||||
|
||||
Minifies SQL into a single line, according to the `options`.
|
||||
|
||||
##### options.compress ⇒ Boolean
|
||||
|
||||
Compresses / uglifies the SQL to its bare minimum, by removing all unnecessary spaces.
|
||||
|
||||
* `false (default)` - keeps minimum spaces, for easier read
|
||||
* `true` - removes all unnecessary spaces
|
||||
|
||||
See also: [SQL Compression].
|
||||
|
||||
##### options.removeAll ⇒ Boolean
|
||||
|
||||
Removes everything, i.e. special/copyright multi-line comments that start with `/*!` will be removed as well.
|
||||
|
||||
## Testing
|
||||
|
||||
First, clone the repository and install DEV dependencies.
|
||||
|
||||
```
|
||||
$ npm test
|
||||
```
|
||||
|
||||
Testing with coverage:
|
||||
```
|
||||
$ npm run coverage
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Copyright © 2020 [Vitaly Tomilov](https://github.com/vitaly-t);
|
||||
Released under the MIT license.
|
||||
|
||||
[SQLParsingError]:https://github.com/vitaly-t/pg-minify/blob/master/lib/error.js#L22
|
||||
[TypeScript]:https://github.com/vitaly-t/pg-minify/tree/master/typescript
|
||||
[SQL Compression]:https://github.com/vitaly-t/pg-minify/wiki/SQL-Compression
|
||||
53
ProjectSourceCode/node_modules/pg-minify/lib/error.js
generated
vendored
Normal file
53
ProjectSourceCode/node_modules/pg-minify/lib/error.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
const {EOL} = require('os');
|
||||
const {addInspection, messageGap} = require('./utils');
|
||||
|
||||
const parsingErrorCode = {
|
||||
unclosedMLC: 0, // Unclosed multi-line comment.
|
||||
unclosedText: 1, // Unclosed text block.
|
||||
unclosedQI: 2, // Unclosed quoted identifier.
|
||||
multiLineQI: 3 // Multi-line quoted identifiers are not supported.
|
||||
};
|
||||
|
||||
Object.freeze(parsingErrorCode);
|
||||
|
||||
const errorMessages = [
|
||||
{name: 'unclosedMLC', message: 'Unclosed multi-line comment.'},
|
||||
{name: 'unclosedText', message: 'Unclosed text block.'},
|
||||
{name: 'unclosedQI', message: 'Unclosed quoted identifier.'},
|
||||
{name: 'multiLineQI', message: 'Multi-line quoted identifiers are not supported.'}
|
||||
];
|
||||
|
||||
class SQLParsingError extends Error {
|
||||
constructor(code, position) {
|
||||
const err = errorMessages[code].message;
|
||||
const message = `Error parsing SQL at {line:${position.line},col:${position.column}}: ${err}`;
|
||||
super(message);
|
||||
this.name = this.constructor.name;
|
||||
this.error = err;
|
||||
this.code = code;
|
||||
this.position = position;
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
|
||||
SQLParsingError.prototype.toString = function (level) {
|
||||
level = level > 0 ? parseInt(level) : 0;
|
||||
const gap = messageGap(level + 1);
|
||||
const lines = [
|
||||
`SQLParsingError {`,
|
||||
`${gap}code: parsingErrorCode.${errorMessages[this.code].name}`,
|
||||
`${gap}error: "${this.error}"`,
|
||||
`${gap}position: {line: ${this.position.line}, col: ${this.position.column}}`,
|
||||
`${messageGap(level)}}`
|
||||
];
|
||||
return lines.join(EOL);
|
||||
};
|
||||
|
||||
addInspection(SQLParsingError.prototype, function () {
|
||||
return this.toString();
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
SQLParsingError,
|
||||
parsingErrorCode
|
||||
};
|
||||
7
ProjectSourceCode/node_modules/pg-minify/lib/index.js
generated
vendored
Normal file
7
ProjectSourceCode/node_modules/pg-minify/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
const parser = require('./parser');
|
||||
const error = require('./error');
|
||||
|
||||
parser.SQLParsingError = error.SQLParsingError;
|
||||
parser.parsingErrorCode = error.parsingErrorCode;
|
||||
|
||||
module.exports = parser;
|
||||
196
ProjectSourceCode/node_modules/pg-minify/lib/parser.js
generated
vendored
Normal file
196
ProjectSourceCode/node_modules/pg-minify/lib/parser.js
generated
vendored
Normal file
@@ -0,0 +1,196 @@
|
||||
const {parsingErrorCode, SQLParsingError} = require('./error');
|
||||
const {getIndexPos} = require('./utils');
|
||||
|
||||
// symbols that need no spaces around them:
|
||||
const compressors = '.,;:()[]=<>+-*/|!?@#';
|
||||
|
||||
////////////////////////////////////////////
|
||||
// Parses and minimizes a PostgreSQL script.
|
||||
function minify(sql, options) {
|
||||
|
||||
if (typeof sql !== 'string') {
|
||||
throw new TypeError('Input SQL must be a text string.');
|
||||
}
|
||||
|
||||
if (!sql.length) {
|
||||
return '';
|
||||
}
|
||||
|
||||
sql = sql.replace(/\r\n/g, '\n');
|
||||
|
||||
options = options || {};
|
||||
|
||||
let idx = 0, // current index
|
||||
result = '', // resulting sql
|
||||
space = false; // add a space on the next step
|
||||
|
||||
const len = sql.length;
|
||||
|
||||
do {
|
||||
const s = sql[idx], // current symbol;
|
||||
s1 = sql[idx + 1]; // next symbol;
|
||||
|
||||
if (isGap(s)) {
|
||||
while (++idx < len && isGap(sql[idx])) ;
|
||||
if (idx < len) {
|
||||
space = true;
|
||||
}
|
||||
idx--;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (s === '-' && s1 === '-') {
|
||||
const lb = sql.indexOf('\n', idx + 2);
|
||||
if (lb < 0) {
|
||||
break;
|
||||
}
|
||||
idx = lb - 1;
|
||||
skipGaps();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (s === '/' && s1 === '*') {
|
||||
let c = idx + 1, open = 0, close = 0, lastOpen, lastClose;
|
||||
while (++c < len - 1 && close <= open) {
|
||||
if (sql[c] === '/' && sql[c + 1] === '*') {
|
||||
lastOpen = c;
|
||||
open++;
|
||||
c++;
|
||||
} else {
|
||||
if (sql[c] === '*' && sql[c + 1] === '/') {
|
||||
lastClose = c;
|
||||
close++;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (close <= open) {
|
||||
idx = lastOpen;
|
||||
throwError(parsingErrorCode.unclosedMLC);
|
||||
}
|
||||
if (sql[idx + 2] === '!' && !options.removeAll) {
|
||||
if (options.compress) {
|
||||
space = false;
|
||||
}
|
||||
addSpace();
|
||||
result += sql.substring(idx, lastClose + 2)
|
||||
.replace(/\n/g, '\r\n');
|
||||
}
|
||||
idx = lastClose + 1;
|
||||
skipGaps();
|
||||
continue;
|
||||
}
|
||||
|
||||
let closeIdx, text;
|
||||
|
||||
if (s === '"') {
|
||||
closeIdx = sql.indexOf('"', idx + 1);
|
||||
if (closeIdx < 0) {
|
||||
throwError(parsingErrorCode.unclosedQI);
|
||||
}
|
||||
text = sql.substring(idx, closeIdx + 1);
|
||||
if (text.indexOf('\n') > 0) {
|
||||
throwError(parsingErrorCode.multiLineQI);
|
||||
}
|
||||
if (options.compress) {
|
||||
space = false;
|
||||
}
|
||||
addSpace();
|
||||
result += text;
|
||||
idx = closeIdx;
|
||||
skipGaps();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (s === `'`) {
|
||||
closeIdx = idx;
|
||||
do {
|
||||
closeIdx = sql.indexOf(`'`, closeIdx + 1);
|
||||
if (closeIdx > 0) {
|
||||
let i = closeIdx;
|
||||
while (sql[--i] === '\\') ;
|
||||
if ((closeIdx - i) % 2) {
|
||||
let step = closeIdx;
|
||||
while (++step < len && sql[step] === `'`) ;
|
||||
if ((step - closeIdx) % 2) {
|
||||
closeIdx = step - 1;
|
||||
break;
|
||||
}
|
||||
closeIdx = step === len ? -1 : step;
|
||||
}
|
||||
}
|
||||
} while (closeIdx > 0);
|
||||
if (closeIdx < 0) {
|
||||
throwError(parsingErrorCode.unclosedText);
|
||||
}
|
||||
if (options.compress) {
|
||||
space = false;
|
||||
}
|
||||
addSpace();
|
||||
text = sql.substring(idx, closeIdx + 1);
|
||||
const hasLB = text.indexOf('\n') > 0;
|
||||
if (hasLB) {
|
||||
text = text.split('\n').map(m => {
|
||||
return m.replace(/^\s+|\s+$/g, '');
|
||||
}).join('\\n');
|
||||
}
|
||||
const hasTabs = text.indexOf('\t') > 0;
|
||||
if (hasLB || hasTabs) {
|
||||
const prev = idx ? sql[idx - 1] : '';
|
||||
if (prev !== 'E' && prev !== 'e') {
|
||||
const r = result ? result[result.length - 1] : '';
|
||||
if (r && r !== ' ' && compressors.indexOf(r) < 0) {
|
||||
result += ' ';
|
||||
}
|
||||
result += 'E';
|
||||
}
|
||||
if (hasTabs) {
|
||||
text = text.replace(/\t/g, '\\t');
|
||||
}
|
||||
}
|
||||
result += text;
|
||||
idx = closeIdx;
|
||||
skipGaps();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (options.compress && compressors.indexOf(s) >= 0) {
|
||||
space = false;
|
||||
skipGaps();
|
||||
}
|
||||
|
||||
addSpace();
|
||||
result += s;
|
||||
|
||||
} while (++idx < len);
|
||||
|
||||
return result;
|
||||
|
||||
function skipGaps() {
|
||||
if (options.compress) {
|
||||
while (idx < len - 1 && isGap(sql[idx + 1]) && idx++) ;
|
||||
}
|
||||
}
|
||||
|
||||
function addSpace() {
|
||||
if (space) {
|
||||
if (result.length) {
|
||||
result += ' ';
|
||||
}
|
||||
space = false;
|
||||
}
|
||||
}
|
||||
|
||||
function throwError(code) {
|
||||
const position = getIndexPos(sql, idx);
|
||||
throw new SQLParsingError(code, position);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////
|
||||
// Identifies a gap / empty symbol.
|
||||
function isGap(s) {
|
||||
return s === ' ' || s === '\t' || s === '\r' || s === '\n';
|
||||
}
|
||||
|
||||
module.exports = minify;
|
||||
38
ProjectSourceCode/node_modules/pg-minify/lib/utils.js
generated
vendored
Normal file
38
ProjectSourceCode/node_modules/pg-minify/lib/utils.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
const {inspect} = require('util');
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Returns {line, column} of an index within multi-line text.
|
||||
function getIndexPos(text, index) {
|
||||
let lineIdx = 0, colIdx = index, pos = 0;
|
||||
do {
|
||||
pos = text.indexOf('\n', pos);
|
||||
if (pos === -1 || index < pos + 1) {
|
||||
break;
|
||||
}
|
||||
lineIdx++;
|
||||
pos++;
|
||||
colIdx = index - pos;
|
||||
} while (pos < index);
|
||||
return {
|
||||
line: lineIdx + 1,
|
||||
column: colIdx + 1
|
||||
};
|
||||
}
|
||||
|
||||
///////////////////////////////////////////
|
||||
// Returns a space gap for console output.
|
||||
function messageGap(level) {
|
||||
return ' '.repeat(level * 4);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// Type inspection
|
||||
function addInspection(type, cb) {
|
||||
type[inspect.custom] = cb;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getIndexPos,
|
||||
messageGap,
|
||||
addInspection
|
||||
};
|
||||
51
ProjectSourceCode/node_modules/pg-minify/package.json
generated
vendored
Normal file
51
ProjectSourceCode/node_modules/pg-minify/package.json
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"name": "pg-minify",
|
||||
"version": "1.6.2",
|
||||
"description": "Minifies PostgreSQL scripts.",
|
||||
"main": "lib/index.js",
|
||||
"typings": "typescript/pg-minify.d.ts",
|
||||
"scripts": {
|
||||
"test": "jasmine-node --captureExceptions test",
|
||||
"coverage": "istanbul cover ./node_modules/jasmine-node/bin/jasmine-node test",
|
||||
"lint": "eslint ./lib ./test/*.js",
|
||||
"travis": "npm run lint && istanbul cover ./node_modules/jasmine-node/bin/jasmine-node test --captureExceptions && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
|
||||
},
|
||||
"files": [
|
||||
"lib",
|
||||
"typescript"
|
||||
],
|
||||
"homepage": "https://github.com/vitaly-t/pg-minify",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/vitaly-t/pg-minify.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/vitaly-t/pg-minify/issues",
|
||||
"email": "vitaly.tomilov@gmail.com"
|
||||
},
|
||||
"keywords": [
|
||||
"sql",
|
||||
"postgresql",
|
||||
"comments",
|
||||
"minify",
|
||||
"uglify",
|
||||
"compress",
|
||||
"strip",
|
||||
"remove"
|
||||
],
|
||||
"author": {
|
||||
"name": "Vitaly Tomilov",
|
||||
"email": "vitaly.tomilov@gmail.com"
|
||||
},
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"coveralls": "3.1.0",
|
||||
"eslint": "7.16.0",
|
||||
"istanbul": "0.4.5",
|
||||
"jasmine-node": "3.0.0",
|
||||
"typescript": "4.1.3"
|
||||
}
|
||||
}
|
||||
26
ProjectSourceCode/node_modules/pg-minify/typescript/README.md
generated
vendored
Normal file
26
ProjectSourceCode/node_modules/pg-minify/typescript/README.md
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
## TypeScript for pg-minify
|
||||
|
||||
Complete TypeScript 3.x (`strict` mode) declarations for the module.
|
||||
|
||||
### Inclusion
|
||||
|
||||
Typescript picks up the definitions without any manual configuration.
|
||||
|
||||
### Usage
|
||||
|
||||
```ts
|
||||
import * as minify from 'pg-minify';
|
||||
|
||||
const sql = 'SELECT 1; -- comments';
|
||||
|
||||
minify(sql); //=> SELECT 1;
|
||||
```
|
||||
|
||||
And if you are using `"allowSyntheticDefaultImports": true` in your `tsconfig.json`,
|
||||
then you can include it like this:
|
||||
|
||||
```ts
|
||||
import minify from 'pg-minify';
|
||||
```
|
||||
|
||||
[pg-minify]:https://github.com/vitaly-t/pg-minify
|
||||
36
ProjectSourceCode/node_modules/pg-minify/typescript/pg-minify.d.ts
generated
vendored
Normal file
36
ProjectSourceCode/node_modules/pg-minify/typescript/pg-minify.d.ts
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
////////////////////////////////////////
|
||||
// For pg-minify v1.6.0 or later.
|
||||
////////////////////////////////////////
|
||||
|
||||
declare namespace pgMinify {
|
||||
|
||||
interface IMinifyOptions {
|
||||
compress?: boolean;
|
||||
removeAll?: boolean;
|
||||
}
|
||||
|
||||
interface IErrorPosition {
|
||||
line: number;
|
||||
column: number;
|
||||
}
|
||||
|
||||
enum parsingErrorCode {
|
||||
unclosedMLC = 0, // Unclosed multi-line comment.
|
||||
unclosedText = 1, // Unclosed text block.
|
||||
unclosedQI = 2, // Unclosed quoted identifier.
|
||||
multiLineQI = 3 // Multi-line quoted identifiers are not supported.
|
||||
}
|
||||
|
||||
class SQLParsingError implements Error {
|
||||
name: string;
|
||||
message: string;
|
||||
stack: string;
|
||||
error: string;
|
||||
code: parsingErrorCode;
|
||||
position: IErrorPosition;
|
||||
}
|
||||
}
|
||||
|
||||
declare function pgMinify(sql: string, options?: pgMinify.IMinifyOptions): string;
|
||||
|
||||
export = pgMinify;
|
||||
Reference in New Issue
Block a user