Skip to content

Commit

Permalink
chore: Upgrade to Deno 1.17 (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
Soremwar committed Jan 15, 2022
1 parent 351f97f commit 9e110a8
Show file tree
Hide file tree
Showing 24 changed files with 837 additions and 900 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -12,13 +12,13 @@ jobs:
- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: 1.16.0
deno-version: 1.17.3

- name: Format
run: deno fmt --check

- name: Lint
run: deno lint --config=deno.json
run: deno lint

- name: Documentation tests
run: deno test --doc client.ts mod.ts pool.ts client/ connection/ query/ utils/
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
@@ -1,4 +1,4 @@
FROM denoland/deno:alpine-1.16.0
FROM denoland/deno:alpine-1.17.3
WORKDIR /app

# Install wait utility
Expand Down
22 changes: 7 additions & 15 deletions README.md
Expand Up @@ -15,8 +15,8 @@ A lightweight PostgreSQL driver for Deno focused on user experience
## Example

```ts
// deno run --allow-net --allow-read --unstable mod.ts
import { Client } from "https://deno.land/x/postgres/mod.ts";
// deno run --allow-net --allow-read mod.ts
import { Client } from "https://deno.land/x/postgres@v0.15.0/mod.ts";

const client = new Client({
user: "user",
Expand Down Expand Up @@ -54,15 +54,6 @@ await client.end();
For more examples visit the documentation available at
[https://deno-postgres.com/](https://deno-postgres.com/)

## Why do I need unstable to connect using TLS?

Sadly, establishing a TLS connection in the way Postgres requires it isn't
possible without the `Deno.startTls` API, which is currently marked as unstable.

At least that was the situation before Deno 1.16, which stabilized the required
API making it possible to use the library without requiring `--unstable`. Users
are urged to upgrade to Deno 1.16 or above to enjoy this feature

## Documentation

The documentation is available on the deno-postgres website
Expand Down Expand Up @@ -164,7 +155,8 @@ This situation will become more stable as `std` and `deno-postgres` approach 1.0
| 1.11.0 and up | 0.12.0 | 0.12.0 |
| 1.14.0 and up | 0.13.0 | 0.13.0 |
| 1.15.0 | 0.13.0 | |
| 1.16.0 | 0.14.0 | |
| 1.16.0 | 0.14.0 | 0.14.3 |
| 1.17.0 | 0.15.0 | |

## Contributing guidelines

Expand All @@ -174,9 +166,9 @@ When contributing to repository make sure to:
2. All public interfaces must be typed and have a corresponding JS block
explaining their usage
3. All code must pass the format and lint checks enforced by `deno fmt` and
`deno lint --config=deno.json` respectively. The build will not pass the
tests if these conditions are not met. Ignore rules will be accepted in the
code base when their respective justification is given in a comment
`deno lint` respectively. The build will not pass the tests if these
conditions are not met. Ignore rules will be accepted in the code base when
their respective justification is given in a comment
4. All features and fixes must have a corresponding test added in order to be
accepted

Expand Down
20 changes: 10 additions & 10 deletions client.ts
@@ -1,22 +1,22 @@
import { Connection } from "./connection/connection.ts";
import {
ClientConfiguration,
ClientOptions,
ConnectionString,
type ClientConfiguration,
type ClientOptions,
type ConnectionString,
createParams,
} from "./connection/connection_params.ts";
import {
Query,
QueryArguments,
QueryArrayResult,
QueryObjectOptions,
QueryObjectResult,
QueryOptions,
QueryResult,
type QueryArguments,
type QueryArrayResult,
type QueryObjectOptions,
type QueryObjectResult,
type QueryOptions,
type QueryResult,
ResultType,
templateStringToQuery,
} from "./query/query.ts";
import { Transaction, TransactionOptions } from "./query/transaction.ts";
import { Transaction, type TransactionOptions } from "./query/transaction.ts";
import { isTemplateString } from "./utils/utils.ts";

export interface Session {
Expand Down
13 changes: 6 additions & 7 deletions client/error.ts
@@ -1,4 +1,4 @@
import type { Notice } from "../connection/message.ts";
import { type Notice } from "../connection/message.ts";

export class ConnectionError extends Error {
constructor(message?: string) {
Expand All @@ -8,8 +8,8 @@ export class ConnectionError extends Error {
}

export class ConnectionParamsError extends Error {
constructor(message: string) {
super(message);
constructor(message: string, cause?: Error) {
super(message, { cause });
this.name = "ConnectionParamsError";
}
}
Expand All @@ -24,15 +24,14 @@ export class PostgresError extends Error {
}
}

// TODO
// Use error cause once it's added to JavaScript
export class TransactionError extends Error {
constructor(
transaction_name: string,
public cause: PostgresError,
cause: PostgresError,
) {
super(
`The transaction "${transaction_name}" has been aborted due to \`${cause}\`. Check the "cause" property to get more details`,
`The transaction "${transaction_name}" has been aborted`,
{ cause },
);
this.name = "TransactionError";
}
Expand Down
23 changes: 7 additions & 16 deletions connection/connection.ts
Expand Up @@ -32,21 +32,21 @@ import { getSocketName, readUInt32BE } from "../utils/utils.ts";
import { PacketWriter } from "./packet.ts";
import {
Message,
Notice,
type Notice,
parseBackendKeyMessage,
parseCommandCompleteMessage,
parseNoticeMessage,
parseRowDataMessage,
parseRowDescriptionMessage,
} from "./message.ts";
import {
Query,
type Query,
QueryArrayResult,
QueryObjectResult,
QueryResult,
type QueryResult,
ResultType,
} from "../query/query.ts";
import { ClientConfiguration } from "./connection_params.ts";
import { type ClientConfiguration } from "./connection_params.ts";
import * as scram from "./scram.ts";
import {
ConnectionError,
Expand Down Expand Up @@ -270,18 +270,9 @@ export class Connection {
connection: Deno.Conn,
options: { hostname: string; caCerts: string[] },
) {
// TODO
// Remove unstable check on 1.17.0
if ("startTls" in Deno) {
// @ts-ignore This API should be available on unstable
this.#conn = await Deno.startTls(connection, options);
this.#bufWriter = new BufWriter(this.#conn);
this.#bufReader = new BufReader(this.#conn);
} else {
throw new Error(
"You need to execute Deno with the `--unstable` argument in order to stablish a TLS connection",
);
}
this.#conn = await Deno.startTls(connection, options);
this.#bufWriter = new BufWriter(this.#conn);
this.#bufReader = new BufReader(this.#conn);
}

#resetConnectionMetadata() {
Expand Down
10 changes: 4 additions & 6 deletions connection/connection_params.ts
Expand Up @@ -177,10 +177,9 @@ function parseOptionsFromUri(connString: string): ClientOptions {
user: uri.user || uri.params.user,
};
} catch (e) {
// TODO
// Use error cause
throw new ConnectionParamsError(
`Could not parse the connection string due to ${e}`,
`Could not parse the connection string`,
e,
);
}

