@amerged/ohmyhost-cli 0.1.37 → 0.1.39
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 +1 -1
- package/THIRD_PARTY_NOTICES.md +27 -1
- package/dist/bin.js +1 -1
- package/dist/{chunk-IHXNADOQ.js → chunk-R2BC42EW.js} +4501 -134
- package/dist/index.js +1 -1
- package/dist/licenses/pgcf-bridge-LICENSE +201 -0
- package/dist/licenses/pgcf-bridge-NOTICE +1 -0
- package/package.json +1 -1
- package/src/apps/product-cli/package.json +4 -3
- package/src/apps/product-cli/src/cli.ts +7 -5
- package/src/apps/product-cli/src/command.ts +18 -5
- package/src/apps/product-cli/src/product-api.ts +22 -15
- package/src/apps/product-cli/src/psql-session.ts +54 -19
- package/src/apps/product-cli/src/repository-init.ts +181 -9
- package/src/packages/contracts/package.json +6 -1
- package/src/packages/contracts/src/credit-pricing.ts +7 -1
- package/src/packages/contracts/src/database-access.ts +53 -12
- package/src/packages/contracts/src/database-compute.ts +66 -11
- package/src/packages/contracts/src/database-sizes.ts +114 -0
- package/src/packages/contracts/src/framework-admission-corpus.ts +15 -18
- package/src/packages/contracts/src/framework-build-script.mjs +10 -3
- package/src/packages/contracts/src/index.ts +3 -0
- package/src/packages/contracts/src/operation-failure.ts +2 -2
- package/src/packages/contracts/src/platform-origins.ts +8 -0
- package/src/packages/contracts/src/problem-policy.ts +16 -2
- package/src/packages/contracts/src/storage-gateway-origin.ts +93 -0
- package/src/packages/postgres-bridge/LICENSE +201 -0
- package/src/packages/postgres-bridge/NOTICE +1 -0
- package/src/packages/postgres-bridge/package.json +26 -0
- package/src/packages/postgres-bridge/src/auth.ts +159 -0
- package/src/packages/postgres-bridge/src/bridge.ts +168 -0
- package/src/packages/postgres-bridge/src/index.ts +2 -0
- package/src/packages/postgres-bridge/src/options.ts +49 -0
- package/src/packages/sdk-ts/package.json +2 -2
- package/src/packages/sdk-ts/src/generated/index.ts +1 -0
- package/src/packages/sdk-ts/src/generated/sdk.gen.ts +9 -8
- package/src/packages/sdk-ts/src/generated/types.gen.ts +91 -24
- package/src/packages/sdk-ts/src/index.ts +1 -0
- package/src/packages/sdk-ts/src/managed-mail-attachment.ts +107 -0
- package/src/packages/workos-auth-contracts/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -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 reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and 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 Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
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 [yyyy] [name of copyright owner]
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PostgreSQL WebSocket bridge and authentication prelude handling adapted from cloudflare-postgres packages/cli, commit e05d9102c840e283602272ed0e16a95be3e3b8ea. Upstream license: Apache-2.0.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohmyhost/product-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.39",
|
|
4
4
|
"private": true,
|
|
5
5
|
"ohmyhost": {
|
|
6
6
|
"deployment": "production",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "tsc --project tsconfig.build.json",
|
|
35
|
-
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
35
|
+
"typecheck": "tsc --project tsconfig.json --noEmit --incremental --tsBuildInfoFile typecheck.tsbuildinfo",
|
|
36
36
|
"test": "vitest run --root ../.. apps/product-cli/test"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"@ohmyhost/sdk-ts": "workspace:*",
|
|
42
42
|
"@ohmyhost/workos-auth-contracts": "workspace:*",
|
|
43
43
|
"ignore": "7.0.12",
|
|
44
|
-
"isomorphic-git": "1.43.0"
|
|
44
|
+
"isomorphic-git": "1.43.0",
|
|
45
|
+
"@ohmyhost/postgres-bridge": "workspace:*"
|
|
45
46
|
},
|
|
46
47
|
"license": "Apache-2.0"
|
|
47
48
|
}
|
|
@@ -281,6 +281,7 @@ export interface ProductCliDependencies {
|
|
|
281
281
|
readonly operationEventSink?: { write(value: string): void };
|
|
282
282
|
readonly readSecretValue: (signal: AbortSignal) => Promise<string>;
|
|
283
283
|
readonly spawnPsql?: (input: {
|
|
284
|
+
readonly websocketUrl?: string;
|
|
284
285
|
readonly host: string;
|
|
285
286
|
readonly user: string;
|
|
286
287
|
readonly password: string;
|
|
@@ -321,7 +322,7 @@ type CustomerCommandLabel = Exclude<CommandLabel, "unknown" | "help" | "version"
|
|
|
321
322
|
|
|
322
323
|
const CLI_VERSION = cliPackage.version;
|
|
323
324
|
const HELP_USAGE = Object.freeze({
|
|
324
|
-
init: "ohmyhost init [--directory PATH] [--root PATH] [--project SLUG] [--region us|eu] [--dry-run] --json (pass the project's
|
|
325
|
+
init: "ohmyhost init [--directory PATH] [--root PATH] [--project SLUG] [--region us|eu] [--dry-run] --json (preserve existing storage jurisdiction; for new storage pass the project's region, us when omitted)",
|
|
325
326
|
login:
|
|
326
327
|
"ohmyhost login [--organization ULID] [--user USER_ID] [--profile-name NAME] --json (adds one saved login; nothing is saved unless the browser signed in as that user and organization)",
|
|
327
328
|
logout:
|
|
@@ -372,7 +373,7 @@ const HELP_USAGE = Object.freeze({
|
|
|
372
373
|
"feedback submit":
|
|
373
374
|
"ohmyhost feedback submit --organization ULID --kind bug|issue|feature_request --title TITLE --description REDACTED_REPORT [--project ULID] [--environment ULID] [--operation ULID] [--error-code CODE] [--client-version VERSION] --idempotency-key KEY --json",
|
|
374
375
|
"project create":
|
|
375
|
-
"ohmyhost project create --organization ULID --name NAME [--data-mode shared|isolated] [--dev-access-mode protected|public] [--region us|eu] --idempotency-key KEY --json (data mode is optional and defaults to shared; later assignments use project data plan/change without copying data; the region is chosen once: us is the default, eu
|
|
376
|
+
"ohmyhost project create --organization ULID --name NAME [--data-mode shared|isolated] [--dev-access-mode protected|public] [--region us|eu] --idempotency-key KEY --json (data mode is optional and defaults to shared; later assignments use project data plan/change without copying data; the region is chosen once: us is the default, eu selects EU database, new files and builds; existing R2 locations survive authorized region moves; the customer API cannot change region later)",
|
|
376
377
|
"project data plan":
|
|
377
378
|
"ohmyhost project data plan --project ULID --change isolate_prod_keeps_data|isolate_dev_keeps_data|share_prod_keeps_data|reset_dev --json (shared is the optional creation default; review which data is kept or deleted; no data is copied)",
|
|
378
379
|
"project data change":
|
|
@@ -398,8 +399,8 @@ const HELP_USAGE = Object.freeze({
|
|
|
398
399
|
"project handle set":
|
|
399
400
|
"ohmyhost project handle set --project ULID --handle HANDLE --if-match ETAG --idempotency-key KEY --json (moves the project to a free address; the old one stops working and anyone may claim it)",
|
|
400
401
|
"database compute set":
|
|
401
|
-
"ohmyhost database compute set --project ULID --environment dev|prod --
|
|
402
|
-
"
|
|
402
|
+
"ohmyhost database compute set --project ULID --environment dev|prod --memory-mib 256|512|1024|2048|4096 --idempotency-key KEY --yes [--wait] --json\n" +
|
|
403
|
+
" 10/20/40/80/160 credits per active hour, prorated; includes 500 MiB/1/2/4/8 GiB total disk and seven-day backups. Free supports 256 MiB; larger sizes require Paid. Sleep after 300 idle seconds. No separate database CPU, network or connection charge. Smaller disk requires a separate data migration. Transitional --profile standard|performance is accepted only for legacy provider use; never combine it with --memory-mib.",
|
|
403
404
|
"database compute get":
|
|
404
405
|
"ohmyhost database compute get --project ULID [--environment dev|prod] --json",
|
|
405
406
|
"database write":
|
|
@@ -1872,7 +1873,8 @@ export class ProductCli {
|
|
|
1872
1873
|
exitCode = await spawnPsql({
|
|
1873
1874
|
host: credential.host,
|
|
1874
1875
|
user: credential.role_name,
|
|
1875
|
-
password: new URL(credential.connection_uri).password,
|
|
1876
|
+
password: decodeURIComponent(new URL(credential.connection_uri).password),
|
|
1877
|
+
...(credential.provider === "pgcf" ? { websocketUrl: credential.websocket_url } : {}),
|
|
1876
1878
|
database: credential.database,
|
|
1877
1879
|
mode: credential.mode,
|
|
1878
1880
|
signal,
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { isUserSecretName } from "@ohmyhost/contracts/secret-names";
|
|
2
|
+
import {
|
|
3
|
+
databaseSizeForMemory,
|
|
4
|
+
type DatabaseComputeSelection,
|
|
5
|
+
} from "@ohmyhost/contracts/database-sizes";
|
|
2
6
|
import {
|
|
3
7
|
isProjectDataChangeKind,
|
|
4
8
|
type ProjectDataChangeKind,
|
|
@@ -92,15 +96,14 @@ export type ProductCliCommand =
|
|
|
92
96
|
readonly organizationId: string;
|
|
93
97
|
readonly credentialStore: "native";
|
|
94
98
|
}
|
|
95
|
-
| {
|
|
99
|
+
| ({
|
|
96
100
|
readonly kind: "database-compute-set";
|
|
97
101
|
readonly projectId: string;
|
|
98
102
|
readonly environment: "dev" | "prod";
|
|
99
|
-
readonly profile: "standard" | "performance";
|
|
100
103
|
readonly idempotencyKey: string;
|
|
101
104
|
readonly wait: boolean;
|
|
102
105
|
readonly credentialStore: "native";
|
|
103
|
-
}
|
|
106
|
+
} & DatabaseComputeSelection)
|
|
104
107
|
| {
|
|
105
108
|
readonly kind: "database-compute-get";
|
|
106
109
|
readonly projectId: string;
|
|
@@ -1761,20 +1764,30 @@ export const parseProductCliCommand = (argv: readonly string[]): ProductCliComma
|
|
|
1761
1764
|
"--project",
|
|
1762
1765
|
"--environment",
|
|
1763
1766
|
"--profile",
|
|
1767
|
+
"--memory-mib",
|
|
1764
1768
|
"--idempotency-key",
|
|
1765
1769
|
]);
|
|
1766
1770
|
if (
|
|
1767
1771
|
!options["--project"] ||
|
|
1768
1772
|
!options["--idempotency-key"] ||
|
|
1769
|
-
(options["--profile"]
|
|
1773
|
+
(options["--profile"] === undefined) === (options["--memory-mib"] === undefined) ||
|
|
1774
|
+
(options["--profile"] !== undefined &&
|
|
1775
|
+
options["--profile"] !== "standard" &&
|
|
1776
|
+
options["--profile"] !== "performance") ||
|
|
1770
1777
|
(options["--environment"] !== "dev" && options["--environment"] !== "prod")
|
|
1771
1778
|
)
|
|
1772
1779
|
throw new InvalidCommandError();
|
|
1780
|
+
let selection: DatabaseComputeSelection;
|
|
1781
|
+
if (options["--memory-mib"] !== undefined) {
|
|
1782
|
+
if (!/^(256|512|1024|2048|4096)$/u.test(options["--memory-mib"]))
|
|
1783
|
+
throw new InvalidCommandError();
|
|
1784
|
+
selection = { memoryMiB: databaseSizeForMemory(Number(options["--memory-mib"])).memoryMiB };
|
|
1785
|
+
} else selection = { profile: options["--profile"] as "standard" | "performance" };
|
|
1773
1786
|
return {
|
|
1774
1787
|
kind: "database-compute-set",
|
|
1775
1788
|
projectId: options["--project"],
|
|
1776
1789
|
environment: options["--environment"],
|
|
1777
|
-
|
|
1790
|
+
...selection,
|
|
1778
1791
|
idempotencyKey: options["--idempotency-key"],
|
|
1779
1792
|
wait,
|
|
1780
1793
|
credentialStore,
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
type ProjectDatabaseWriteReceipt,
|
|
21
21
|
} from "@ohmyhost/contracts/database-access";
|
|
22
22
|
import { assertDatabaseCompute, type DatabaseCompute } from "@ohmyhost/contracts/database-compute";
|
|
23
|
+
import type { DatabaseComputeSelection } from "@ohmyhost/contracts/database-sizes";
|
|
23
24
|
import {
|
|
24
25
|
assertProjectContext,
|
|
25
26
|
assertProjectNotesReceipt,
|
|
@@ -173,12 +174,13 @@ export interface ProductApi {
|
|
|
173
174
|
confirmationToken: string;
|
|
174
175
|
idempotencyKey: string;
|
|
175
176
|
}): Promise<Operation>;
|
|
176
|
-
changeDatabaseCompute(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
177
|
+
changeDatabaseCompute(
|
|
178
|
+
input: {
|
|
179
|
+
projectId: string;
|
|
180
|
+
environment: "dev" | "prod";
|
|
181
|
+
idempotencyKey: string;
|
|
182
|
+
} & DatabaseComputeSelection,
|
|
183
|
+
): Promise<import("@ohmyhost/sdk-ts").Operation>;
|
|
182
184
|
getDatabaseCompute(input: {
|
|
183
185
|
projectId: string;
|
|
184
186
|
environment: "dev" | "prod";
|
|
@@ -456,18 +458,23 @@ export class GeneratedSdkProductApi implements ProductApi {
|
|
|
456
458
|
this.managedSource = new GeneratedSdkManagedSourceApi(() => this.#client);
|
|
457
459
|
}
|
|
458
460
|
|
|
459
|
-
public async changeDatabaseCompute(
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
461
|
+
public async changeDatabaseCompute(
|
|
462
|
+
input: {
|
|
463
|
+
projectId: string;
|
|
464
|
+
environment: "dev" | "prod";
|
|
465
|
+
idempotencyKey: string;
|
|
466
|
+
} & DatabaseComputeSelection,
|
|
467
|
+
) {
|
|
465
468
|
return changeDatabaseCompute(
|
|
466
469
|
{
|
|
467
470
|
project_id: input.projectId,
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
+
body: {
|
|
472
|
+
environment: input.environment,
|
|
473
|
+
...(input.memoryMiB === undefined
|
|
474
|
+
? { profile: input.profile }
|
|
475
|
+
: { memory_mib: input.memoryMiB }),
|
|
476
|
+
confirm: true,
|
|
477
|
+
},
|
|
471
478
|
"Idempotency-Key": input.idempotencyKey,
|
|
472
479
|
},
|
|
473
480
|
{ client: this.#client },
|
|
@@ -1,29 +1,64 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
+
import { startBridge } from "@ohmyhost/postgres-bridge";
|
|
2
3
|
|
|
3
4
|
import { PsqlUnavailableError } from "./cli.js";
|
|
4
5
|
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
* The password reaches psql only through its private environment, never through
|
|
8
|
-
* argv, the terminal title or any file; no authentication credential is involved.
|
|
9
|
-
*/
|
|
10
|
-
export const runLocalPsql = (input: {
|
|
6
|
+
/** One private loopback bridge lasts exactly as long as the customer's native psql session. */
|
|
7
|
+
export const runLocalPsql = async (input: {
|
|
11
8
|
readonly host: string;
|
|
12
9
|
readonly user: string;
|
|
13
10
|
readonly password: string;
|
|
14
11
|
readonly database: string;
|
|
12
|
+
readonly websocketUrl?: string;
|
|
15
13
|
readonly signal: AbortSignal;
|
|
16
|
-
}): Promise<number> =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
}): Promise<number> => {
|
|
15
|
+
input.signal.throwIfAborted();
|
|
16
|
+
if (input.websocketUrl !== undefined && input.websocketUrl !== `wss://${input.host}/`)
|
|
17
|
+
throw new Error("Invalid PGCF transport");
|
|
18
|
+
const bridge =
|
|
19
|
+
input.websocketUrl === undefined
|
|
20
|
+
? null
|
|
21
|
+
: await startBridge({
|
|
22
|
+
endpoint: input.websocketUrl,
|
|
23
|
+
database: input.database,
|
|
24
|
+
user: input.user,
|
|
25
|
+
port: 0,
|
|
26
|
+
});
|
|
27
|
+
try {
|
|
28
|
+
input.signal.throwIfAborted();
|
|
29
|
+
// A caller's libpq service/hostaddr settings must not redirect this temporary credential.
|
|
30
|
+
const environment = Object.fromEntries(
|
|
31
|
+
Object.entries(process.env).filter(([key]) => !/^PG[A-Z_]+$/iu.test(key)),
|
|
32
|
+
);
|
|
33
|
+
return await new Promise<number>((resolve, reject) => {
|
|
34
|
+
const child = spawn(
|
|
35
|
+
"psql",
|
|
36
|
+
["-h", bridge?.host ?? input.host, "-U", input.user, "-d", input.database],
|
|
37
|
+
{
|
|
38
|
+
stdio: "inherit",
|
|
39
|
+
signal: input.signal,
|
|
40
|
+
env: {
|
|
41
|
+
...environment,
|
|
42
|
+
PGPASSWORD: input.password,
|
|
43
|
+
PGSSLMODE: bridge ? "disable" : "require",
|
|
44
|
+
...(bridge
|
|
45
|
+
? {
|
|
46
|
+
PGPORT: String(bridge.port),
|
|
47
|
+
PGCHANNELBINDING: "disable",
|
|
48
|
+
PGGSSENCMODE: "disable",
|
|
49
|
+
}
|
|
50
|
+
: {}),
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
child.once("error", (error: NodeJS.ErrnoException) => {
|
|
55
|
+
reject(error.code === "ENOENT" ? new PsqlUnavailableError() : error);
|
|
56
|
+
});
|
|
57
|
+
child.once("close", (code, signalName) => {
|
|
58
|
+
resolve(code ?? (signalName === null ? 1 : 130));
|
|
59
|
+
});
|
|
22
60
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
resolve(code ?? (signalName === null ? 1 : 130));
|
|
28
|
-
});
|
|
29
|
-
});
|
|
61
|
+
} finally {
|
|
62
|
+
await bridge?.close();
|
|
63
|
+
}
|
|
64
|
+
};
|