diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5a8f84..5921e1e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: ci -on: [ push, pull_request, release ] +on: [push, pull_request, release] jobs: code_quality: @@ -12,11 +12,11 @@ jobs: - name: Setup Deno uses: denoland/setup-deno@v1 with: - deno-version: v1.x - + deno-version: v2.x + - name: Format run: deno fmt --check - + - name: Lint run: deno lint @@ -31,7 +31,7 @@ jobs: - name: Build tests container run: docker compose build tests - + - name: Run tests run: docker compose run tests @@ -51,7 +51,7 @@ jobs: no_typecheck_status: ${{ steps.no_typecheck_status.outputs.status }} report_warnings: - needs: [ code_quality, test ] + needs: [code_quality, test] runs-on: ubuntu-latest steps: - name: Set no-typecheck fail comment @@ -70,4 +70,4 @@ jobs:

             ${{ needs.test.outputs.no_typecheck }}
               
- \ No newline at end of file + diff --git a/.github/workflows/publish_jsr.yml b/.github/workflows/publish_jsr.yml index 18d6114..d98bad6 100644 --- a/.github/workflows/publish_jsr.yml +++ b/.github/workflows/publish_jsr.yml @@ -22,13 +22,15 @@ jobs: - name: Set up Deno uses: denoland/setup-deno@v1 - + with: + deno-version: v2.x + - name: Check Format run: deno fmt --check - name: Format run: deno fmt - + - name: Lint run: deno lint @@ -37,7 +39,7 @@ jobs: - name: Build tests container run: docker compose build tests - + - name: Run tests run: docker compose run tests diff --git a/Dockerfile b/Dockerfile index 131495f..a94a5e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM denoland/deno:alpine-1.40.3 +FROM denoland/deno:alpine-2.1.4 WORKDIR /app # Install wait utility diff --git a/client/error.ts b/client/error.ts index 35d0599..fa75998 100644 --- a/client/error.ts +++ b/client/error.ts @@ -20,7 +20,7 @@ export class ConnectionParamsError extends Error { /** * Create a new ConnectionParamsError */ - constructor(message: string, cause?: Error) { + constructor(message: string, cause?: unknown) { super(message, { cause }); this.name = "ConnectionParamsError"; } diff --git a/connection/connection.ts b/connection/connection.ts index a43ab1c..69a9615 100644 --- a/connection/connection.ts +++ b/connection/connection.ts @@ -373,7 +373,7 @@ export class Connection { if (!tls_enforced) { console.error( bold(yellow("TLS connection failed with message: ")) + - e.message + + (e as Error).message + "\n" + bold("Defaulting to non-encrypted connection"), ); @@ -474,7 +474,7 @@ export class Connection { let reconnection_attempts = 0; const max_reconnections = this.#connection_params.connection.attempts; - let error: Error | undefined; + let error: unknown | undefined; // If no connection has been established and the reconnection attempts are // set to zero, attempt to connect at least once if (!is_reconnection && this.#connection_params.connection.attempts === 0) { @@ -692,7 +692,7 @@ export class Connection { result = new QueryObjectResult(query); } - let error: Error | undefined; + let error: unknown | undefined; let current_message = await this.#readMessage(); // Process messages until ready signal is sent @@ -887,7 +887,7 @@ export class Connection { result = new QueryObjectResult(query); } - let error: Error | undefined; + let error: unknown | undefined; let current_message = await this.#readMessage(); while (current_message.type !== INCOMING_QUERY_MESSAGES.READY) { diff --git a/deno.json b/deno.json index e693e9e..49a4d61 100644 --- a/deno.json +++ b/deno.json @@ -3,14 +3,12 @@ "version": "0.19.4", "exports": "./mod.ts", "imports": { - "@std/async/delay": "jsr:@std/async@^1.0.3/delay", - "@std/bytes/copy": "jsr:@std/bytes@^1.0.2/copy", - "@std/crypto/crypto": "jsr:@std/crypto@^1.0.2/crypto", - "@std/datetime/parse": "jsr:@std/datetime@^0.225.0/parse", - "@std/encoding/base64": "jsr:@std/encoding@^1.0.2/base64", - "@std/encoding/hex": "jsr:@std/encoding@^1.0.2/hex", - "@std/fmt/colors": "jsr:@std/fmt@^1.0.0/colors", - "@std/path": "jsr:@std/path@^1.0.2" + "@std/async": "jsr:@std/async@^1.0.9", + "@std/bytes": "jsr:@std/bytes@^1.0.4", + "@std/crypto": "jsr:@std/crypto@^1.0.3", + "@std/encoding": "jsr:@std/encoding@^1.0.6", + "@std/fmt": "jsr:@std/fmt@^1.0.3", + "@std/path": "jsr:@std/path@^1.0.8" }, "lock": false } diff --git a/docker-compose.yml b/docker-compose.yml index 4981d43..e49dc01 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,7 +30,7 @@ services: - /var/run/postgres_clear:/var/run/postgresql ports: - "6000:6000" - + postgres_md5: image: postgres:14 hostname: postgres_md5 @@ -56,7 +56,7 @@ services: - /var/run/postgres_scram:/var/run/postgresql ports: - "6002:6002" - + tests: build: . # Name the image to be reused in no_check_tests @@ -78,4 +78,4 @@ services: environment: <<: *test-env NO_COLOR: "true" - volumes: *test-volumes \ No newline at end of file + volumes: *test-volumes diff --git a/docs/index.html b/docs/index.html index 4ce33e9..89c6b93 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,22 +1,30 @@ - - - Deno Postgres - - - - - - -
- - - - + + + Deno Postgres + + + + + + +
+ + + + diff --git a/query/decode.ts b/query/decode.ts index cc13e7d..0543e86 100644 --- a/query/decode.ts +++ b/query/decode.ts @@ -199,7 +199,7 @@ function decodeText(value: string, typeOid: number) { } catch (_e) { console.error( bold(yellow(`Error decoding type Oid ${typeOid} value`)) + - _e.message + + (_e as Error).message + "\n" + bold("Defaulting to null."), ); diff --git a/query/decoders.ts b/query/decoders.ts index 6cf3278..434ecd7 100644 --- a/query/decoders.ts +++ b/query/decoders.ts @@ -1,4 +1,3 @@ -import { parse as parseDate } from "@std/datetime/parse"; import { parseArray } from "./array_parser.ts"; import type { Box, @@ -64,7 +63,7 @@ export function decodeBox(value: string): Box { b: decodePoint(b), }; } catch (e) { - throw new Error(`Invalid Box: "${value}" : ${e.message}`); + throw new Error(`Invalid Box: "${value}" : ${(e as Error).message}`); } } @@ -140,7 +139,7 @@ export function decodeCircle(value: string): Circle { radius: radius, }; } catch (e) { - throw new Error(`Invalid Circle: "${value}" : ${e.message}`); + throw new Error(`Invalid Circle: "${value}" : ${(e as Error).message}`); } } @@ -157,7 +156,7 @@ export function decodeDate(dateStr: string): Date | number { return Number(-Infinity); } - return parseDate(dateStr, "yyyy-MM-dd"); + return new Date(dateStr); } export function decodeDateArray(value: string) { @@ -287,7 +286,9 @@ export function decodeLineSegment(value: string): LineSegment { b: decodePoint(b), }; } catch (e) { - throw new Error(`Invalid Line Segment: "${value}" : ${e.message}`); + throw new Error( + `Invalid Line Segment: "${value}" : ${(e as Error).message}`, + ); } } @@ -304,7 +305,7 @@ export function decodePath(value: string): Path { try { return decodePoint(point); } catch (e) { - throw new Error(`Invalid Path: "${value}" : ${e.message}`); + throw new Error(`Invalid Path: "${value}" : ${(e as Error).message}`); } }); } @@ -348,7 +349,7 @@ export function decodePolygon(value: string): Polygon { try { return decodePath(value); } catch (e) { - throw new Error(`Invalid Polygon: "${value}" : ${e.message}`); + throw new Error(`Invalid Polygon: "${value}" : ${(e as Error).message}`); } } diff --git a/query/query.ts b/query/query.ts index fa4eae8..3c2d888 100644 --- a/query/query.ts +++ b/query/query.ts @@ -155,7 +155,7 @@ export interface QueryObjectOptions extends QueryOptions { /** * This class is used to handle the result of a query */ -export class QueryResult { +export abstract class QueryResult { /** * Type of query executed for this result */ @@ -225,9 +225,7 @@ export class QueryResult { * * This function can throw on validation, so any errors must be handled in the message loop accordingly */ - insertRow(_row: Uint8Array[]): void { - throw new Error("No implementation for insertRow is defined"); - } + abstract insertRow(_row: Uint8Array[]): void; } /** diff --git a/tests/auth_test.ts b/tests/auth_test.ts index f7ed38d..4b06120 100644 --- a/tests/auth_test.ts +++ b/tests/auth_test.ts @@ -1,4 +1,8 @@ -import { assertEquals, assertNotEquals, assertRejects } from "./test_deps.ts"; +import { + assertEquals, + assertNotEquals, + assertRejects, +} from "jsr:@std/assert@1.0.10"; import { Client as ScramClient, Reason } from "../connection/scram.ts"; Deno.test("Scram client reproduces RFC 7677 example", async () => { diff --git a/tests/connection_params_test.ts b/tests/connection_params_test.ts index 1bb08b0..94df433 100644 --- a/tests/connection_params_test.ts +++ b/tests/connection_params_test.ts @@ -1,4 +1,4 @@ -import { assertEquals, assertThrows } from "./test_deps.ts"; +import { assertEquals, assertThrows } from "jsr:@std/assert@1.0.10"; import { fromFileUrl } from "@std/path"; import { createParams } from "../connection/connection_params.ts"; import { ConnectionParamsError } from "../client/error.ts"; diff --git a/tests/connection_test.ts b/tests/connection_test.ts index 8a34019..5b94d27 100644 --- a/tests/connection_test.ts +++ b/tests/connection_test.ts @@ -1,4 +1,4 @@ -import { assertEquals, assertRejects, copyStream } from "./test_deps.ts"; +import { assertEquals, assertRejects } from "jsr:@std/assert@1.0.10"; import { join as joinPath } from "@std/path"; import { getClearConfiguration, @@ -32,10 +32,8 @@ function createProxy( outbound.close(); aborted = true; }); - await Promise.all([ - copyStream(conn, outbound), - copyStream(outbound, conn), - ]).catch(() => {}); + await conn.readable.pipeTo(outbound.writable, { preventClose: true }); + await outbound.readable.pipeTo(conn.writable, { preventClose: true }); if (!aborted) { conn.close(); @@ -397,7 +395,7 @@ Deno.test("Closes connection on bad TLS availability verification", async functi await client.connect(); } catch (e) { if ( - e instanceof Error || + e instanceof Error && e.message.startsWith("Could not check if server accepts SSL connections") ) { bad_tls_availability_message = true; diff --git a/tests/data_types_test.ts b/tests/data_types_test.ts index 7cbd22c..1dc1c46 100644 --- a/tests/data_types_test.ts +++ b/tests/data_types_test.ts @@ -1,5 +1,4 @@ -import { assertEquals, formatDate } from "./test_deps.ts"; -import { parse as parseDate } from "@std/datetime/parse"; +import { assertEquals } from "jsr:@std/assert@1.0.10"; import { decodeBase64, encodeBase64 } from "@std/encoding/base64"; import { getMainConfiguration } from "./config.ts"; import { generateSimpleClientTest } from "./helpers.ts"; @@ -933,7 +932,7 @@ Deno.test( ); assertEquals(result.rows[0], [ - parseDate(date_text, "yyyy-MM-dd"), + new Date(date_text), Infinity, ]); }), @@ -943,7 +942,7 @@ Deno.test( "date array", testClient(async (client) => { await client.queryArray(`SET SESSION TIMEZONE TO '${timezone}'`); - const dates = ["2020-01-01", formatDate(new Date(), "yyyy-MM-dd")]; + const dates = ["2020-01-01", (new Date()).toISOString().split("T")[0]]; const { rows: result } = await client.queryArray<[[Date, Date]]>( "SELECT ARRAY[$1::DATE, $2]", @@ -952,7 +951,7 @@ Deno.test( assertEquals( result[0][0], - dates.map((d) => parseDate(d, "yyyy-MM-dd")), + dates.map((d) => new Date(d)), ); }), ); diff --git a/tests/decode_test.ts b/tests/decode_test.ts index 0651291..b2f0657 100644 --- a/tests/decode_test.ts +++ b/tests/decode_test.ts @@ -17,7 +17,7 @@ import { decodePoint, decodeTid, } from "../query/decoders.ts"; -import { assertEquals, assertThrows } from "./test_deps.ts"; +import { assertEquals, assertThrows } from "jsr:@std/assert@1.0.10"; import { Oid } from "../query/oid.ts"; Deno.test("decodeBigint", function () { diff --git a/tests/encode_test.ts b/tests/encode_test.ts index 784fdaa..eab2186 100644 --- a/tests/encode_test.ts +++ b/tests/encode_test.ts @@ -1,4 +1,4 @@ -import { assertEquals } from "./test_deps.ts"; +import { assertEquals } from "jsr:@std/assert@1.0.10"; import { encodeArgument } from "../query/encode.ts"; // internally `encodeArguments` uses `getTimezoneOffset` to encode Date diff --git a/tests/pool_test.ts b/tests/pool_test.ts index 5934bd7..d5a9981 100644 --- a/tests/pool_test.ts +++ b/tests/pool_test.ts @@ -1,4 +1,4 @@ -import { assertEquals } from "./test_deps.ts"; +import { assertEquals } from "jsr:@std/assert@1.0.10"; import { delay } from "@std/async/delay"; import { getMainConfiguration } from "./config.ts"; import { generatePoolClientTest } from "./helpers.ts"; diff --git a/tests/query_client_test.ts b/tests/query_client_test.ts index abc7332..26966de 100644 --- a/tests/query_client_test.ts +++ b/tests/query_client_test.ts @@ -12,7 +12,7 @@ import { assertObjectMatch, assertRejects, assertThrows, -} from "./test_deps.ts"; +} from "jsr:@std/assert@1.0.10"; import { getMainConfiguration } from "./config.ts"; import type { PoolClient, QueryClient } from "../client.ts"; import type { ClientOptions } from "../connection/connection_params.ts"; diff --git a/tests/test_deps.ts b/tests/test_deps.ts index 788e687..cb56ee5 100644 --- a/tests/test_deps.ts +++ b/tests/test_deps.ts @@ -6,6 +6,4 @@ export { assertObjectMatch, assertRejects, assertThrows, -} from "https://deno.land/std@0.214.0/assert/mod.ts"; -export { format as formatDate } from "https://deno.land/std@0.214.0/datetime/format.ts"; -export { copy as copyStream } from "https://deno.land/std@0.214.0/io/copy.ts"; +} from "jsr:@std/assert@1.0.10"; diff --git a/tests/utils_test.ts b/tests/utils_test.ts index 1491831..40542ea 100644 --- a/tests/utils_test.ts +++ b/tests/utils_test.ts @@ -1,4 +1,4 @@ -import { assertEquals, assertThrows } from "./test_deps.ts"; +import { assertEquals, assertThrows } from "jsr:@std/assert@1.0.10"; import { parseConnectionUri, type Uri } from "../utils/utils.ts"; import { DeferredAccessStack, DeferredStack } from "../utils/deferred.ts";