@prairielearn/postgres 2.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/error.d.ts +1 -0
- package/dist/error.js +19 -0
- package/dist/error.js.map +1 -0
- package/dist/error.test.d.ts +1 -0
- package/dist/error.test.js +9 -0
- package/dist/error.test.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/error.test.ts +13 -0
- package/src/error.ts +19 -0
- package/src/index.ts +2 -0
package/CHANGELOG.md
CHANGED
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatQueryWithErrorPosition(query: string, position: number | null | undefined): string;
|
package/dist/error.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function formatQueryWithErrorPosition(query, position) {
|
|
2
|
+
if (position == null)
|
|
3
|
+
return query;
|
|
4
|
+
const prevNewline = Math.max(0, query.lastIndexOf('\n', position) + 1);
|
|
5
|
+
let nextNewline = query.indexOf('\n', position);
|
|
6
|
+
if (nextNewline < 0)
|
|
7
|
+
nextNewline = query.length;
|
|
8
|
+
const gap = ' '.repeat(Math.max(0, position - prevNewline - 1));
|
|
9
|
+
return (query.substring(0, nextNewline) +
|
|
10
|
+
'\n' +
|
|
11
|
+
gap +
|
|
12
|
+
'^\n' +
|
|
13
|
+
gap +
|
|
14
|
+
'|\n' +
|
|
15
|
+
gap +
|
|
16
|
+
'+ ERROR POSITION SHOWN ABOVE\n' +
|
|
17
|
+
query.substring(nextNewline));
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,4BAA4B,CAAC,KAAa,EAAE,QAAmC;IAC7F,IAAI,QAAQ,IAAI,IAAI;QAAE,OAAO,KAAK,CAAC;IAEnC,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IACvE,IAAI,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAChD,IAAI,WAAW,GAAG,CAAC;QAAE,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC;IAChD,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC;IAChE,OAAO,CACL,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,WAAW,CAAC;QAC/B,IAAI;QACJ,GAAG;QACH,KAAK;QACL,GAAG;QACH,KAAK;QACL,GAAG;QACH,gCAAgC;QAChC,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAC7B,CAAC;AACJ,CAAC","sourcesContent":["export function formatQueryWithErrorPosition(query: string, position: number | null | undefined) {\n if (position == null) return query;\n\n const prevNewline = Math.max(0, query.lastIndexOf('\\n', position) + 1);\n let nextNewline = query.indexOf('\\n', position);\n if (nextNewline < 0) nextNewline = query.length;\n const gap = ' '.repeat(Math.max(0, position - prevNewline - 1));\n return (\n query.substring(0, nextNewline) +\n '\\n' +\n gap +\n '^\\n' +\n gap +\n '|\\n' +\n gap +\n '+ ERROR POSITION SHOWN ABOVE\\n' +\n query.substring(nextNewline)\n );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { assert } from 'chai';
|
|
2
|
+
import { formatQueryWithErrorPosition } from './error.js';
|
|
3
|
+
describe('formatQueryWithErrorPosition', () => {
|
|
4
|
+
it('formats a query', () => {
|
|
5
|
+
const formattedQuery = formatQueryWithErrorPosition('SELECT\n foo bar baz\nFROM table;', 18);
|
|
6
|
+
assert.equal(formattedQuery, 'SELECT\n foo bar baz\n ^\n |\n + ERROR POSITION SHOWN ABOVE\n\nFROM table;');
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=error.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.test.js","sourceRoot":"","sources":["../src/error.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAE1D,QAAQ,CAAC,8BAA8B,EAAE,GAAG,EAAE;IAC5C,EAAE,CAAC,iBAAiB,EAAE,GAAG,EAAE;QACzB,MAAM,cAAc,GAAG,4BAA4B,CAAC,oCAAoC,EAAE,EAAE,CAAC,CAAC;QAC9F,MAAM,CAAC,KAAK,CACV,cAAc,EACd,wGAAwG,CACzG,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { assert } from 'chai';\n\nimport { formatQueryWithErrorPosition } from './error.js';\n\ndescribe('formatQueryWithErrorPosition', () => {\n it('formats a query', () => {\n const formattedQuery = formatQueryWithErrorPosition('SELECT\\n foo bar baz\\nFROM table;', 18);\n assert.equal(\n formattedQuery,\n 'SELECT\\n foo bar baz\\n ^\\n |\\n + ERROR POSITION SHOWN ABOVE\\n\\nFROM table;',\n );\n });\n});\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export { type PoolClient } from 'pg';
|
|
|
2
2
|
export { loadSql, loadSqlEquiv } from './loader.js';
|
|
3
3
|
export { PostgresPool, PostgresPoolConfig } from './pool.js';
|
|
4
4
|
export * from './default-pool.js';
|
|
5
|
+
export { formatQueryWithErrorPosition } from './error.js';
|
|
5
6
|
export { makePostgresTestUtils, type PostgresTestUtils, type PostgresTestUtilsOptions, } from './test-utils.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { loadSql, loadSqlEquiv } from './loader.js';
|
|
2
2
|
export { PostgresPool } from './pool.js';
|
|
3
3
|
export * from './default-pool.js';
|
|
4
|
+
export { formatQueryWithErrorPosition } from './error.js';
|
|
4
5
|
export { makePostgresTestUtils, } from './test-utils.js';
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,YAAY,EAAsB,MAAM,WAAW,CAAC;AAE7D,cAAc,mBAAmB,CAAC;AAElC,OAAO,EACL,qBAAqB,GAGtB,MAAM,iBAAiB,CAAC","sourcesContent":["export { type PoolClient } from 'pg';\n\nexport { loadSql, loadSqlEquiv } from './loader.js';\nexport { PostgresPool, PostgresPoolConfig } from './pool.js';\n\nexport * from './default-pool.js';\n\nexport {\n makePostgresTestUtils,\n type PostgresTestUtils,\n type PostgresTestUtilsOptions,\n} from './test-utils.js';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,YAAY,EAAsB,MAAM,WAAW,CAAC;AAE7D,cAAc,mBAAmB,CAAC;AAElC,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAE1D,OAAO,EACL,qBAAqB,GAGtB,MAAM,iBAAiB,CAAC","sourcesContent":["export { type PoolClient } from 'pg';\n\nexport { loadSql, loadSqlEquiv } from './loader.js';\nexport { PostgresPool, PostgresPoolConfig } from './pool.js';\n\nexport * from './default-pool.js';\n\nexport { formatQueryWithErrorPosition } from './error.js';\n\nexport {\n makePostgresTestUtils,\n type PostgresTestUtils,\n type PostgresTestUtilsOptions,\n} from './test-utils.js';\n"]}
|
package/package.json
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { assert } from 'chai';
|
|
2
|
+
|
|
3
|
+
import { formatQueryWithErrorPosition } from './error.js';
|
|
4
|
+
|
|
5
|
+
describe('formatQueryWithErrorPosition', () => {
|
|
6
|
+
it('formats a query', () => {
|
|
7
|
+
const formattedQuery = formatQueryWithErrorPosition('SELECT\n foo bar baz\nFROM table;', 18);
|
|
8
|
+
assert.equal(
|
|
9
|
+
formattedQuery,
|
|
10
|
+
'SELECT\n foo bar baz\n ^\n |\n + ERROR POSITION SHOWN ABOVE\n\nFROM table;',
|
|
11
|
+
);
|
|
12
|
+
});
|
|
13
|
+
});
|
package/src/error.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function formatQueryWithErrorPosition(query: string, position: number | null | undefined) {
|
|
2
|
+
if (position == null) return query;
|
|
3
|
+
|
|
4
|
+
const prevNewline = Math.max(0, query.lastIndexOf('\n', position) + 1);
|
|
5
|
+
let nextNewline = query.indexOf('\n', position);
|
|
6
|
+
if (nextNewline < 0) nextNewline = query.length;
|
|
7
|
+
const gap = ' '.repeat(Math.max(0, position - prevNewline - 1));
|
|
8
|
+
return (
|
|
9
|
+
query.substring(0, nextNewline) +
|
|
10
|
+
'\n' +
|
|
11
|
+
gap +
|
|
12
|
+
'^\n' +
|
|
13
|
+
gap +
|
|
14
|
+
'|\n' +
|
|
15
|
+
gap +
|
|
16
|
+
'+ ERROR POSITION SHOWN ABOVE\n' +
|
|
17
|
+
query.substring(nextNewline)
|
|
18
|
+
);
|
|
19
|
+
}
|