Skip to content

Commit

Permalink
Tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
jawj committed Jan 21, 2025
1 parent 613afcd commit 1fdc143
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 44 deletions.
34 changes: 17 additions & 17 deletions src/httpQuery.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
import { Socket } from './shims/net';
import { parse } from './shims/url';
import { toHex } from 'hextreme';
import type {
HTTPQueryOptions,
HTTPTransactionOptions,
NeonQueryPromise,
NeonQueryFunction,
ParameterizedQuery,
ProcessQueryResultOptions,
} from './httpTypes';

// @ts-ignore -- this isn't officially exported by pg
import { prepareValue } from 'pg/lib/utils';
// @ts-ignore -- this isn't officially exported by pg
import TypeOverrides from 'pg/lib/type-overrides';

/*
Note: most config options can be set in 3 places:
Expand All @@ -33,6 +16,23 @@ That is:
* `neon` options override defaults.
*/

import { Socket } from './shims/net';
import { parse } from './shims/url';
import { toHex } from 'hextreme';
import type {
HTTPQueryOptions,
HTTPTransactionOptions,
NeonQueryPromise,
NeonQueryFunction,
ParameterizedQuery,
ProcessQueryResultOptions,
} from './httpTypes';

// @ts-ignore -- this isn't officially exported by pg
import { prepareValue } from 'pg/lib/utils';
// @ts-ignore -- this isn't officially exported by pg
import TypeOverrides from 'pg/lib/type-overrides';

function encodeBuffersAsBytea(value: unknown): unknown {
// convert Buffer to bytea hex format: https://www.postgresql.org/docs/current/datatype-binary.html#DATATYPE-BINARY-BYTEA-HEX-FORMAT
if (value instanceof Buffer) return '\\x' + toHex(value);
Expand Down
53 changes: 28 additions & 25 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,43 @@ for repeated SHA-256 digests. This saves some time and CPU.
circumstances are right.
*/

import type { ClientBase, PoolClient } from 'pg';
import { Socket, type SocketDefaults } from './shims/net';
import { neon, NeonDbError } from './httpQuery';
import { NeonClient } from './client';
import { NeonPool } from './pool';
import type { ClientBase as PgClientBase, PoolClient as PgPoolClient } from 'pg';
import { type SocketDefaults } from './shims/net';

export * from './httpQuery';
export type * from './httpTypes';

export { NeonPool as Pool } from './pool';
export { NeonClient as Client } from './client';

export { Socket as neonConfig } from './shims/net';
export type {
SocketDefaults as NeonConfig,
FetchEndpointOptions,
WebSocketConstructor,
WebSocketLike,
subtls,
startTls,
TrustedCert,
WebSocketReadQueue,
} from './shims/net';

// class 'ClientBase' exists only in @types/pg: under the hood in pg it's just a `Client extends EventEmitter`
interface NeonClientBase extends ClientBase {
export interface ClientBase extends PgClientBase {
neonConfig: NeonConfigGlobalAndClient;
}

// class 'PoolClient' exists only in @types/pg: under the hood in pg it's just a `Client extends EventEmitter`
interface NeonPoolClient extends PoolClient {
export interface PoolClient extends PgPoolClient {
neonConfig: NeonConfigGlobalAndClient;
}

export { defaults, types, DatabaseError } from 'pg';
export {
defaults,
types,
DatabaseError
} from 'pg';

export type {
BindConfig,
ClientConfig,
Expand All @@ -58,23 +78,6 @@ export type {
Submittable,
} from 'pg';

export * from './httpQuery';

export { Socket as neonConfig, NeonPool as Pool, NeonClient as Client, neon, NeonDbError };

export type { NeonPoolClient as PoolClient, NeonClientBase as ClientBase };

export type {
SocketDefaults as NeonConfig,
FetchEndpointOptions,
WebSocketConstructor,
WebSocketLike,
subtls,
startTls,
TrustedCert,
WebSocketReadQueue,
} from './shims/net';

// provided for backwards-compatibility
export type NeonConfigGlobalOnly = Pick<
SocketDefaults,
Expand Down
6 changes: 4 additions & 2 deletions src/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ function promisify(Promise: any, callback: any) {
return { callback: cb, result: result };
}

export declare interface NeonPool {
Promise: typeof Promise;
}

/**
* The node-postgres `Pool` object re-exported with minor modifications.
* https://node-postgres.com/apis/pool
Expand All @@ -53,7 +57,6 @@ export class NeonPool extends Pool {
override addListener = this.on;

override query<T extends Submittable>(queryStream: T): T;
// tslint:disable:no-unnecessary-generics
override query<R extends any[] = any[], I = any[]>(
queryConfig: QueryArrayConfig<I>,
values?: QueryConfigValues<I>,
Expand Down Expand Up @@ -94,7 +97,6 @@ export class NeonPool extends Pool {
}

// create a synthetic callback that resolves the returned Promise
// @ts-ignore -- TS doesn't know about this.Promise
const response = promisify(this.Promise, cb);
cb = response.callback;

Expand Down

0 comments on commit 1fdc143

Please sign in to comment.