@ooraini/pgquic 0.1.0 → 0.2.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/README.md +46 -2
- package/dist/index.d.ts +6 -4
- package/dist/index.js +4 -5
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Connect to PostgreSQL from the browser over WebTransport.
|
|
4
4
|
|
|
5
|
+
## npm
|
|
6
|
+
|
|
5
7
|
```sh
|
|
6
8
|
npm install @ooraini/pgquic
|
|
7
9
|
```
|
|
@@ -11,7 +13,6 @@ import { Pool, PgWebTransport } from "@ooraini/pgquic";
|
|
|
11
13
|
|
|
12
14
|
const transport = new PgWebTransport({
|
|
13
15
|
url: "https://db.example.com/v1/session",
|
|
14
|
-
token: () => getAccessToken(),
|
|
15
16
|
});
|
|
16
17
|
|
|
17
18
|
const pool = new Pool({
|
|
@@ -26,4 +27,47 @@ const pool = new Pool({
|
|
|
26
27
|
const result = await pool.query("select now()");
|
|
27
28
|
```
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
For the gateway's generated certificate, supply its logged base64 `certificate_sha256` value through `serverCertificateHashes` as shown below.
|
|
31
|
+
|
|
32
|
+
## HTML
|
|
33
|
+
|
|
34
|
+
The package is a self-contained ES module and can be imported without a build step:
|
|
35
|
+
|
|
36
|
+
```html
|
|
37
|
+
<script type="module">
|
|
38
|
+
import {
|
|
39
|
+
Pool,
|
|
40
|
+
PgWebTransport,
|
|
41
|
+
} from "https://cdn.jsdelivr.net/npm/@ooraini/pgquic@0.2.0/dist/index.js";
|
|
42
|
+
|
|
43
|
+
const hash = "PASTE_CERTIFICATE_SHA256_FROM_PGQUIC_LOG";
|
|
44
|
+
const transport = new PgWebTransport({
|
|
45
|
+
url: "https://localhost:4433/v1/session",
|
|
46
|
+
serverCertificateHashes: [{
|
|
47
|
+
algorithm: "sha-256",
|
|
48
|
+
value: Uint8Array.from(atob(hash), (c) => c.charCodeAt(0)),
|
|
49
|
+
}],
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const pool = new Pool({
|
|
53
|
+
transport,
|
|
54
|
+
user: "app_user",
|
|
55
|
+
password: "password",
|
|
56
|
+
database: "app",
|
|
57
|
+
ssl: false,
|
|
58
|
+
enableChannelBinding: false,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const result = await pool.query("select now()");
|
|
62
|
+
</script>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Use `<script type="module">`; the package does not expose a global for classic scripts.
|
|
66
|
+
|
|
67
|
+
Both approaches require a [pgquic gateway](https://github.com/ooraini/pgquic). The host CLI reaches PostgreSQL at `127.0.0.1:5432` by default. A gateway container is also available:
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
docker pull ghcr.io/ooraini/pgquic-gateway:0.2.0
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
See the repository for gateway configuration and deployment.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { ClientConfig, PoolConfig } from 'pg';
|
|
1
|
+
import { Client as Client$1, ClientConfig, PoolConfig, Pool as Pool$1 } from 'pg';
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
|
|
4
|
-
type TokenProvider = string | (() => string | Promise<string>);
|
|
5
4
|
interface CertificateHash {
|
|
6
5
|
algorithm: "sha-256";
|
|
7
6
|
value: BufferSource;
|
|
8
7
|
}
|
|
9
8
|
interface PgWebTransportOptions {
|
|
10
9
|
url: string;
|
|
11
|
-
token?: TokenProvider;
|
|
12
10
|
serverCertificateHashes?: CertificateHash[];
|
|
13
11
|
maxConnections?: number;
|
|
14
12
|
highWaterMark?: number;
|
|
@@ -111,12 +109,16 @@ interface PgquicPoolConfig extends PoolConfig {
|
|
|
111
109
|
enableChannelBinding?: boolean;
|
|
112
110
|
}
|
|
113
111
|
declare const Client_base: any;
|
|
112
|
+
interface Client extends Client$1 {
|
|
113
|
+
}
|
|
114
114
|
declare class Client extends Client_base {
|
|
115
115
|
constructor(config: PgquicClientConfig);
|
|
116
116
|
}
|
|
117
117
|
declare const Pool_base: any;
|
|
118
|
+
interface Pool extends Pool$1 {
|
|
119
|
+
}
|
|
118
120
|
declare class Pool extends Pool_base {
|
|
119
121
|
constructor(config: PgquicPoolConfig);
|
|
120
122
|
}
|
|
121
123
|
|
|
122
|
-
export { Client, PgWebTransport, type PgWebTransportOptions, PgWebTransportSocket, type PgquicClientConfig, type PgquicPoolConfig, Pool, type
|
|
124
|
+
export { Client, PgWebTransport, type PgWebTransportOptions, PgWebTransportSocket, type PgquicClientConfig, type PgquicPoolConfig, Pool, type TransportState };
|
package/dist/index.js
CHANGED
|
@@ -6956,8 +6956,8 @@ init_inject();
|
|
|
6956
6956
|
// src/framing.ts
|
|
6957
6957
|
init_inject();
|
|
6958
6958
|
var import_buffer3 = __toESM(require_buffer(), 1);
|
|
6959
|
-
function encodeControl(
|
|
6960
|
-
const payload = import_buffer3.Buffer.from(JSON.stringify({ version: 1
|
|
6959
|
+
function encodeControl() {
|
|
6960
|
+
const payload = import_buffer3.Buffer.from(JSON.stringify({ version: 1 }), "utf8");
|
|
6961
6961
|
const result = import_buffer3.Buffer.allocUnsafe(4 + payload.length);
|
|
6962
6962
|
result.writeUInt32BE(payload.length, 0);
|
|
6963
6963
|
payload.copy(result, 4);
|
|
@@ -7077,11 +7077,10 @@ var PgWebTransport = class extends EventTarget {
|
|
|
7077
7077
|
const control = await session.createBidirectionalStream();
|
|
7078
7078
|
const writer = control.writable.getWriter();
|
|
7079
7079
|
const reader = control.readable.getReader();
|
|
7080
|
-
|
|
7081
|
-
await writer.write(encodeControl(token));
|
|
7080
|
+
await writer.write(encodeControl());
|
|
7082
7081
|
const welcome = await readControl(reader);
|
|
7083
7082
|
if (!welcome.ok)
|
|
7084
|
-
throw new Error(welcome.error || "pgquic
|
|
7083
|
+
throw new Error(welcome.error || "pgquic control handshake failed");
|
|
7085
7084
|
writer.releaseLock();
|
|
7086
7085
|
reader.releaseLock();
|
|
7087
7086
|
this.session = session;
|