@xemahq/database-driver-postgres 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend, and
172
+ hold each Contributor harmless for any liability incurred by, or
173
+ claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Xema
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ <p align="center">
2
+ <svg width="680" height="120" viewBox="0 0 680 120" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="@xemahq/database-driver-postgres">
3
+ <rect width="680" height="120" rx="14" fill="#0B1020"/>
4
+ <g transform="translate(28,34)">
5
+ <path d="M26 0 L52 15 L52 45 L26 60 L0 45 L0 15 Z" fill="#8B5CF6" opacity="0.18"/>
6
+ <path d="M26 12 L41 21 L41 39 L26 48 L11 39 L11 21 Z" fill="#8B5CF6"/>
7
+ </g>
8
+ <text x="92" y="52" font-family="ui-monospace,SFMono-Regular,Menlo,monospace" font-size="22" fill="#F8FAFC" font-weight="700">@xemahq/database-driver-postgres</text>
9
+ <text x="92" y="80" font-family="ui-sans-serif,system-ui,sans-serif" font-size="15" fill="#94A3B8">PostgreSQL driver for org-managed databases</text>
10
+ <text x="652" y="105" text-anchor="end" font-family="ui-sans-serif,system-ui,sans-serif" font-size="12" fill="#475569">xema.dev</text>
11
+ </svg>
12
+ </p>
13
+
14
+ <p align="center">
15
+ <a href="https://xema.dev">Website</a> &middot;
16
+ <a href="https://www.npmjs.com/package/@xemahq/database-driver-postgres">npm</a>
17
+ </p>
18
+
19
+ <p align="center">
20
+ <img alt="npm" src="https://img.shields.io/npm/v/%40xemahq%2Fdatabase-driver-postgres?color=2563eb&label=npm">
21
+ <img alt="license" src="https://img.shields.io/npm/l/%40xemahq%2Fdatabase-driver-postgres?color=10b981">
22
+ <img alt="types" src="https://img.shields.io/npm/types/%40xemahq%2Fdatabase-driver-postgres?color=3178c6">
23
+ </p>
24
+
25
+ # @xemahq/database-driver-postgres
26
+
27
+ > PostgreSQL driver for org-managed databases
28
+
29
+ ## Overview
30
+
31
+ A PostgreSQL implementation of the org-database driver contract. It provisions
32
+ databases, ensures and drops per-org schemas with read-write and read-only
33
+ roles, and mints short-lived connection grants. It also ships a provisioner
34
+ pool for managing the underlying admin connections. Pairs with the shared
35
+ org-database driver interface so consumers stay engine-agnostic.
36
+
37
+ ## When to use it
38
+
39
+ - Use it to provision and manage org-scoped PostgreSQL databases behind the
40
+ shared driver contract.
41
+
42
+ ## Installation
43
+
44
+ ```bash
45
+ pnpm add @xemahq/database-driver-postgres
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ ```ts
51
+ import { PostgresDatabaseDriver } from '@xemahq/database-driver-postgres';
52
+
53
+ const driver = new PostgresDatabaseDriver(provisionerPool);
54
+ await driver.provision({ orgId, databaseName });
55
+ ```
56
+
57
+ ## License
58
+
59
+ Apache-2.0 &copy; Xema — [xema.dev](https://xema.dev)
@@ -0,0 +1,4 @@
1
+ export { PostgresDatabaseDriver } from './lib/postgres-driver';
2
+ export { ProvisionerPool } from './lib/provisioner-pool';
3
+ export type { ProvisionerPoolConfig } from './lib/provisioner-pool';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,YAAY,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProvisionerPool = exports.PostgresDatabaseDriver = void 0;
4
+ var postgres_driver_1 = require("./lib/postgres-driver");
5
+ Object.defineProperty(exports, "PostgresDatabaseDriver", { enumerable: true, get: function () { return postgres_driver_1.PostgresDatabaseDriver; } });
6
+ var provisioner_pool_1 = require("./lib/provisioner-pool");
7
+ Object.defineProperty(exports, "ProvisionerPool", { enumerable: true, get: function () { return provisioner_pool_1.ProvisionerPool; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+D;AAAtD,yHAAA,sBAAsB,OAAA;AAC/B,2DAAyD;AAAhD,mHAAA,eAAe,OAAA"}
@@ -0,0 +1,19 @@
1
+ import { DbDriverKind, type ConnectionGrant, type DatabaseDriver, type DropSchemaInput, type EnsureSchemaInput, type MintConnectionInput, type ProvisionInput } from '@xemahq/kernel-contracts/org-database';
2
+ import type { ProvisionerPool } from './provisioner-pool';
3
+ export declare class PostgresDatabaseDriver implements DatabaseDriver {
4
+ private readonly pool;
5
+ private readonly poolHost;
6
+ private readonly poolPort;
7
+ readonly kind = DbDriverKind.Postgres;
8
+ constructor(pool: ProvisionerPool, poolHost: string, poolPort: number);
9
+ provisionOrgDatabase(input: ProvisionInput): Promise<{
10
+ databaseName: string;
11
+ }>;
12
+ ensureSchema(input: EnsureSchemaInput): Promise<void>;
13
+ dropSchema(input: DropSchemaInput): Promise<void>;
14
+ dropOrgDatabase(databaseName: string): Promise<void>;
15
+ mintConnection(input: MintConnectionInput): Promise<ConnectionGrant>;
16
+ private sanitizeIdentifier;
17
+ private escapeLiteral;
18
+ }
19
+ //# sourceMappingURL=postgres-driver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-driver.d.ts","sourceRoot":"","sources":["../../src/lib/postgres-driver.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,YAAY,EACZ,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACpB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,qBAAa,sBAAuB,YAAW,cAAc;IAIzD,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAL3B,QAAQ,CAAC,IAAI,yBAAyB;gBAGnB,IAAI,EAAE,eAAe,EACrB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM;IAG7B,oBAAoB,CACxB,KAAK,EAAE,cAAc,GACpB,OAAO,CAAC;QAAE,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;IAsB9B,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IA0DrD,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IA4CjD,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBpD,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,eAAe,CAAC;IAmC1E,OAAO,CAAC,kBAAkB;IAQ1B,OAAO,CAAC,aAAa;CAGtB"}
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PostgresDatabaseDriver = void 0;
4
+ const crypto_1 = require("crypto");
5
+ const org_database_1 = require("@xemahq/kernel-contracts/org-database");
6
+ class PostgresDatabaseDriver {
7
+ pool;
8
+ poolHost;
9
+ poolPort;
10
+ kind = org_database_1.DbDriverKind.Postgres;
11
+ constructor(pool, poolHost, poolPort) {
12
+ this.pool = pool;
13
+ this.poolHost = poolHost;
14
+ this.poolPort = poolPort;
15
+ }
16
+ async provisionOrgDatabase(input) {
17
+ const { databaseName } = input;
18
+ const client = await this.pool.pg.connect();
19
+ try {
20
+ const res = await client.query(`SELECT datname FROM pg_database WHERE datname = $1`, [databaseName]);
21
+ if (res.rowCount === 0) {
22
+ await client.query(`CREATE DATABASE "${this.sanitizeIdentifier(databaseName)}"`);
23
+ }
24
+ return { databaseName };
25
+ }
26
+ finally {
27
+ client.release();
28
+ }
29
+ }
30
+ async ensureSchema(input) {
31
+ const { databaseName, schemaName, rwRoleName, roRoleName } = input;
32
+ const { Pool } = await import('pg');
33
+ const targetPool = new Pool({
34
+ host: this.poolHost,
35
+ port: this.poolPort,
36
+ database: databaseName,
37
+ user: this.pool.pg.options.user,
38
+ password: this.pool.pg.options.password,
39
+ max: 2,
40
+ });
41
+ const client = await targetPool.connect();
42
+ try {
43
+ const sn = this.sanitizeIdentifier(schemaName);
44
+ const rw = this.sanitizeIdentifier(rwRoleName);
45
+ const ro = this.sanitizeIdentifier(roRoleName);
46
+ const rwLit = this.escapeLiteral(rwRoleName);
47
+ const roLit = this.escapeLiteral(roRoleName);
48
+ await client.query(`CREATE SCHEMA IF NOT EXISTS "${sn}"`);
49
+ await client.query(`
50
+ DO $$
51
+ BEGIN
52
+ IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = '${rwLit}') THEN
53
+ CREATE ROLE "${rw}" NOLOGIN;
54
+ END IF;
55
+ END
56
+ $$;
57
+ `);
58
+ await client.query(`
59
+ DO $$
60
+ BEGIN
61
+ IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = '${roLit}') THEN
62
+ CREATE ROLE "${ro}" NOLOGIN;
63
+ END IF;
64
+ END
65
+ $$;
66
+ `);
67
+ await client.query(`GRANT USAGE, CREATE ON SCHEMA "${sn}" TO "${rw}"`);
68
+ await client.query(`GRANT USAGE ON SCHEMA "${sn}" TO "${ro}"`);
69
+ await client.query(`ALTER DEFAULT PRIVILEGES IN SCHEMA "${sn}" GRANT SELECT ON TABLES TO "${ro}"`);
70
+ }
71
+ finally {
72
+ client.release();
73
+ await targetPool.end();
74
+ }
75
+ }
76
+ async dropSchema(input) {
77
+ const { databaseName, schemaName, rwRoleName, roRoleName } = input;
78
+ const { Pool } = await import('pg');
79
+ const targetPool = new Pool({
80
+ host: this.poolHost,
81
+ port: this.poolPort,
82
+ database: databaseName,
83
+ user: this.pool.pg.options.user,
84
+ password: this.pool.pg.options.password,
85
+ max: 2,
86
+ });
87
+ const client = await targetPool.connect();
88
+ try {
89
+ const sn = this.sanitizeIdentifier(schemaName);
90
+ const rw = this.sanitizeIdentifier(rwRoleName);
91
+ const ro = this.sanitizeIdentifier(roRoleName);
92
+ const rwLit = this.escapeLiteral(rwRoleName);
93
+ const roLit = this.escapeLiteral(roRoleName);
94
+ await client.query(`DROP SCHEMA IF EXISTS "${sn}" CASCADE`);
95
+ await client.query(`
96
+ DO $$
97
+ BEGIN
98
+ IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = '${rwLit}') THEN
99
+ DROP ROLE "${rw}";
100
+ END IF;
101
+ END
102
+ $$;
103
+ `);
104
+ await client.query(`
105
+ DO $$
106
+ BEGIN
107
+ IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = '${roLit}') THEN
108
+ DROP ROLE "${ro}";
109
+ END IF;
110
+ END
111
+ $$;
112
+ `);
113
+ }
114
+ finally {
115
+ client.release();
116
+ await targetPool.end();
117
+ }
118
+ }
119
+ async dropOrgDatabase(databaseName) {
120
+ const client = await this.pool.pg.connect();
121
+ try {
122
+ await client.query(`
123
+ SELECT pg_terminate_backend(pid)
124
+ FROM pg_stat_activity
125
+ WHERE datname = $1 AND pid <> pg_backend_pid()
126
+ `, [databaseName]);
127
+ await client.query(`DROP DATABASE IF EXISTS "${this.sanitizeIdentifier(databaseName)}"`);
128
+ }
129
+ finally {
130
+ client.release();
131
+ }
132
+ }
133
+ async mintConnection(input) {
134
+ const { databaseName, schemaName, roleName, ttlSeconds } = input;
135
+ const tmpUser = `xema_tmp_${(0, crypto_1.randomBytes)(6).toString('hex')}`;
136
+ const tmpPassword = (0, crypto_1.randomBytes)(24).toString('base64url');
137
+ const expiresAt = new Date(Date.now() + ttlSeconds * 1000);
138
+ const client = await this.pool.pg.connect();
139
+ try {
140
+ const u = this.sanitizeIdentifier(tmpUser);
141
+ const r = this.sanitizeIdentifier(roleName);
142
+ await client.query(`CREATE USER "${u}" WITH PASSWORD '${tmpPassword}' CONNECTION LIMIT 5`);
143
+ await client.query(`GRANT "${r}" TO "${u}"`);
144
+ }
145
+ finally {
146
+ client.release();
147
+ }
148
+ return {
149
+ host: this.poolHost,
150
+ port: this.poolPort,
151
+ database: databaseName,
152
+ schema: schemaName,
153
+ user: tmpUser,
154
+ password: tmpPassword,
155
+ expiresAt,
156
+ };
157
+ }
158
+ sanitizeIdentifier(value) {
159
+ return value.replace(/"/g, '""');
160
+ }
161
+ escapeLiteral(value) {
162
+ return value.replace(/'/g, "''");
163
+ }
164
+ }
165
+ exports.PostgresDatabaseDriver = PostgresDatabaseDriver;
166
+ //# sourceMappingURL=postgres-driver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-driver.js","sourceRoot":"","sources":["../../src/lib/postgres-driver.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AAIrC,wEAQ+C;AAI/C,MAAa,sBAAsB;IAId;IACA;IACA;IALV,IAAI,GAAG,2BAAY,CAAC,QAAQ,CAAC;IAEtC,YACmB,IAAqB,EACrB,QAAgB,EAChB,QAAgB;QAFhB,SAAI,GAAJ,IAAI,CAAiB;QACrB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,aAAQ,GAAR,QAAQ,CAAQ;IAChC,CAAC;IAEJ,KAAK,CAAC,oBAAoB,CACxB,KAAqB;QAErB,MAAM,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;QAC/B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;QAC5C,IAAI,CAAC;YAEH,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,KAAK,CAC5B,oDAAoD,EACpD,CAAC,YAAY,CAAC,CACf,CAAC;YACF,IAAI,GAAG,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;gBAGvB,MAAM,MAAM,CAAC,KAAK,CAChB,oBAAoB,IAAI,CAAC,kBAAkB,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WAAW,GAAG,IAAA,oBAAW,EAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAC1D,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,UAAU,GAAG,IAAI,CAAC,CAAC;QAE3D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;QAC5C,IAAI,CAAC;YACH,MAAM,CAAC,GAAG,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;YAC3C,MAAM,CAAC,GAAG,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;YAE5C,MAAM,MAAM,CAAC,KAAK,CAChB,gBAAgB,CAAC,oBAAoB,WAAW,sBAAsB,CACvE,CAAC;YACF,MAAM,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAC/C,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,CAAC;QAED,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,QAAQ;YACnB,IAAI,EAAE,IAAI,CAAC,QAAQ;YACnB,QAAQ,EAAE,YAAY;YACtB,MAAM,EAAE,UAAU;YAClB,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,WAAW;YACrB,SAAS;SACV,CAAC;IACJ,CAAC;IAOO,kBAAkB,CAAC,KAAa;QACtC,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;IAMO,aAAa,CAAC,KAAa;QACjC,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;CACF;AAtMD,wDAsMC"}
@@ -0,0 +1,16 @@
1
+ import { Pool } from 'pg';
2
+ export interface ProvisionerPoolConfig {
3
+ host: string;
4
+ port: number;
5
+ database: string;
6
+ user: string;
7
+ password: string;
8
+ ssl?: boolean;
9
+ }
10
+ export declare class ProvisionerPool {
11
+ private readonly pool;
12
+ constructor(config: ProvisionerPoolConfig);
13
+ get pg(): Pool;
14
+ end(): Promise<void>;
15
+ }
16
+ //# sourceMappingURL=provisioner-pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provisioner-pool.d.ts","sourceRoot":"","sources":["../../src/lib/provisioner-pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE1B,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAO;gBAEhB,MAAM,EAAE,qBAAqB;IAYzC,IAAI,EAAE,IAAI,IAAI,CAEb;IAEK,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAG3B"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProvisionerPool = void 0;
4
+ const pg_1 = require("pg");
5
+ class ProvisionerPool {
6
+ pool;
7
+ constructor(config) {
8
+ this.pool = new pg_1.Pool({
9
+ host: config.host,
10
+ port: config.port,
11
+ database: config.database,
12
+ user: config.user,
13
+ password: config.password,
14
+ ssl: config.ssl ? { rejectUnauthorized: false } : false,
15
+ max: 5,
16
+ });
17
+ }
18
+ get pg() {
19
+ return this.pool;
20
+ }
21
+ async end() {
22
+ await this.pool.end();
23
+ }
24
+ }
25
+ exports.ProvisionerPool = ProvisionerPool;
26
+ //# sourceMappingURL=provisioner-pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provisioner-pool.js","sourceRoot":"","sources":["../../src/lib/provisioner-pool.ts"],"names":[],"mappings":";;;AAAA,2BAA0B;AAW1B,MAAa,eAAe;IACT,IAAI,CAAO;IAE5B,YAAY,MAA6B;QACvC,IAAI,CAAC,IAAI,GAAG,IAAI,SAAI,CAAC;YACnB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK;YACvD,GAAG,EAAE,CAAC;SACP,CAAC,CAAC;IACL,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,GAAG;QACP,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;IACxB,CAAC;CACF;AAtBD,0CAsBC"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@xemahq/database-driver-postgres",
3
+ "version": "0.1.1",
4
+ "description": "PostgreSQL DatabaseDriver implementation for org-managed databases.",
5
+ "publishConfig": {
6
+ "registry": "https://npm.pkg.github.com"
7
+ },
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "dependencies": {
14
+ "@xemahq/kernel-contracts": "^0.2.0",
15
+ "pg": "8.16.3"
16
+ },
17
+ "devDependencies": {
18
+ "@types/node": "25.2.3",
19
+ "@types/pg": "^8.16.0",
20
+ "prettier": "3.6.2",
21
+ "typescript": "5.9.3"
22
+ },
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "xema-source": "./src/index.ts",
27
+ "default": "./dist/index.js"
28
+ },
29
+ "./dist/lib/*": {
30
+ "types": "./dist/lib/*.d.ts",
31
+ "default": "./dist/lib/*.js"
32
+ }
33
+ },
34
+ "scripts": {
35
+ "clean": "rm -rf dist",
36
+ "build": "tsc -p tsconfig.json",
37
+ "format": "prettier --write \"src/**/*.ts\"",
38
+ "typecheck": "tsc -p tsconfig.json --noEmit"
39
+ }
40
+ }