pgsql-client 3.18.1 → 3.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.d.ts +1 -1
- package/client.js +4 -9
- package/driver.d.ts +36 -0
- package/driver.js +28 -0
- package/esm/client.js +4 -9
- package/esm/driver.js +21 -0
- package/esm/index.js +1 -0
- package/esm/roles.js +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +4 -4
- package/roles.js +1 -0
package/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { AuthOptions, PgTestClientContext, PgTestConnectionOptions } from '@pgpmjs/types';
|
|
1
2
|
import { Client, QueryResult } from 'pg';
|
|
2
3
|
import { PgConfig } from 'pg-env';
|
|
3
|
-
import { AuthOptions, PgTestConnectionOptions, PgTestClientContext } from '@pgpmjs/types';
|
|
4
4
|
export type PgClientOpts = {
|
|
5
5
|
deferConnect?: boolean;
|
|
6
6
|
trackConnect?: (p: Promise<any>) => void;
|
package/client.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PgClient = void 0;
|
|
4
|
-
const pg_1 = require("pg");
|
|
5
|
-
const roles_1 = require("./roles");
|
|
6
4
|
const context_utils_1 = require("./context-utils");
|
|
5
|
+
const driver_1 = require("./driver");
|
|
6
|
+
const roles_1 = require("./roles");
|
|
7
7
|
class PgClient {
|
|
8
8
|
config;
|
|
9
9
|
client;
|
|
@@ -15,13 +15,8 @@ class PgClient {
|
|
|
15
15
|
constructor(config, opts = {}) {
|
|
16
16
|
this.opts = opts;
|
|
17
17
|
this.config = config;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
port: this.config.port,
|
|
21
|
-
database: this.config.database,
|
|
22
|
-
user: this.config.user,
|
|
23
|
-
password: this.config.password
|
|
24
|
-
});
|
|
18
|
+
const factory = (0, driver_1.getActivePgClientFactory)() ?? driver_1.defaultPgClientFactory;
|
|
19
|
+
this.client = factory(this.config);
|
|
25
20
|
if (!opts.deferConnect) {
|
|
26
21
|
this.connectPromise = this.client.connect();
|
|
27
22
|
if (opts.trackConnect)
|
package/driver.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Client } from 'pg';
|
|
2
|
+
import type { PgConfig } from 'pg-env';
|
|
3
|
+
/**
|
|
4
|
+
* Minimal client-factory seam for pgsql-client.
|
|
5
|
+
*
|
|
6
|
+
* `PgClient` builds a single `pg.Client` per instance. By default that client is
|
|
7
|
+
* a real `new pg.Client(...)` over TCP (see `defaultPgClientFactory`).
|
|
8
|
+
* Registering an alternate factory lets a different backend (e.g. an in-process
|
|
9
|
+
* PGlite instance) supply the client WITHOUT any backend-specific dependency
|
|
10
|
+
* leaking into pgsql-client or its consumers.
|
|
11
|
+
*
|
|
12
|
+
* The only surface `PgClient` relies on is `connect()`, `query()` and `end()`.
|
|
13
|
+
* A real `pg.Client` structurally satisfies `QueryablePgClient`, so the default
|
|
14
|
+
* path is unchanged and fully backward-compatible.
|
|
15
|
+
*
|
|
16
|
+
* This mirrors the pool-factory seam in `pg-cache`; the two are independent
|
|
17
|
+
* because `pgsql-client`/`pgsql-test` construct `pg.Client`s directly rather
|
|
18
|
+
* than going through `getPgPool`.
|
|
19
|
+
*/
|
|
20
|
+
export interface QueryablePgClient {
|
|
21
|
+
connect(): Promise<any>;
|
|
22
|
+
query(text: any, values?: any[]): Promise<any>;
|
|
23
|
+
end(): Promise<any>;
|
|
24
|
+
}
|
|
25
|
+
export type PgClientFactory = (config: PgConfig) => Client | QueryablePgClient;
|
|
26
|
+
/**
|
|
27
|
+
* Register the factory `PgClient` uses to build its underlying client. Pass
|
|
28
|
+
* `undefined` to restore the default (`pg.Client`) behavior.
|
|
29
|
+
*/
|
|
30
|
+
export declare const registerPgClientFactory: (factory: PgClientFactory | undefined) => void;
|
|
31
|
+
/** The currently-registered factory, or `undefined` when using the default. */
|
|
32
|
+
export declare const getActivePgClientFactory: () => PgClientFactory | undefined;
|
|
33
|
+
/** Whether a non-default client factory is currently registered. */
|
|
34
|
+
export declare const hasPgClientFactory: () => boolean;
|
|
35
|
+
/** The default factory: a real node-`pg` `Client` over TCP. */
|
|
36
|
+
export declare const defaultPgClientFactory: PgClientFactory;
|
package/driver.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultPgClientFactory = exports.hasPgClientFactory = exports.getActivePgClientFactory = exports.registerPgClientFactory = void 0;
|
|
4
|
+
const pg_1 = require("pg");
|
|
5
|
+
let activeFactory;
|
|
6
|
+
/**
|
|
7
|
+
* Register the factory `PgClient` uses to build its underlying client. Pass
|
|
8
|
+
* `undefined` to restore the default (`pg.Client`) behavior.
|
|
9
|
+
*/
|
|
10
|
+
const registerPgClientFactory = (factory) => {
|
|
11
|
+
activeFactory = factory;
|
|
12
|
+
};
|
|
13
|
+
exports.registerPgClientFactory = registerPgClientFactory;
|
|
14
|
+
/** The currently-registered factory, or `undefined` when using the default. */
|
|
15
|
+
const getActivePgClientFactory = () => activeFactory;
|
|
16
|
+
exports.getActivePgClientFactory = getActivePgClientFactory;
|
|
17
|
+
/** Whether a non-default client factory is currently registered. */
|
|
18
|
+
const hasPgClientFactory = () => activeFactory !== undefined;
|
|
19
|
+
exports.hasPgClientFactory = hasPgClientFactory;
|
|
20
|
+
/** The default factory: a real node-`pg` `Client` over TCP. */
|
|
21
|
+
const defaultPgClientFactory = (config) => new pg_1.Client({
|
|
22
|
+
host: config.host,
|
|
23
|
+
port: config.port,
|
|
24
|
+
database: config.database,
|
|
25
|
+
user: config.user,
|
|
26
|
+
password: config.password
|
|
27
|
+
});
|
|
28
|
+
exports.defaultPgClientFactory = defaultPgClientFactory;
|
package/esm/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Client } from 'pg';
|
|
2
|
-
import { getRoleName } from './roles';
|
|
3
1
|
import { generateContextStatements } from './context-utils';
|
|
2
|
+
import { defaultPgClientFactory, getActivePgClientFactory } from './driver';
|
|
3
|
+
import { getRoleName } from './roles';
|
|
4
4
|
export class PgClient {
|
|
5
5
|
config;
|
|
6
6
|
client;
|
|
@@ -12,13 +12,8 @@ export class PgClient {
|
|
|
12
12
|
constructor(config, opts = {}) {
|
|
13
13
|
this.opts = opts;
|
|
14
14
|
this.config = config;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
port: this.config.port,
|
|
18
|
-
database: this.config.database,
|
|
19
|
-
user: this.config.user,
|
|
20
|
-
password: this.config.password
|
|
21
|
-
});
|
|
15
|
+
const factory = getActivePgClientFactory() ?? defaultPgClientFactory;
|
|
16
|
+
this.client = factory(this.config);
|
|
22
17
|
if (!opts.deferConnect) {
|
|
23
18
|
this.connectPromise = this.client.connect();
|
|
24
19
|
if (opts.trackConnect)
|
package/esm/driver.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Client } from 'pg';
|
|
2
|
+
let activeFactory;
|
|
3
|
+
/**
|
|
4
|
+
* Register the factory `PgClient` uses to build its underlying client. Pass
|
|
5
|
+
* `undefined` to restore the default (`pg.Client`) behavior.
|
|
6
|
+
*/
|
|
7
|
+
export const registerPgClientFactory = (factory) => {
|
|
8
|
+
activeFactory = factory;
|
|
9
|
+
};
|
|
10
|
+
/** The currently-registered factory, or `undefined` when using the default. */
|
|
11
|
+
export const getActivePgClientFactory = () => activeFactory;
|
|
12
|
+
/** Whether a non-default client factory is currently registered. */
|
|
13
|
+
export const hasPgClientFactory = () => activeFactory !== undefined;
|
|
14
|
+
/** The default factory: a real node-`pg` `Client` over TCP. */
|
|
15
|
+
export const defaultPgClientFactory = (config) => new Client({
|
|
16
|
+
host: config.host,
|
|
17
|
+
port: config.port,
|
|
18
|
+
database: config.database,
|
|
19
|
+
user: config.user,
|
|
20
|
+
password: config.password
|
|
21
|
+
});
|
package/esm/index.js
CHANGED
package/esm/roles.js
CHANGED
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -18,6 +18,7 @@ exports.streamSql = void 0;
|
|
|
18
18
|
__exportStar(require("./admin"), exports);
|
|
19
19
|
__exportStar(require("./client"), exports);
|
|
20
20
|
__exportStar(require("./context-utils"), exports);
|
|
21
|
+
__exportStar(require("./driver"), exports);
|
|
21
22
|
__exportStar(require("./ephemeral"), exports);
|
|
22
23
|
__exportStar(require("./roles"), exports);
|
|
23
24
|
var stream_1 = require("./stream");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pgsql-client",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.20.0",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "PostgreSQL client utilities with query helpers, RLS context management, and database administration",
|
|
6
6
|
"main": "index.js",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"makage": "^0.3.0"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@pgpmjs/core": "^6.
|
|
48
|
+
"@pgpmjs/core": "^6.27.1",
|
|
49
49
|
"@pgpmjs/logger": "^2.13.0",
|
|
50
|
-
"@pgpmjs/types": "^2.
|
|
50
|
+
"@pgpmjs/types": "^2.31.0",
|
|
51
51
|
"pg": "^8.21.0",
|
|
52
52
|
"pg-env": "^1.17.0"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "7cbe15fac21a9345b169203ba9542ba9a50c866c"
|
|
55
55
|
}
|