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 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/deps.ts b/deps.ts index fdb5cc5b..32c38737 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 } 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/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/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; } 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/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 c473af63..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, @@ -88,8 +88,10 @@ 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);