Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: denodrivers/postgres
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: skymethod/deno-postgres
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 4 files changed
  • 1 contributor

Commits on Oct 9, 2023

  1. Copy the full SHA
    4dcc721 View commit details
Showing with 14 additions and 7 deletions.
  1. +8 −3 connection/connection.ts
  2. +3 −1 connection/connection_params.ts
  3. +1 −1 deps.ts
  4. +2 −2 query/decoders.ts
11 changes: 8 additions & 3 deletions connection/connection.ts
Original file line number Diff line number Diff line change
@@ -142,6 +142,11 @@ export class Connection {
return this.#transport;
}

static connFactory?: { // dfp: allow alternate Deno.connect/startTls
connect: typeof Deno.connect,
startTls: typeof Deno.startTls,
}

constructor(
connection_params: ClientConfiguration,
disconnection_callback: () => Promise<void>,
@@ -250,7 +255,7 @@ export class Connection {
async #openConnection(options: ConnectOptions) {
// @ts-ignore This will throw in runtime if the options passed to it are socket related and deno is running
// on stable
this.#conn = await Deno.connect(options);
this.#conn = await (Connection.connFactory?.connect ?? Deno.connect)(options); // dfp: allow alternate Deno.connect
this.#bufWriter = new BufWriter(this.#conn);
this.#bufReader = new BufReader(this.#conn);
}
@@ -287,7 +292,7 @@ export class Connection {
connection: Deno.Conn,
options: { hostname: string; caCerts: string[] },
) {
this.#conn = await Deno.startTls(connection, options);
this.#conn = await (Connection.connFactory?.startTls ?? Deno.startTls)(connection, options); // dfp: allow alternate Deno.startTls
this.#bufWriter = new BufWriter(this.#conn);
this.#bufReader = new BufReader(this.#conn);
}
@@ -387,7 +392,7 @@ export class Connection {
} catch (e) {
// Make sure to close the connection before erroring or reseting
this.#closeConnection();
if (e instanceof Deno.errors.InvalidData && tls_enabled) {
if (globalThis.Deno?.errors?.InvalidData && e instanceof Deno.errors.InvalidData && tls_enabled) { // dfp: Deno.errors.InvalidData may not exist
if (tls_enforced) {
throw new Error(
"The certificate used to secure the TLS connection is invalid.",
4 changes: 3 additions & 1 deletion connection/connection_params.ts
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ export type ConnectionString = string;
* It will throw if no env permission was provided on startup
*/
function getPgEnv(): ClientOptions {
if (!globalThis.Deno?.env) throw new Error(`No Deno.env`); // dfp: Deno.env may not exist
return {
applicationName: Deno.env.get("PGAPPNAME"),
database: Deno.env.get("PGDATABASE"),
@@ -333,7 +334,7 @@ export function createParams(
try {
pgEnv = getPgEnv();
} catch (e) {
if (e instanceof Deno.errors.PermissionDenied) {
if (e.message === 'No Deno.env' || globalThis.Deno?.errors?.PermissionDenied && e instanceof Deno.errors.PermissionDenied) { // dfp: Deno.errors.PermissionDenied may not exist
has_env_access = false;
} else {
throw e;
@@ -354,6 +355,7 @@ export function createParams(
const socket = provided_host ?? DEFAULT_OPTIONS.socket;
try {
if (!isAbsolute(socket)) {
if (!Deno?.mainModule) throw new Error(`Relative socket needs Deno.mainModule`); // dfp: Deno.mainModule may not exist
const parsed_host = new URL(socket, Deno.mainModule);

// Resolve relative path
2 changes: 1 addition & 1 deletion deps.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ export {
BufWriter,
} from "https://deno.land/std@0.160.0/io/buffer.ts";
export { copy } from "https://deno.land/std@0.160.0/bytes/mod.ts";
export { crypto } from "https://deno.land/std@0.160.0/crypto/mod.ts";
const crypto = globalThis.crypto; export { crypto }; // dfp: assume crypto in globalThis
export {
type Deferred,
deferred,
4 changes: 2 additions & 2 deletions query/decoders.ts
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ export function decodeBooleanArray(value: string) {
}

export function decodeBox(value: string): Box {
const [a, b] = value.match(/\(.*?\)/g) || [];
const [a, b] = value.match(/\(.*?\)/g) || [] as any; // dfp: doesn't compile, wait for an upstream fix

return {
a: decodePoint(a),
@@ -221,7 +221,7 @@ export function decodeLineArray(value: string) {
export function decodeLineSegment(value: string): LineSegment {
const [a, b] = value
.substring(1, value.length - 1)
.match(/\(.*?\)/g) || [];
.match(/\(.*?\)/g) || [] as any; // dfp: doesn't compile, wait for an upstream fix

return {
a: decodePoint(a),