Skip to content

Commit

Permalink
Deno 2 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
williamhorning committed Dec 21, 2024
1 parent 677fdf0 commit 341f200
Show file tree
Hide file tree
Showing 21 changed files with 85 additions and 79 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ci

on: [ push, pull_request, release ]
on: [push, pull_request, release]

jobs:
code_quality:
Expand All @@ -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

Expand All @@ -31,7 +31,7 @@ jobs:

- name: Build tests container
run: docker compose build tests

- name: Run tests
run: docker compose run tests

Expand All @@ -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
Expand All @@ -70,4 +70,4 @@ jobs:
<pre><code>
${{ needs.test.outputs.no_typecheck }}
</code></pre>
</details>
</details>
8 changes: 5 additions & 3 deletions .github/workflows/publish_jsr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -37,7 +39,7 @@ jobs:

- name: Build tests container
run: docker compose build tests

- name: Run tests
run: docker compose run tests

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM denoland/deno:alpine-1.40.3
FROM denoland/deno:alpine-2.1.4
WORKDIR /app

# Install wait utility
Expand Down
2 changes: 1 addition & 1 deletion client/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
8 changes: 4 additions & 4 deletions connection/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 6 additions & 8 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ services:
- /var/run/postgres_clear:/var/run/postgresql
ports:
- "6000:6000"

postgres_md5:
image: postgres:14
hostname: postgres_md5
Expand All @@ -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
Expand All @@ -78,4 +78,4 @@ services:
environment:
<<: *test-env
NO_COLOR: "true"
volumes: *test-volumes
volumes: *test-volumes
46 changes: 27 additions & 19 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Deno Postgres</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="🦕 Lightweight PostgreSQL driver for Deno focused on developer experience">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//unpkg.com/docsify/lib/themes/vue.css">
</head>
<body>
<div id="app"></div>
<script>
window.$docsify = {
name: 'deno-postgres',
repo: 'buildondata/deno-postgres',
}
</script>
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-typescript.min.js"></script>
</body>
<head>
<meta charset="UTF-8">
<title>Deno Postgres</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta
name="description"
content="🦕 Lightweight PostgreSQL driver for Deno focused on developer experience"
>
<meta
name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
>
<link rel="stylesheet" href="//unpkg.com/docsify/lib/themes/vue.css">
</head>
<body>
<div id="app"></div>
<script>
window.$docsify = {
name: "deno-postgres",
repo: "buildondata/deno-postgres",
};
</script>
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
<script
src="//unpkg.com/prismjs/components/prism-typescript.min.js"
></script>
</body>
</html>
2 changes: 1 addition & 1 deletion query/decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
);
Expand Down
15 changes: 8 additions & 7 deletions query/decoders.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { parse as parseDate } from "@std/datetime/parse";
import { parseArray } from "./array_parser.ts";
import type {
Box,
Expand Down Expand Up @@ -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}`);
}
}

Expand Down Expand Up @@ -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}`);
}
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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}`,
);
}
}

Expand All @@ -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}`);
}
});
}
Expand Down Expand Up @@ -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}`);
}
}

Expand Down
6 changes: 2 additions & 4 deletions query/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion tests/auth_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { assertEquals, assertNotEquals, assertRejects } from "./test_deps.ts";
import {
assertEquals,
assertNotEquals,
assertRejects,
} from "jsr:@std/[email protected]";
import { Client as ScramClient, Reason } from "../connection/scram.ts";

Deno.test("Scram client reproduces RFC 7677 example", async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/connection_params_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals, assertThrows } from "./test_deps.ts";
import { assertEquals, assertThrows } from "jsr:@std/[email protected]";
import { fromFileUrl } from "@std/path";
import { createParams } from "../connection/connection_params.ts";
import { ConnectionParamsError } from "../client/error.ts";
Expand Down
10 changes: 4 additions & 6 deletions tests/connection_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals, assertRejects, copyStream } from "./test_deps.ts";
import { assertEquals, assertRejects } from "jsr:@std/[email protected]";
import { join as joinPath } from "@std/path";
import {
getClearConfiguration,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions tests/data_types_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { assertEquals, formatDate } from "./test_deps.ts";
import { parse as parseDate } from "@std/datetime/parse";
import { assertEquals } from "jsr:@std/[email protected]";
import { decodeBase64, encodeBase64 } from "@std/encoding/base64";
import { getMainConfiguration } from "./config.ts";
import { generateSimpleClientTest } from "./helpers.ts";
Expand Down Expand Up @@ -933,7 +932,7 @@ Deno.test(
);

assertEquals(result.rows[0], [
parseDate(date_text, "yyyy-MM-dd"),
new Date(date_text),
Infinity,
]);
}),
Expand All @@ -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]",
Expand All @@ -952,7 +951,7 @@ Deno.test(

assertEquals(
result[0][0],
dates.map((d) => parseDate(d, "yyyy-MM-dd")),
dates.map((d) => new Date(d)),
);
}),
);
Expand Down
2 changes: 1 addition & 1 deletion tests/decode_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
decodePoint,
decodeTid,
} from "../query/decoders.ts";
import { assertEquals, assertThrows } from "./test_deps.ts";
import { assertEquals, assertThrows } from "jsr:@std/[email protected]";
import { Oid } from "../query/oid.ts";

Deno.test("decodeBigint", function () {
Expand Down
Loading

0 comments on commit 341f200

Please sign in to comment.