From a21b0710490efd04ca0c794ecbf7bd9ea7c6b5b4 Mon Sep 17 00:00:00 2001 From: Nicolas Guerrero Date: Wed, 9 Dec 2020 15:24:50 -0500 Subject: [PATCH 1/7] Upgrade to Deno 1.6.0 --- deps.ts | 10 +++++----- test_deps.ts | 3 +-- tests/client.ts | 4 ++-- utils.ts | 8 +++++--- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/deps.ts b/deps.ts index fdb5cc5b..2fe28c39 100644 --- a/deps.ts +++ b/deps.ts @@ -1,5 +1,5 @@ -export { BufReader, BufWriter } from "https://deno.land/std@0.69.0/io/bufio.ts"; -export { copyBytes } from "https://deno.land/std@0.67.0/bytes/mod.ts"; -export { deferred } from "https://deno.land/std@0.69.0/async/deferred.ts"; -export type { Deferred } from "https://deno.land/std@0.69.0/async/deferred.ts"; -export { createHash } from "https://deno.land/std@0.67.0/hash/mod.ts"; +export { BufReader, BufWriter } from "https://deno.land/std@0.80.0/io/bufio.ts"; +export { copy as copyBytes } from "https://deno.land/std@0.80.0/bytes/mod.ts"; +export { deferred } from "https://deno.land/std@0.80.0/async/deferred.ts"; +export type { Deferred } from "https://deno.land/std@0.80.0/async/deferred.ts"; +export { createHash } from "https://deno.land/std@0.80.0/hash/mod.ts"; diff --git a/test_deps.ts b/test_deps.ts index 30d8d184..344cf50f 100644 --- a/test_deps.ts +++ b/test_deps.ts @@ -2,7 +2,6 @@ export * from "./deps.ts"; export { assert, assertEquals, - assertStringContains, assertThrows, assertThrowsAsync, -} from "https://deno.land/std@0.67.0/testing/asserts.ts"; +} from "https://deno.land/std@0.80.0/testing/asserts.ts"; diff --git a/tests/client.ts b/tests/client.ts index 04163ac9..ae52c37a 100644 --- a/tests/client.ts +++ b/tests/client.ts @@ -1,6 +1,6 @@ const { test } = Deno; import { Client, PostgresError } from "../mod.ts"; -import { assert, assertStringContains } from "../test_deps.ts"; +import { assert } from "../test_deps.ts"; import { TEST_CONNECTION_PARAMS } from "./constants.ts"; test("badAuthData", async function () { @@ -15,7 +15,7 @@ test("badAuthData", async function () { } catch (e) { thrown = true; assert(e instanceof PostgresError); - assertStringContains(e.message, "password authentication failed for user"); + assert(e.message.includes("password authentication failed for user")); } finally { await client.end(); } diff --git a/utils.ts b/utils.ts index c473af63..d4f3e640 100644 --- a/utils.ts +++ b/utils.ts @@ -88,10 +88,12 @@ export function parseDsn(dsn: string): DsnResult { }; } -export function delay(ms: number, value?: T): Promise { - return new Promise((resolve, reject) => { +export function delay(ms: number): Promise; +export function delay(ms: number, value: T): Promise; +export function delay(ms: number, value?: unknown){ + return new Promise((resolve) => { setTimeout(() => { resolve(value); }, ms); }); -} +} \ No newline at end of file From c50c71c591a2d22bab3798cedc58e085bc4fbcc4 Mon Sep 17 00:00:00 2001 From: Nicolas Guerrero Date: Wed, 9 Dec 2020 15:26:12 -0500 Subject: [PATCH 2/7] Cleanup rename --- deps.ts | 2 +- packet_writer.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/deps.ts b/deps.ts index 2fe28c39..32c38737 100644 --- a/deps.ts +++ b/deps.ts @@ -1,5 +1,5 @@ export { BufReader, BufWriter } from "https://deno.land/std@0.80.0/io/bufio.ts"; -export { copy as copyBytes } from "https://deno.land/std@0.80.0/bytes/mod.ts"; +export { copy } from "https://deno.land/std@0.80.0/bytes/mod.ts"; export { deferred } from "https://deno.land/std@0.80.0/async/deferred.ts"; export type { Deferred } from "https://deno.land/std@0.80.0/async/deferred.ts"; export { createHash } from "https://deno.land/std@0.80.0/hash/mod.ts"; diff --git a/packet_writer.ts b/packet_writer.ts index 4a3d9f2b..ea95cc6b 100644 --- a/packet_writer.ts +++ b/packet_writer.ts @@ -25,7 +25,7 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { copyBytes } from "./deps.ts"; +import { copy } from "./deps.ts"; export class PacketWriter { private size: number; @@ -49,7 +49,7 @@ export class PacketWriter { // https://stackoverflow.com/questions/2269063/buffer-growth-strategy const newSize = oldBuffer.length + (oldBuffer.length >> 1) + size; this.buffer = new Uint8Array(newSize); - copyBytes(oldBuffer, this.buffer); + copy(oldBuffer, this.buffer); } } @@ -76,7 +76,7 @@ export class PacketWriter { } else { const encodedStr = this.encoder.encode(string); this._ensure(encodedStr.byteLength + 1); // +1 for null terminator - copyBytes(encodedStr, this.buffer, this.offset); + copy(encodedStr, this.buffer, this.offset); this.offset += encodedStr.byteLength; } @@ -90,7 +90,7 @@ export class PacketWriter { } this._ensure(1); - copyBytes(this.encoder.encode(c), this.buffer, this.offset); + copy(this.encoder.encode(c), this.buffer, this.offset); this.offset++; return this; } @@ -99,14 +99,14 @@ export class PacketWriter { string = string || ""; const encodedStr = this.encoder.encode(string); this._ensure(encodedStr.byteLength); - copyBytes(encodedStr, this.buffer, this.offset); + copy(encodedStr, this.buffer, this.offset); this.offset += encodedStr.byteLength; return this; } add(otherBuffer: Uint8Array) { this._ensure(otherBuffer.length); - copyBytes(otherBuffer, this.buffer, this.offset); + copy(otherBuffer, this.buffer, this.offset); this.offset += otherBuffer.length; return this; } From 85846fa40da88496c34a8688dd6efca4acfaaad8 Mon Sep 17 00:00:00 2001 From: Nicolas Guerrero Date: Wed, 9 Dec 2020 15:27:08 -0500 Subject: [PATCH 3/7] Upgrade CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f67c5cc3..53523ffd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: - name: Install deno uses: denolib/setup-deno@master with: - deno-version: 1.4.0 + deno-version: 1.6.0 - name: Check formatting run: deno fmt --check From cdf7e48b5736e810f1677061d72021010f6e39a3 Mon Sep 17 00:00:00 2001 From: Nicolas Guerrero Date: Wed, 9 Dec 2020 15:30:25 -0500 Subject: [PATCH 4/7] Fix lint warnings --- array_parser.ts | 2 +- decode.ts | 6 +++--- encode.ts | 4 ++-- oid.ts | 21 +++++++++++++++++++++ tests/data_types.ts | 2 ++ tests/encode.ts | 2 ++ tests/helpers.ts | 2 +- tests/pool.ts | 6 +++++- utils.ts | 1 + 9 files changed, 38 insertions(+), 8 deletions(-) diff --git a/array_parser.ts b/array_parser.ts index da42f962..ee3361e8 100644 --- a/array_parser.ts +++ b/array_parser.ts @@ -79,7 +79,7 @@ class ArrayParser { consumeDimensions(): void { if (this.source[0] === "[") { while (!this.isEof()) { - let char = this.nextCharacter(); + const char = this.nextCharacter(); if (char.value === "=") break; } } diff --git a/decode.ts b/decode.ts index 3e32098f..05151580 100644 --- a/decode.ts +++ b/decode.ts @@ -139,8 +139,8 @@ function decodeBytea(byteaStr: string): Uint8Array { } function decodeByteaHex(byteaStr: string): Uint8Array { - let bytesStr = byteaStr.slice(2); - let bytes = new Uint8Array(bytesStr.length / 2); + const bytesStr = byteaStr.slice(2); + const bytes = new Uint8Array(bytesStr.length / 2); for (let i = 0, j = 0; i < bytesStr.length; i += 2, j++) { bytes[j] = parseInt(bytesStr[i] + bytesStr[i + 1], HEX); } @@ -148,7 +148,7 @@ function decodeByteaHex(byteaStr: string): Uint8Array { } function decodeByteaEscape(byteaStr: string): Uint8Array { - let bytes = []; + const bytes = []; let i = 0; let k = 0; while (i < byteaStr.length) { diff --git a/encode.ts b/encode.ts index 43b16f61..50e35dee 100644 --- a/encode.ts +++ b/encode.ts @@ -41,7 +41,7 @@ function encodeDate(date: Date): string { function escapeArrayElement(value: unknown): string { // deno-lint-ignore no-explicit-any - let strValue = (value as any).toString(); + const strValue = (value as any).toString(); const escapedValue = strValue.replace(/\\/g, "\\\\").replace(/"/g, '\\"'); return `"${escapedValue}"`; @@ -73,7 +73,7 @@ function encodeArray(array: Array): string { } function encodeBytes(value: Uint8Array): string { - let hex = Array.from(value) + const hex = Array.from(value) .map((val) => (val < 10 ? `0${val.toString(16)}` : val.toString(16))) .join(""); return `\\x${hex}`; diff --git a/oid.ts b/oid.ts index 300407d8..3a68f7ba 100644 --- a/oid.ts +++ b/oid.ts @@ -14,17 +14,25 @@ export const Oid = { xid: 28, cid: 29, oidvector: 30, + // deno-lint-ignore camelcase pg_ddl_command: 32, + // deno-lint-ignore camelcase pg_type: 71, + // deno-lint-ignore camelcase pg_attribute: 75, + // deno-lint-ignore camelcase pg_proc: 81, + // deno-lint-ignore camelcase pg_class: 83, json: 114, xml: 142, _xml: 143, + // deno-lint-ignore camelcase pg_node_tree: 194, + // deno-lint-ignore camelcase json_array: 199, smgr: 210, + // deno-lint-ignore camelcase index_am_handler: 325, point: 600, lseg: 601, @@ -91,6 +99,7 @@ export const Oid = { interval: 1186, _interval: 1187, _numeric: 1231, + // deno-lint-ignore camelcase pg_database: 1248, _cstring: 1263, timetz: 1266, @@ -118,21 +127,30 @@ export const Oid = { anyarray: 2277, void: 2278, trigger: 2279, + // deno-lint-ignore camelcase language_handler: 2280, internal: 2281, opaque: 2282, anyelement: 2283, _record: 2287, anynonarray: 2776, + // deno-lint-ignore camelcase pg_authid: 2842, + // deno-lint-ignore camelcase pg_auth_members: 2843, + // deno-lint-ignore camelcase _txid_snapshot: 2949, uuid: 2950, _uuid: 2951, + // deno-lint-ignore camelcase txid_snapshot: 2970, + // deno-lint-ignore camelcase fdw_handler: 3115, + // deno-lint-ignore camelcase pg_lsn: 3220, + // deno-lint-ignore camelcase _pg_lsn: 3221, + // deno-lint-ignore camelcase tsm_handler: 3310, anyenum: 3500, tsvector: 3614, @@ -146,8 +164,10 @@ export const Oid = { regdictionary: 3769, _regdictionary: 3770, jsonb: 3802, + // deno-lint-ignore camelcase jsonb_array: 3807, anyrange: 3831, + // deno-lint-ignore camelcase event_trigger: 3838, int4range: 3904, _int4range: 3905, @@ -161,6 +181,7 @@ export const Oid = { _daterange: 3913, int8range: 3926, _int8range: 3927, + // deno-lint-ignore camelcase pg_shseclabel: 4066, regnamespace: 4089, _regnamespace: 4090, diff --git a/tests/data_types.ts b/tests/data_types.ts index e30a185b..94a4cf6d 100644 --- a/tests/data_types.ts +++ b/tests/data_types.ts @@ -269,6 +269,7 @@ testClient(async function bpcharNestedArray() { }); testClient(async function jsonArray() { + // deno-lint-ignore camelcase const json_array = await CLIENT.query( `SELECT ARRAY_AGG(A) FROM ( SELECT JSON_BUILD_OBJECT( 'X', '1' ) AS A @@ -279,6 +280,7 @@ testClient(async function jsonArray() { assertEquals(json_array.rows[0][0], [{ X: "1" }, { Y: "2" }]); + // deno-lint-ignore camelcase const json_array_nested = await CLIENT.query( `SELECT ARRAY[ARRAY[ARRAY_AGG(A), ARRAY_AGG(A)], ARRAY[ARRAY_AGG(A), ARRAY_AGG(A)]] FROM ( SELECT JSON_BUILD_OBJECT( 'X', '1' ) AS A diff --git a/tests/encode.ts b/tests/encode.ts index aa48df41..ddc89be6 100644 --- a/tests/encode.ts +++ b/tests/encode.ts @@ -63,7 +63,9 @@ test("encodeObject", function () { }); test("encodeUint8Array", function () { + // deno-lint-ignore camelcase const buf_1 = new Uint8Array([1, 2, 3]); + // deno-lint-ignore camelcase const buf_2 = new Uint8Array([2, 10, 500]); assertEquals("\\x010203", encode(buf_1)); diff --git a/tests/helpers.ts b/tests/helpers.ts index 8d037e9a..2cb51ca2 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -4,7 +4,7 @@ export function getTestClient( client: Client, defSetupQueries?: Array, ) { - return async function testClient( + return function testClient( t: Deno.TestDefinition["fn"], setupQueries?: Array, ) { diff --git a/tests/pool.ts b/tests/pool.ts index dd941b76..84705ff8 100644 --- a/tests/pool.ts +++ b/tests/pool.ts @@ -3,7 +3,7 @@ import { Pool } from "../pool.ts"; import { delay } from "../utils.ts"; import { DEFAULT_SETUP, TEST_CONNECTION_PARAMS } from "./constants.ts"; -async function testPool( +function testPool( t: (pool: Pool) => void | Promise, setupQueries?: Array | null, lazy?: boolean, @@ -63,9 +63,11 @@ testPool( await p; assertEquals(POOL.available, 1); + // deno-lint-ignore camelcase const qs_thunks = [...Array(25)].map((_, i) => POOL.query("SELECT pg_sleep(0.1) is null, $1::text as id;", i) ); + // deno-lint-ignore camelcase const qs_promises = Promise.all(qs_thunks); await delay(1); assertEquals(POOL.available, 0); @@ -101,9 +103,11 @@ testPool(async function manyQueries(POOL) { await p; assertEquals(POOL.available, 10); + // deno-lint-ignore camelcase const qs_thunks = [...Array(25)].map((_, i) => POOL.query("SELECT pg_sleep(0.1) is null, $1::text as id;", i) ); + // deno-lint-ignore camelcase const qs_promises = Promise.all(qs_thunks); await delay(1); assertEquals(POOL.available, 0); diff --git a/utils.ts b/utils.ts index d4f3e640..ce7b80da 100644 --- a/utils.ts +++ b/utils.ts @@ -73,6 +73,7 @@ export interface DsnResult { export function parseDsn(dsn: string): DsnResult { //URL object won't parse the URL if it doesn't recognize the protocol //This line replaces the protocol with http and then leaves it up to URL + // deno-lint-ignore camelcase const [protocol, stripped_url] = dsn.match(/(?:(?!:\/\/).)+/g) ?? ["", ""]; const url = new URL(`http:${stripped_url}`); From 986f04f3afcee57e81d16d1cd5244a59d9545852 Mon Sep 17 00:00:00 2001 From: Nicolas Guerrero Date: Wed, 9 Dec 2020 15:30:43 -0500 Subject: [PATCH 5/7] Fmt --- utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils.ts b/utils.ts index ce7b80da..f9cc9481 100644 --- a/utils.ts +++ b/utils.ts @@ -91,10 +91,10 @@ export function parseDsn(dsn: string): DsnResult { export function delay(ms: number): Promise; export function delay(ms: number, value: T): Promise; -export function delay(ms: number, value?: unknown){ +export function delay(ms: number, value?: unknown) { return new Promise((resolve) => { setTimeout(() => { resolve(value); }, ms); }); -} \ No newline at end of file +} From 02ed613da09de053ebbd395c96cf8338fe612a0c Mon Sep 17 00:00:00 2001 From: Nicolas Guerrero Date: Wed, 9 Dec 2020 19:25:44 -0500 Subject: [PATCH 6/7] Revert "Fix lint warnings" This reverts commit cdf7e48b5736e810f1677061d72021010f6e39a3. --- array_parser.ts | 2 +- decode.ts | 6 +++--- encode.ts | 4 ++-- oid.ts | 21 --------------------- tests/data_types.ts | 2 -- tests/encode.ts | 2 -- tests/helpers.ts | 2 +- tests/pool.ts | 6 +----- utils.ts | 1 - 9 files changed, 8 insertions(+), 38 deletions(-) diff --git a/array_parser.ts b/array_parser.ts index ee3361e8..da42f962 100644 --- a/array_parser.ts +++ b/array_parser.ts @@ -79,7 +79,7 @@ class ArrayParser { consumeDimensions(): void { if (this.source[0] === "[") { while (!this.isEof()) { - const char = this.nextCharacter(); + let char = this.nextCharacter(); if (char.value === "=") break; } } diff --git a/decode.ts b/decode.ts index 05151580..3e32098f 100644 --- a/decode.ts +++ b/decode.ts @@ -139,8 +139,8 @@ function decodeBytea(byteaStr: string): Uint8Array { } function decodeByteaHex(byteaStr: string): Uint8Array { - const bytesStr = byteaStr.slice(2); - const bytes = new Uint8Array(bytesStr.length / 2); + let bytesStr = byteaStr.slice(2); + let bytes = new Uint8Array(bytesStr.length / 2); for (let i = 0, j = 0; i < bytesStr.length; i += 2, j++) { bytes[j] = parseInt(bytesStr[i] + bytesStr[i + 1], HEX); } @@ -148,7 +148,7 @@ function decodeByteaHex(byteaStr: string): Uint8Array { } function decodeByteaEscape(byteaStr: string): Uint8Array { - const bytes = []; + let bytes = []; let i = 0; let k = 0; while (i < byteaStr.length) { diff --git a/encode.ts b/encode.ts index 50e35dee..43b16f61 100644 --- a/encode.ts +++ b/encode.ts @@ -41,7 +41,7 @@ function encodeDate(date: Date): string { function escapeArrayElement(value: unknown): string { // deno-lint-ignore no-explicit-any - const strValue = (value as any).toString(); + let strValue = (value as any).toString(); const escapedValue = strValue.replace(/\\/g, "\\\\").replace(/"/g, '\\"'); return `"${escapedValue}"`; @@ -73,7 +73,7 @@ function encodeArray(array: Array): string { } function encodeBytes(value: Uint8Array): string { - const hex = Array.from(value) + let hex = Array.from(value) .map((val) => (val < 10 ? `0${val.toString(16)}` : val.toString(16))) .join(""); return `\\x${hex}`; diff --git a/oid.ts b/oid.ts index 3a68f7ba..300407d8 100644 --- a/oid.ts +++ b/oid.ts @@ -14,25 +14,17 @@ export const Oid = { xid: 28, cid: 29, oidvector: 30, - // deno-lint-ignore camelcase pg_ddl_command: 32, - // deno-lint-ignore camelcase pg_type: 71, - // deno-lint-ignore camelcase pg_attribute: 75, - // deno-lint-ignore camelcase pg_proc: 81, - // deno-lint-ignore camelcase pg_class: 83, json: 114, xml: 142, _xml: 143, - // deno-lint-ignore camelcase pg_node_tree: 194, - // deno-lint-ignore camelcase json_array: 199, smgr: 210, - // deno-lint-ignore camelcase index_am_handler: 325, point: 600, lseg: 601, @@ -99,7 +91,6 @@ export const Oid = { interval: 1186, _interval: 1187, _numeric: 1231, - // deno-lint-ignore camelcase pg_database: 1248, _cstring: 1263, timetz: 1266, @@ -127,30 +118,21 @@ export const Oid = { anyarray: 2277, void: 2278, trigger: 2279, - // deno-lint-ignore camelcase language_handler: 2280, internal: 2281, opaque: 2282, anyelement: 2283, _record: 2287, anynonarray: 2776, - // deno-lint-ignore camelcase pg_authid: 2842, - // deno-lint-ignore camelcase pg_auth_members: 2843, - // deno-lint-ignore camelcase _txid_snapshot: 2949, uuid: 2950, _uuid: 2951, - // deno-lint-ignore camelcase txid_snapshot: 2970, - // deno-lint-ignore camelcase fdw_handler: 3115, - // deno-lint-ignore camelcase pg_lsn: 3220, - // deno-lint-ignore camelcase _pg_lsn: 3221, - // deno-lint-ignore camelcase tsm_handler: 3310, anyenum: 3500, tsvector: 3614, @@ -164,10 +146,8 @@ export const Oid = { regdictionary: 3769, _regdictionary: 3770, jsonb: 3802, - // deno-lint-ignore camelcase jsonb_array: 3807, anyrange: 3831, - // deno-lint-ignore camelcase event_trigger: 3838, int4range: 3904, _int4range: 3905, @@ -181,7 +161,6 @@ export const Oid = { _daterange: 3913, int8range: 3926, _int8range: 3927, - // deno-lint-ignore camelcase pg_shseclabel: 4066, regnamespace: 4089, _regnamespace: 4090, diff --git a/tests/data_types.ts b/tests/data_types.ts index 94a4cf6d..e30a185b 100644 --- a/tests/data_types.ts +++ b/tests/data_types.ts @@ -269,7 +269,6 @@ testClient(async function bpcharNestedArray() { }); testClient(async function jsonArray() { - // deno-lint-ignore camelcase const json_array = await CLIENT.query( `SELECT ARRAY_AGG(A) FROM ( SELECT JSON_BUILD_OBJECT( 'X', '1' ) AS A @@ -280,7 +279,6 @@ testClient(async function jsonArray() { assertEquals(json_array.rows[0][0], [{ X: "1" }, { Y: "2" }]); - // deno-lint-ignore camelcase const json_array_nested = await CLIENT.query( `SELECT ARRAY[ARRAY[ARRAY_AGG(A), ARRAY_AGG(A)], ARRAY[ARRAY_AGG(A), ARRAY_AGG(A)]] FROM ( SELECT JSON_BUILD_OBJECT( 'X', '1' ) AS A diff --git a/tests/encode.ts b/tests/encode.ts index ddc89be6..aa48df41 100644 --- a/tests/encode.ts +++ b/tests/encode.ts @@ -63,9 +63,7 @@ test("encodeObject", function () { }); test("encodeUint8Array", function () { - // deno-lint-ignore camelcase const buf_1 = new Uint8Array([1, 2, 3]); - // deno-lint-ignore camelcase const buf_2 = new Uint8Array([2, 10, 500]); assertEquals("\\x010203", encode(buf_1)); diff --git a/tests/helpers.ts b/tests/helpers.ts index 2cb51ca2..8d037e9a 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -4,7 +4,7 @@ export function getTestClient( client: Client, defSetupQueries?: Array, ) { - return function testClient( + return async function testClient( t: Deno.TestDefinition["fn"], setupQueries?: Array, ) { diff --git a/tests/pool.ts b/tests/pool.ts index 84705ff8..dd941b76 100644 --- a/tests/pool.ts +++ b/tests/pool.ts @@ -3,7 +3,7 @@ import { Pool } from "../pool.ts"; import { delay } from "../utils.ts"; import { DEFAULT_SETUP, TEST_CONNECTION_PARAMS } from "./constants.ts"; -function testPool( +async function testPool( t: (pool: Pool) => void | Promise, setupQueries?: Array | null, lazy?: boolean, @@ -63,11 +63,9 @@ testPool( await p; assertEquals(POOL.available, 1); - // deno-lint-ignore camelcase const qs_thunks = [...Array(25)].map((_, i) => POOL.query("SELECT pg_sleep(0.1) is null, $1::text as id;", i) ); - // deno-lint-ignore camelcase const qs_promises = Promise.all(qs_thunks); await delay(1); assertEquals(POOL.available, 0); @@ -103,11 +101,9 @@ testPool(async function manyQueries(POOL) { await p; assertEquals(POOL.available, 10); - // deno-lint-ignore camelcase const qs_thunks = [...Array(25)].map((_, i) => POOL.query("SELECT pg_sleep(0.1) is null, $1::text as id;", i) ); - // deno-lint-ignore camelcase const qs_promises = Promise.all(qs_thunks); await delay(1); assertEquals(POOL.available, 0); diff --git a/utils.ts b/utils.ts index f9cc9481..9d8c4828 100644 --- a/utils.ts +++ b/utils.ts @@ -73,7 +73,6 @@ export interface DsnResult { export function parseDsn(dsn: string): DsnResult { //URL object won't parse the URL if it doesn't recognize the protocol //This line replaces the protocol with http and then leaves it up to URL - // deno-lint-ignore camelcase const [protocol, stripped_url] = dsn.match(/(?:(?!:\/\/).)+/g) ?? ["", ""]; const url = new URL(`http:${stripped_url}`); From 6cf686ee6afbee7c1b8a7e87e25b11c013692ff2 Mon Sep 17 00:00:00 2001 From: Nicolas Guerrero Date: Wed, 9 Dec 2020 19:31:42 -0500 Subject: [PATCH 7/7] Fix linting problems and rename --- array_parser.ts | 2 +- decode.ts | 6 +++--- encode.ts | 4 ++-- oid.ts | 21 +++++++++++++++++++++ tests/data_types.ts | 8 ++++---- tests/encode.ts | 8 ++++---- tests/helpers.ts | 2 +- tests/pool.ts | 14 +++++++------- utils.ts | 4 ++-- 9 files changed, 45 insertions(+), 24 deletions(-) diff --git a/array_parser.ts b/array_parser.ts index da42f962..ee3361e8 100644 --- a/array_parser.ts +++ b/array_parser.ts @@ -79,7 +79,7 @@ class ArrayParser { consumeDimensions(): void { if (this.source[0] === "[") { while (!this.isEof()) { - let char = this.nextCharacter(); + const char = this.nextCharacter(); if (char.value === "=") break; } } diff --git a/decode.ts b/decode.ts index 3e32098f..05151580 100644 --- a/decode.ts +++ b/decode.ts @@ -139,8 +139,8 @@ function decodeBytea(byteaStr: string): Uint8Array { } function decodeByteaHex(byteaStr: string): Uint8Array { - let bytesStr = byteaStr.slice(2); - let bytes = new Uint8Array(bytesStr.length / 2); + const bytesStr = byteaStr.slice(2); + const bytes = new Uint8Array(bytesStr.length / 2); for (let i = 0, j = 0; i < bytesStr.length; i += 2, j++) { bytes[j] = parseInt(bytesStr[i] + bytesStr[i + 1], HEX); } @@ -148,7 +148,7 @@ function decodeByteaHex(byteaStr: string): Uint8Array { } function decodeByteaEscape(byteaStr: string): Uint8Array { - let bytes = []; + const bytes = []; let i = 0; let k = 0; while (i < byteaStr.length) { diff --git a/encode.ts b/encode.ts index 43b16f61..50e35dee 100644 --- a/encode.ts +++ b/encode.ts @@ -41,7 +41,7 @@ function encodeDate(date: Date): string { function escapeArrayElement(value: unknown): string { // deno-lint-ignore no-explicit-any - let strValue = (value as any).toString(); + const strValue = (value as any).toString(); const escapedValue = strValue.replace(/\\/g, "\\\\").replace(/"/g, '\\"'); return `"${escapedValue}"`; @@ -73,7 +73,7 @@ function encodeArray(array: Array): string { } function encodeBytes(value: Uint8Array): string { - let hex = Array.from(value) + const hex = Array.from(value) .map((val) => (val < 10 ? `0${val.toString(16)}` : val.toString(16))) .join(""); return `\\x${hex}`; diff --git a/oid.ts b/oid.ts index 300407d8..3a68f7ba 100644 --- a/oid.ts +++ b/oid.ts @@ -14,17 +14,25 @@ export const Oid = { xid: 28, cid: 29, oidvector: 30, + // deno-lint-ignore camelcase pg_ddl_command: 32, + // deno-lint-ignore camelcase pg_type: 71, + // deno-lint-ignore camelcase pg_attribute: 75, + // deno-lint-ignore camelcase pg_proc: 81, + // deno-lint-ignore camelcase pg_class: 83, json: 114, xml: 142, _xml: 143, + // deno-lint-ignore camelcase pg_node_tree: 194, + // deno-lint-ignore camelcase json_array: 199, smgr: 210, + // deno-lint-ignore camelcase index_am_handler: 325, point: 600, lseg: 601, @@ -91,6 +99,7 @@ export const Oid = { interval: 1186, _interval: 1187, _numeric: 1231, + // deno-lint-ignore camelcase pg_database: 1248, _cstring: 1263, timetz: 1266, @@ -118,21 +127,30 @@ export const Oid = { anyarray: 2277, void: 2278, trigger: 2279, + // deno-lint-ignore camelcase language_handler: 2280, internal: 2281, opaque: 2282, anyelement: 2283, _record: 2287, anynonarray: 2776, + // deno-lint-ignore camelcase pg_authid: 2842, + // deno-lint-ignore camelcase pg_auth_members: 2843, + // deno-lint-ignore camelcase _txid_snapshot: 2949, uuid: 2950, _uuid: 2951, + // deno-lint-ignore camelcase txid_snapshot: 2970, + // deno-lint-ignore camelcase fdw_handler: 3115, + // deno-lint-ignore camelcase pg_lsn: 3220, + // deno-lint-ignore camelcase _pg_lsn: 3221, + // deno-lint-ignore camelcase tsm_handler: 3310, anyenum: 3500, tsvector: 3614, @@ -146,8 +164,10 @@ export const Oid = { regdictionary: 3769, _regdictionary: 3770, jsonb: 3802, + // deno-lint-ignore camelcase jsonb_array: 3807, anyrange: 3831, + // deno-lint-ignore camelcase event_trigger: 3838, int4range: 3904, _int4range: 3905, @@ -161,6 +181,7 @@ export const Oid = { _daterange: 3913, int8range: 3926, _int8range: 3927, + // deno-lint-ignore camelcase pg_shseclabel: 4066, regnamespace: 4089, _regnamespace: 4090, diff --git a/tests/data_types.ts b/tests/data_types.ts index e30a185b..83c706c0 100644 --- a/tests/data_types.ts +++ b/tests/data_types.ts @@ -269,7 +269,7 @@ testClient(async function bpcharNestedArray() { }); testClient(async function jsonArray() { - const json_array = await CLIENT.query( + const jsonArray = await CLIENT.query( `SELECT ARRAY_AGG(A) FROM ( SELECT JSON_BUILD_OBJECT( 'X', '1' ) AS A UNION ALL @@ -277,9 +277,9 @@ testClient(async function jsonArray() { ) A`, ); - assertEquals(json_array.rows[0][0], [{ X: "1" }, { Y: "2" }]); + assertEquals(jsonArray.rows[0][0], [{ X: "1" }, { Y: "2" }]); - const json_array_nested = await CLIENT.query( + const jsonArrayNested = await CLIENT.query( `SELECT ARRAY[ARRAY[ARRAY_AGG(A), ARRAY_AGG(A)], ARRAY[ARRAY_AGG(A), ARRAY_AGG(A)]] FROM ( SELECT JSON_BUILD_OBJECT( 'X', '1' ) AS A UNION ALL @@ -288,7 +288,7 @@ testClient(async function jsonArray() { ); assertEquals( - json_array_nested.rows[0][0], + jsonArrayNested.rows[0][0], [ [ [{ X: "1" }, { Y: "2" }], diff --git a/tests/encode.ts b/tests/encode.ts index aa48df41..e927600c 100644 --- a/tests/encode.ts +++ b/tests/encode.ts @@ -63,11 +63,11 @@ test("encodeObject", function () { }); test("encodeUint8Array", function () { - const buf_1 = new Uint8Array([1, 2, 3]); - const buf_2 = new Uint8Array([2, 10, 500]); + const buf1 = new Uint8Array([1, 2, 3]); + const buf2 = new Uint8Array([2, 10, 500]); - assertEquals("\\x010203", encode(buf_1)); - assertEquals("\\x02af4", encode(buf_2)); + assertEquals("\\x010203", encode(buf1)); + assertEquals("\\x02af4", encode(buf2)); }); test("encodeArray", function () { diff --git a/tests/helpers.ts b/tests/helpers.ts index 8d037e9a..2cb51ca2 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -4,7 +4,7 @@ export function getTestClient( client: Client, defSetupQueries?: Array, ) { - return async function testClient( + return function testClient( t: Deno.TestDefinition["fn"], setupQueries?: Array, ) { diff --git a/tests/pool.ts b/tests/pool.ts index dd941b76..1dfe0cfd 100644 --- a/tests/pool.ts +++ b/tests/pool.ts @@ -3,7 +3,7 @@ import { Pool } from "../pool.ts"; import { delay } from "../utils.ts"; import { DEFAULT_SETUP, TEST_CONNECTION_PARAMS } from "./constants.ts"; -async function testPool( +function testPool( t: (pool: Pool) => void | Promise, setupQueries?: Array | null, lazy?: boolean, @@ -63,13 +63,13 @@ testPool( await p; assertEquals(POOL.available, 1); - const qs_thunks = [...Array(25)].map((_, i) => + const qsThunks = [...Array(25)].map((_, i) => POOL.query("SELECT pg_sleep(0.1) is null, $1::text as id;", i) ); - const qs_promises = Promise.all(qs_thunks); + const qsPromises = Promise.all(qsThunks); await delay(1); assertEquals(POOL.available, 0); - const qs = await qs_promises; + const qs = await qsPromises; assertEquals(POOL.available, 10); assertEquals(POOL.size, 10); @@ -101,13 +101,13 @@ testPool(async function manyQueries(POOL) { await p; assertEquals(POOL.available, 10); - const qs_thunks = [...Array(25)].map((_, i) => + const qsThunks = [...Array(25)].map((_, i) => POOL.query("SELECT pg_sleep(0.1) is null, $1::text as id;", i) ); - const qs_promises = Promise.all(qs_thunks); + const qsPromises = Promise.all(qsThunks); await delay(1); assertEquals(POOL.available, 0); - const qs = await qs_promises; + const qs = await qsPromises; assertEquals(POOL.available, 10); assertEquals(POOL.size, 10); diff --git a/utils.ts b/utils.ts index 9d8c4828..08d01144 100644 --- a/utils.ts +++ b/utils.ts @@ -73,8 +73,8 @@ export interface DsnResult { export function parseDsn(dsn: string): DsnResult { //URL object won't parse the URL if it doesn't recognize the protocol //This line replaces the protocol with http and then leaves it up to URL - const [protocol, stripped_url] = dsn.match(/(?:(?!:\/\/).)+/g) ?? ["", ""]; - const url = new URL(`http:${stripped_url}`); + const [protocol, strippedUrl] = dsn.match(/(?:(?!:\/\/).)+/g) ?? ["", ""]; + const url = new URL(`http:${strippedUrl}`); return { driver: protocol,