Expand Down Expand Up @@ -296,10 +295,9 @@ export function createParams(
host = socket;
}
} catch (e) {
// TODO
// Add error cause
throw new ConnectionParamsError(
`Could not parse host "${socket}" due to "${e}"`,
`Could not parse host "${socket}"`,
e,
);
}
} else {
Expand Down
9 changes: 0 additions & 9 deletions deno.json

This file was deleted.

23 changes: 13 additions & 10 deletions deps.ts
@@ -1,17 +1,20 @@
export * as base64 from "https://deno.land/std@0.114.0/encoding/base64.ts";
export * as hex from "https://deno.land/std@0.114.0/encoding/hex.ts";
export * as date from "https://deno.land/std@0.114.0/datetime/mod.ts";
export * as base64 from "https://deno.land/std@0.121.0/encoding/base64.ts";
export * as hex from "https://deno.land/std@0.121.0/encoding/hex.ts";
export * as date from "https://deno.land/std@0.121.0/datetime/mod.ts";
export {
BufReader,
BufWriter,
} from "https://deno.land/std@0.114.0/io/buffer.ts";
export { copy } from "https://deno.land/std@0.114.0/bytes/mod.ts";
export { crypto } from "https://deno.land/std@0.114.0/crypto/mod.ts";
export { deferred, delay } from "https://deno.land/std@0.114.0/async/mod.ts";
export type { Deferred } from "https://deno.land/std@0.114.0/async/mod.ts";
export { bold, yellow } from "https://deno.land/std@0.114.0/fmt/colors.ts";
} from "https://deno.land/std@0.121.0/io/buffer.ts";
export { copy } from "https://deno.land/std@0.121.0/bytes/mod.ts";
export { crypto } from "https://deno.land/std@0.121.0/crypto/mod.ts";
export {
type Deferred,
deferred,
delay,
} from "https://deno.land/std@0.121.0/async/mod.ts";
export { bold, yellow } from "https://deno.land/std@0.121.0/fmt/colors.ts";
export {
fromFileUrl,
isAbsolute,
join as joinPath,
} from "https://deno.land/std@0.114.0/path/mod.ts";
} from "https://deno.land/std@0.121.0/path/mod.ts";
2 changes: 1 addition & 1 deletion docs/README.md
Expand Up @@ -348,7 +348,7 @@ consistency with other PostgreSQL clients out there (see
https://www.postgresql.org/docs/14/libpq-envars.html)

```ts
// PGUSER=user PGPASSWORD=admin PGDATABASE=test deno run --allow-net --allow-env --unstable database.js
// PGUSER=user PGPASSWORD=admin PGDATABASE=test deno run --allow-net --allow-env database.js
import { Client } from "https://deno.land/x/postgres/mod.ts";

const client = new Client();
Expand Down
6 changes: 3 additions & 3 deletions pool.ts
@@ -1,8 +1,8 @@
import { PoolClient } from "./client.ts";
import {
ClientConfiguration,
ClientOptions,
ConnectionString,
type ClientConfiguration,
type ClientOptions,
type ConnectionString,
createParams,
} from "./connection/connection_params.ts";
import { DeferredAccessStack } from "./utils/deferred.ts";
Expand Down
2 changes: 1 addition & 1 deletion query/decoders.ts
@@ -1,6 +1,6 @@
import { date } from "../deps.ts";
import { parseArray } from "./array_parser.ts";
import {
import type {
Box,
Circle,
Float8,
Expand Down
3 changes: 2 additions & 1 deletion query/encode.ts
Expand Up @@ -60,7 +60,8 @@ function encodeArray(array: Array<unknown>): string {
} else if (Array.isArray(element)) {
encodedArray += encodeArray(element);
} else if (element instanceof Uint8Array) {
// TODO: it should be encoded as bytea?
// TODO
// Should it be encoded as bytea?
throw new Error("Can't encode array of buffers.");
} else {
const encodedElement = encodeArgument(element);
Expand Down
6 changes: 3 additions & 3 deletions query/query.ts
@@ -1,6 +1,6 @@
import { encodeArgument, EncodedArg } from "./encode.ts";
import { Column, decode } from "./decode.ts";
import { Notice } from "../connection/message.ts";
import { encodeArgument, type EncodedArg } from "./encode.ts";
import { type Column, decode } from "./decode.ts";
import { type Notice } from "../connection/message.ts";

// TODO
// Limit the type of parameters that can be passed
Expand Down
14 changes: 7 additions & 7 deletions query/transaction.ts
@@ -1,12 +1,12 @@
import type { QueryClient } from "../client.ts";
import { type QueryClient } from "../client.ts";
import {
Query,
QueryArguments,
QueryArrayResult,
QueryObjectOptions,
QueryObjectResult,
QueryOptions,
QueryResult,
type QueryArguments,
type QueryArrayResult,
type QueryObjectOptions,
type QueryObjectResult,
type QueryOptions,
type QueryResult,
ResultType,
templateStringToQuery,
} from "./query.ts";
Expand Down
59 changes: 12 additions & 47 deletions tests/config.ts
@@ -1,4 +1,5 @@
import { ClientConfiguration } from "../connection/connection_params.ts";
import config_file1 from "./config.json" assert { type: "json" };

type TcpConfiguration = Omit<ClientConfiguration, "connection"> & {
host_type: "tcp";
Expand All @@ -7,54 +8,18 @@ type SocketConfiguration = Omit<ClientConfiguration, "connection" | "tls"> & {
host_type: "socket";
};

type ConfigFileConnection =
& Pick<
ClientConfiguration,
"applicationName" | "database" | "hostname" | "password" | "port"
>
& {
socket: string;
};

type Clear = ConfigFileConnection & {
users: {
clear: string;
socket: string;
};
};

type Classic = ConfigFileConnection & {
users: {
main: string;
md5: string;
socket: string;
tls_only: string;
};
};

type Scram = ConfigFileConnection & {
users: {
scram: string;
socket: string;
};
};

interface EnvironmentConfig {
postgres_clear: Clear;
postgres_md5: Classic;
postgres_scram: Scram;
let DEV_MODE: string | undefined;
try {
DEV_MODE = Deno.env.get("DENO_POSTGRES_DEVELOPMENT");
} catch (e) {
if (e instanceof Deno.errors.PermissionDenied) {
throw new Error(
"You need to provide ENV access in order to run the test suite",
);
}
throw e;
}

const config_file: {
ci: EnvironmentConfig;
local: EnvironmentConfig;
} = JSON.parse(
await Deno.readTextFile(new URL("./config.json", import.meta.url)),
);

const config = Deno.env.get("DENO_POSTGRES_DEVELOPMENT") === "true"
? config_file.local
: config_file.ci;
const config = DEV_MODE === "true" ? config_file1.local : config_file1.ci;

const enabled_tls = {
caCertificates: [
Expand Down

0 comments on commit 9e110a8

Please sign in to comment.