@hesed/psql 0.1.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.
Files changed (42) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +293 -0
  3. package/bin/dev.cmd +3 -0
  4. package/bin/dev.js +5 -0
  5. package/bin/run.cmd +3 -0
  6. package/bin/run.js +5 -0
  7. package/dist/commands/psql/auth/add.d.ts +18 -0
  8. package/dist/commands/psql/auth/add.js +57 -0
  9. package/dist/commands/psql/auth/test.d.ts +12 -0
  10. package/dist/commands/psql/auth/test.js +41 -0
  11. package/dist/commands/psql/auth/update.d.ts +18 -0
  12. package/dist/commands/psql/auth/update.js +74 -0
  13. package/dist/commands/psql/databases.d.ts +9 -0
  14. package/dist/commands/psql/databases.js +31 -0
  15. package/dist/commands/psql/describe-table.d.ts +13 -0
  16. package/dist/commands/psql/describe-table.js +39 -0
  17. package/dist/commands/psql/explain-query.d.ts +13 -0
  18. package/dist/commands/psql/explain-query.js +39 -0
  19. package/dist/commands/psql/indexes.d.ts +13 -0
  20. package/dist/commands/psql/indexes.js +39 -0
  21. package/dist/commands/psql/query.d.ts +14 -0
  22. package/dist/commands/psql/query.js +47 -0
  23. package/dist/commands/psql/tables.d.ts +9 -0
  24. package/dist/commands/psql/tables.js +31 -0
  25. package/dist/config.d.ts +13 -0
  26. package/dist/config.js +18 -0
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.js +1 -0
  29. package/dist/psql/config-loader.d.ts +28 -0
  30. package/dist/psql/config-loader.js +26 -0
  31. package/dist/psql/database.d.ts +85 -0
  32. package/dist/psql/database.js +5 -0
  33. package/dist/psql/index.d.ts +3 -0
  34. package/dist/psql/index.js +1 -0
  35. package/dist/psql/postgres-client.d.ts +60 -0
  36. package/dist/psql/postgres-client.js +131 -0
  37. package/dist/psql/postgres-utils.d.ts +72 -0
  38. package/dist/psql/postgres-utils.js +364 -0
  39. package/dist/psql/query-validator.d.ts +38 -0
  40. package/dist/psql/query-validator.js +91 -0
  41. package/oclif.manifest.json +521 -0
  42. package/package.json +103 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Hesed
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,293 @@
1
+ # psql
2
+
3
+ CLI for PostgreSQL database interaction
4
+
5
+ [![Version](https://img.shields.io/npm/v/@hesed/psql.svg)](https://npmjs.org/package/@hesed/psql)
6
+ [![Downloads/week](https://img.shields.io/npm/dw/@hesed/psql.svg)](https://npmjs.org/package/@hesed/psql)
7
+
8
+ # Install
9
+
10
+ ```bash
11
+ sdkck plugins install @hesed/psql
12
+ ```
13
+
14
+ <!-- toc -->
15
+ * [psql](#psql)
16
+ * [Install](#install)
17
+ * [Usage](#usage)
18
+ * [Commands](#commands)
19
+ <!-- tocstop -->
20
+
21
+ # Usage
22
+
23
+ <!-- usage -->
24
+ ```sh-session
25
+ $ npm install -g @hesed/psql
26
+ $ pg COMMAND
27
+ running command...
28
+ $ pg (--version)
29
+ @hesed/psql/0.1.0 darwin-arm64 node-v22.14.0
30
+ $ pg --help [COMMAND]
31
+ USAGE
32
+ $ pg COMMAND
33
+ ...
34
+ ```
35
+ <!-- usagestop -->
36
+
37
+ # Commands
38
+
39
+ <!-- commands -->
40
+ * [`pg psql auth add`](#pg-psql-auth-add)
41
+ * [`pg psql auth test`](#pg-psql-auth-test)
42
+ * [`pg psql auth update`](#pg-psql-auth-update)
43
+ * [`pg psql databases`](#pg-psql-databases)
44
+ * [`pg psql describe-table TABLE`](#pg-psql-describe-table-table)
45
+ * [`pg psql explain-query QUERY`](#pg-psql-explain-query-query)
46
+ * [`pg psql indexes TABLE`](#pg-psql-indexes-table)
47
+ * [`pg psql query QUERY`](#pg-psql-query-query)
48
+ * [`pg psql tables`](#pg-psql-tables)
49
+
50
+ ## `pg psql auth add`
51
+
52
+ Add a PostgreSQL connection profile
53
+
54
+ ```
55
+ USAGE
56
+ $ pg psql auth add [--json] [-d <value>] [--host <value>] [-p <value>] [-P <value>] [--profile <value>] [--ssl]
57
+ [-u <value>]
58
+
59
+ FLAGS
60
+ -P, --port=<value> PostgreSQL port
61
+ -d, --database=<value> Database name
62
+ -p, --password=<value> Password
63
+ -u, --user=<value> Username
64
+ --host=<value> PostgreSQL host
65
+ --profile=<value> Profile name
66
+ --[no-]ssl Use SSL
67
+
68
+ GLOBAL FLAGS
69
+ --json Format output as json.
70
+
71
+ DESCRIPTION
72
+ Add a PostgreSQL connection profile
73
+
74
+ EXAMPLES
75
+ $ pg psql auth add
76
+
77
+ $ pg psql auth add --no-ssl
78
+ ```
79
+
80
+ _See code: [src/commands/psql/auth/add.ts](https://github.com/hesedcasa/psql/blob/v0.1.0/src/commands/psql/auth/add.ts)_
81
+
82
+ ## `pg psql auth test`
83
+
84
+ Test PostgreSQL database connection
85
+
86
+ ```
87
+ USAGE
88
+ $ pg psql auth test [--json] [--profile <value>]
89
+
90
+ FLAGS
91
+ --profile=<value> Profile name to test
92
+
93
+ GLOBAL FLAGS
94
+ --json Format output as json.
95
+
96
+ DESCRIPTION
97
+ Test PostgreSQL database connection
98
+
99
+ EXAMPLES
100
+ $ pg psql auth test
101
+
102
+ $ pg psql auth test --profile staging
103
+ ```
104
+
105
+ _See code: [src/commands/psql/auth/test.ts](https://github.com/hesedcasa/psql/blob/v0.1.0/src/commands/psql/auth/test.ts)_
106
+
107
+ ## `pg psql auth update`
108
+
109
+ Update an existing PostgreSQL connection profile
110
+
111
+ ```
112
+ USAGE
113
+ $ pg psql auth update [--json] [-d <value>] [--host <value>] [-p <value>] [-P <value>] [--profile <value>] [--ssl]
114
+ [-u <value>]
115
+
116
+ FLAGS
117
+ -P, --port=<value> PostgreSQL port
118
+ -d, --database=<value> Database name
119
+ -p, --password=<value> Password
120
+ -u, --user=<value> Username
121
+ --host=<value> PostgreSQL host
122
+ --profile=<value> Profile name to update
123
+ --[no-]ssl Use SSL
124
+
125
+ GLOBAL FLAGS
126
+ --json Format output as json.
127
+
128
+ DESCRIPTION
129
+ Update an existing PostgreSQL connection profile
130
+
131
+ EXAMPLES
132
+ $ pg psql auth update --ssl
133
+
134
+ $ pg psql auth update --profile staging
135
+ ```
136
+
137
+ _See code: [src/commands/psql/auth/update.ts](https://github.com/hesedcasa/psql/blob/v0.1.0/src/commands/psql/auth/update.ts)_
138
+
139
+ ## `pg psql databases`
140
+
141
+ List all databases accessible on the PostgreSQL server
142
+
143
+ ```
144
+ USAGE
145
+ $ pg psql databases [--profile <value>]
146
+
147
+ FLAGS
148
+ --profile=<value> Database profile name from config
149
+
150
+ DESCRIPTION
151
+ List all databases accessible on the PostgreSQL server
152
+
153
+ EXAMPLES
154
+ $ pg psql databases
155
+
156
+ $ pg psql databases --profile staging
157
+ ```
158
+
159
+ _See code: [src/commands/psql/databases.ts](https://github.com/hesedcasa/psql/blob/v0.1.0/src/commands/psql/databases.ts)_
160
+
161
+ ## `pg psql describe-table TABLE`
162
+
163
+ Describe the structure of a PostgreSQL table
164
+
165
+ ```
166
+ USAGE
167
+ $ pg psql describe-table TABLE [--format table|json|toon] [--profile <value>]
168
+
169
+ ARGUMENTS
170
+ TABLE Table name to describe
171
+
172
+ FLAGS
173
+ --format=<option> [default: table] Output format
174
+ <options: table|json|toon>
175
+ --profile=<value> Database profile name from config
176
+
177
+ DESCRIPTION
178
+ Describe the structure of a PostgreSQL table
179
+
180
+ EXAMPLES
181
+ $ pg psql describe-table users
182
+
183
+ $ pg psql describe-table orders --format json --profile prod
184
+ ```
185
+
186
+ _See code: [src/commands/psql/describe-table.ts](https://github.com/hesedcasa/psql/blob/v0.1.0/src/commands/psql/describe-table.ts)_
187
+
188
+ ## `pg psql explain-query QUERY`
189
+
190
+ Show the execution plan for a PostgreSQL query
191
+
192
+ ```
193
+ USAGE
194
+ $ pg psql explain-query QUERY [--format table|json|toon] [--profile <value>]
195
+
196
+ ARGUMENTS
197
+ QUERY SQL query to explain
198
+
199
+ FLAGS
200
+ --format=<option> [default: table] Output format
201
+ <options: table|json|toon>
202
+ --profile=<value> Database profile name from config
203
+
204
+ DESCRIPTION
205
+ Show the execution plan for a PostgreSQL query
206
+
207
+ EXAMPLES
208
+ $ pg psql explain-query "SELECT * FROM users WHERE id = 1"
209
+
210
+ $ pg psql explain-query "SELECT * FROM orders JOIN users ON orders.user_id = users.id" --format json
211
+ ```
212
+
213
+ _See code: [src/commands/psql/explain-query.ts](https://github.com/hesedcasa/psql/blob/v0.1.0/src/commands/psql/explain-query.ts)_
214
+
215
+ ## `pg psql indexes TABLE`
216
+
217
+ Show indexes for a PostgreSQL table
218
+
219
+ ```
220
+ USAGE
221
+ $ pg psql indexes TABLE [--format table|json|toon] [--profile <value>]
222
+
223
+ ARGUMENTS
224
+ TABLE Table name to show indexes for
225
+
226
+ FLAGS
227
+ --format=<option> [default: table] Output format
228
+ <options: table|json|toon>
229
+ --profile=<value> Database profile name from config
230
+
231
+ DESCRIPTION
232
+ Show indexes for a PostgreSQL table
233
+
234
+ EXAMPLES
235
+ $ pg psql indexes users
236
+
237
+ $ pg psql indexes orders --format json --profile prod
238
+ ```
239
+
240
+ _See code: [src/commands/psql/indexes.ts](https://github.com/hesedcasa/psql/blob/v0.1.0/src/commands/psql/indexes.ts)_
241
+
242
+ ## `pg psql query QUERY`
243
+
244
+ Execute a SQL query against a PostgreSQL database
245
+
246
+ ```
247
+ USAGE
248
+ $ pg psql query QUERY [--format table|json|csv|toon] [--profile <value>] [--skip-confirmation]
249
+
250
+ ARGUMENTS
251
+ QUERY SQL query to execute
252
+
253
+ FLAGS
254
+ --format=<option> [default: table] Output format
255
+ <options: table|json|csv|toon>
256
+ --profile=<value> Database profile name from config
257
+ --skip-confirmation Skip confirmation prompt for destructive operations
258
+
259
+ DESCRIPTION
260
+ Execute a SQL query against a PostgreSQL database
261
+
262
+ EXAMPLES
263
+ $ pg psql query "SELECT * FROM users LIMIT 10"
264
+
265
+ $ pg psql query "UPDATE users SET email = 'user@email.com' WHERE id = 999" --format json
266
+
267
+ $ pg psql query "DELETE FROM sessions" --profile prod --skip-confirmation
268
+ ```
269
+
270
+ _See code: [src/commands/psql/query.ts](https://github.com/hesedcasa/psql/blob/v0.1.0/src/commands/psql/query.ts)_
271
+
272
+ ## `pg psql tables`
273
+
274
+ List all tables in the current PostgreSQL database
275
+
276
+ ```
277
+ USAGE
278
+ $ pg psql tables [--profile <value>]
279
+
280
+ FLAGS
281
+ --profile=<value> Database profile name from config
282
+
283
+ DESCRIPTION
284
+ List all tables in the current PostgreSQL database
285
+
286
+ EXAMPLES
287
+ $ pg psql tables
288
+
289
+ $ pg psql tables --profile local
290
+ ```
291
+
292
+ _See code: [src/commands/psql/tables.ts](https://github.com/hesedcasa/psql/blob/v0.1.0/src/commands/psql/tables.ts)_
293
+ <!-- commandsstop -->
package/bin/dev.cmd ADDED
@@ -0,0 +1,3 @@
1
+ @echo off
2
+
3
+ node --loader ts-node/esm --no-warnings=ExperimentalWarning "%~dp0\dev" %*
package/bin/dev.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env -S node --loader ts-node/esm --disable-warning=ExperimentalWarning
2
+
3
+ import {execute} from '@oclif/core'
4
+
5
+ await execute({development: true, dir: import.meta.url})
package/bin/run.cmd ADDED
@@ -0,0 +1,3 @@
1
+ @echo off
2
+
3
+ node "%~dp0\run" %*
package/bin/run.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {execute} from '@oclif/core'
4
+
5
+ await execute({dir: import.meta.url})
@@ -0,0 +1,18 @@
1
+ import { Command } from '@oclif/core';
2
+ import type { ConnectionTestResult } from '../../../psql/index.js';
3
+ export default class AuthAdd extends Command {
4
+ static args: {};
5
+ static description: string;
6
+ static enableJsonFlag: boolean;
7
+ static examples: string[];
8
+ static flags: {
9
+ database: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ host: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ password: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ port: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ ssl: import("@oclif/core/interfaces").BooleanFlag<boolean>;
15
+ user: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ };
17
+ run(): Promise<ConnectionTestResult>;
18
+ }
@@ -0,0 +1,57 @@
1
+ import { input } from '@inquirer/prompts';
2
+ import { Command, Flags } from '@oclif/core';
3
+ import { action } from '@oclif/core/ux';
4
+ import { default as fs } from 'fs-extra';
5
+ import { default as path } from 'node:path';
6
+ import { testDirectConnection } from '../../../psql/index.js';
7
+ export default class AuthAdd extends Command {
8
+ static args = {};
9
+ static description = 'Add a PostgreSQL connection profile';
10
+ static enableJsonFlag = true;
11
+ static examples = ['<%= config.bin %> <%= command.id %>', '<%= config.bin %> <%= command.id %> --no-ssl'];
12
+ static flags = {
13
+ database: Flags.string({ char: 'd', description: 'Database name', required: !process.stdout.isTTY }),
14
+ host: Flags.string({ description: 'PostgreSQL host', required: !process.stdout.isTTY }),
15
+ password: Flags.string({ char: 'p', description: 'Password', required: !process.stdout.isTTY }),
16
+ port: Flags.integer({ char: 'P', description: 'PostgreSQL port', required: !process.stdout.isTTY }),
17
+ profile: Flags.string({ description: 'Profile name', required: !process.stdout.isTTY }),
18
+ ssl: Flags.boolean({ allowNo: true, default: false, description: 'Use SSL', required: false }),
19
+ user: Flags.string({ char: 'u', description: 'Username', required: !process.stdout.isTTY }),
20
+ };
21
+ async run() {
22
+ const { flags } = await this.parse(AuthAdd);
23
+ const profileName = flags.profile ?? (await input({ message: 'Profile name:', required: true }));
24
+ const host = flags.host ?? (await input({ message: 'PostgreSQL host:', required: true }));
25
+ const port = flags.port ?? Number(await input({ default: '5432', message: 'Port:', required: true }));
26
+ const user = flags.user ?? (await input({ message: 'Username:', required: true }));
27
+ const password = flags.password ?? (await input({ message: 'Password:', required: true }));
28
+ const database = flags.database ?? (await input({ message: 'Database:', required: true }));
29
+ const configPath = path.join(this.config.configDir, 'pg-config.json');
30
+ const profileData = { database, host, password, port, ssl: flags.ssl, user };
31
+ const exists = await fs.pathExists(configPath);
32
+ let config;
33
+ if (exists) {
34
+ config = await fs.readJSON(configPath);
35
+ }
36
+ else {
37
+ await fs.createFile(configPath);
38
+ config = { defaultProfile: profileName, profiles: {} };
39
+ }
40
+ config.profiles[profileName] = profileData;
41
+ if (Object.keys(config.profiles).length === 1) {
42
+ config.defaultProfile = profileName;
43
+ }
44
+ await fs.writeJSON(configPath, config, { mode: 0o600 });
45
+ action.start('Testing connection');
46
+ const result = await testDirectConnection(profileData);
47
+ if (result.success) {
48
+ action.stop('✓ successful');
49
+ this.log(`Profile "${profileName}" added successfully`);
50
+ }
51
+ else {
52
+ action.stop('✗ failed');
53
+ this.error('Connection failed. Please check your configuration.');
54
+ }
55
+ return result;
56
+ }
57
+ }
@@ -0,0 +1,12 @@
1
+ import { Command } from '@oclif/core';
2
+ import type { ConnectionTestResult } from '../../../psql/index.js';
3
+ export default class AuthTest extends Command {
4
+ static args: {};
5
+ static description: string;
6
+ static enableJsonFlag: boolean;
7
+ static examples: string[];
8
+ static flags: {
9
+ profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ };
11
+ run(): Promise<ConnectionTestResult>;
12
+ }
@@ -0,0 +1,41 @@
1
+ import { Command, Flags } from '@oclif/core';
2
+ import { action } from '@oclif/core/ux';
3
+ import { readConfig } from '../../../config.js';
4
+ import { testDirectConnection } from '../../../psql/index.js';
5
+ export default class AuthTest extends Command {
6
+ static args = {};
7
+ static description = 'Test PostgreSQL database connection';
8
+ static enableJsonFlag = true;
9
+ static examples = [
10
+ '<%= config.bin %> <%= command.id %>',
11
+ '<%= config.bin %> <%= command.id %> --profile staging',
12
+ ];
13
+ static flags = {
14
+ profile: Flags.string({ description: 'Profile name to test', required: false }),
15
+ };
16
+ async run() {
17
+ const { flags } = await this.parse(AuthTest);
18
+ const config = await readConfig(this.config.configDir, this.log.bind(this));
19
+ if (!config) {
20
+ return {
21
+ error: 'Missing connection config',
22
+ success: false,
23
+ };
24
+ }
25
+ const profile = config.profiles[flags.profile ?? config.defaultProfile];
26
+ if (!profile) {
27
+ this.error(`Profile "${flags.profile}" not found. Available: ${Object.keys(config.profiles).join(', ')}`);
28
+ }
29
+ action.start('Testing connection');
30
+ const result = await testDirectConnection(profile);
31
+ if (result.success) {
32
+ action.stop('✓ successful');
33
+ this.log('Successfully connected to PostgreSQL');
34
+ }
35
+ else {
36
+ action.stop('✗ failed');
37
+ this.error('Failed to connect to PostgreSQL.');
38
+ }
39
+ return result;
40
+ }
41
+ }
@@ -0,0 +1,18 @@
1
+ import { Command } from '@oclif/core';
2
+ import type { ConnectionTestResult } from '../../../psql/index.js';
3
+ export default class AuthUpdate extends Command {
4
+ static args: {};
5
+ static description: string;
6
+ static enableJsonFlag: boolean;
7
+ static examples: string[];
8
+ static flags: {
9
+ database: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ host: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ password: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ port: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ ssl: import("@oclif/core/interfaces").BooleanFlag<boolean>;
15
+ user: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ };
17
+ run(): Promise<ConnectionTestResult | void>;
18
+ }