@amerged/ohmyhost-cli 0.1.41 → 0.1.43

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.
@@ -112,21 +112,12 @@ export interface ProjectDatabaseAccessFields {
112
112
  | "data_change"
113
113
  | null;
114
114
  }
115
- export type ProjectDatabaseAccess = ProjectDatabaseAccessFields &
116
- (
117
- | {
118
- readonly database: "neondb";
119
- readonly provider?: never;
120
- readonly transport?: never;
121
- readonly websocket_url?: never;
122
- }
123
- | {
124
- readonly provider: "pgcf";
125
- readonly transport: "wss";
126
- readonly websocket_url: string;
127
- readonly database: string;
128
- }
129
- );
115
+ export type ProjectDatabaseAccess = ProjectDatabaseAccessFields & {
116
+ readonly provider: "pgcf";
117
+ readonly transport: "wss";
118
+ readonly websocket_url: string;
119
+ readonly database: string;
120
+ };
130
121
  export type ProjectDatabaseAccessCredential = ProjectDatabaseAccess & {
131
122
  readonly connection_uri: string;
132
123
  readonly psql_command: string;
@@ -140,6 +131,9 @@ const ACCESS_KEYS = [
140
131
  "mode",
141
132
  "role_name",
142
133
  "host",
134
+ "provider",
135
+ "transport",
136
+ "websocket_url",
143
137
  "database",
144
138
  "label",
145
139
  "state",
@@ -177,26 +171,23 @@ export function parseProjectDatabaseAccessRequest(value: unknown): ProjectDataba
177
171
  export function assertProjectDatabaseAccess(
178
172
  value: unknown,
179
173
  ): asserts value is ProjectDatabaseAccess {
180
- if (!record(value) || !exact(value, accessKeys(value)))
181
- throw new TypeError("Invalid database access");
174
+ if (!record(value) || !exact(value, ACCESS_KEYS)) throw new TypeError("Invalid database access");
182
175
  assertAccessFields(value);
183
176
  }
184
177
  export function assertProjectDatabaseAccessCredential(
185
178
  value: unknown,
186
179
  ): asserts value is ProjectDatabaseAccessCredential {
187
- if (!record(value) || !exact(value, [...accessKeys(value), "connection_uri", "psql_command"]))
180
+ if (!record(value) || !exact(value, [...ACCESS_KEYS, "connection_uri", "psql_command"]))
188
181
  throw new TypeError("Invalid database access credential");
189
182
  assertAccessFields(value);
190
183
  const uri = value["connection_uri"];
191
184
  if (
192
185
  typeof uri !== "string" ||
193
- (value["provider"] === "pgcf"
194
- ? typeof value["psql_command"] !== "string" ||
195
- !new RegExp(
196
- `^ohmyhost database psql --project [0-7][0-9A-HJKMNP-TV-Z]{25} --environment ${value["environment"]} --mode ${value["mode"]}$`,
197
- "u",
198
- ).test(value["psql_command"])
199
- : value["psql_command"] !== `psql '${uri}'`)
186
+ typeof value["psql_command"] !== "string" ||
187
+ !new RegExp(
188
+ `^ohmyhost database psql --project [0-7][0-9A-HJKMNP-TV-Z]{25} --environment ${value["environment"]} --mode ${value["mode"]}$`,
189
+ "u",
190
+ ).test(value["psql_command"])
200
191
  )
201
192
  throw new TypeError("Invalid database access credential");
202
193
  let parsed: URL;
@@ -206,20 +197,14 @@ export function assertProjectDatabaseAccessCredential(
206
197
  throw new TypeError("Invalid database access credential");
207
198
  }
208
199
  if (
209
- (value["provider"] === "pgcf"
210
- ? !["postgres:", "postgresql:"].includes(parsed.protocol)
211
- : parsed.protocol !== "postgresql:") ||
200
+ !["postgres:", "postgresql:"].includes(parsed.protocol) ||
212
201
  decodeURIComponent(parsed.username) !== value["role_name"] ||
213
202
  parsed.password === "" ||
214
203
  parsed.hostname !== value["host"] ||
215
- (value["provider"] === "pgcf"
216
- ? parsed.port !== "" && parsed.port !== "5432"
217
- : parsed.host !== value["host"]) ||
204
+ (parsed.port !== "" && parsed.port !== "5432") ||
218
205
  decodeURIComponent(parsed.pathname.slice(1)) !== value["database"] ||
219
206
  parsed.hash !== "" ||
220
- (value["provider"] === "pgcf"
221
- ? !["", "?sslmode=require", "?sslmode=verify-full"].includes(parsed.search)
222
- : parsed.search !== "?sslmode=require")
207
+ !["", "?sslmode=require", "?sslmode=verify-full"].includes(parsed.search)
223
208
  )
224
209
  throw new TypeError("Invalid database access credential");
225
210
  }
@@ -235,11 +220,6 @@ export function assertProjectDatabaseAccessPage(
235
220
  throw new TypeError("Invalid database access page");
236
221
  for (const item of value["items"]) assertProjectDatabaseAccess(item);
237
222
  }
238
- function accessKeys(value: Record<string, unknown>): readonly string[] {
239
- return value["provider"] === "pgcf"
240
- ? [...ACCESS_KEYS, "provider", "transport", "websocket_url"]
241
- : ACCESS_KEYS;
242
- }
243
223
  function assertAccessFields(value: Record<string, unknown>): void {
244
224
  const revoked = value["revoked_at"],
245
225
  reason = value["revocation_reason"];
@@ -252,12 +232,11 @@ function assertAccessFields(value: Record<string, unknown>): void {
252
232
  !ACCESS_ROLE_PATTERN.test(value["role_name"]) ||
253
233
  typeof value["host"] !== "string" ||
254
234
  !/^[a-z0-9]([a-z0-9.-]{0,251}[a-z0-9])?$/u.test(value["host"]) ||
255
- (value["provider"] === "pgcf"
256
- ? typeof value["database"] !== "string" ||
257
- !/^[a-z][a-z0-9]{19}$/u.test(value["database"]) ||
258
- value["transport"] !== "wss" ||
259
- value["websocket_url"] !== `wss://${value["host"]}/`
260
- : value["database"] !== "neondb") ||
235
+ value["provider"] !== "pgcf" ||
236
+ value["transport"] !== "wss" ||
237
+ value["websocket_url"] !== `wss://${value["host"]}/` ||
238
+ typeof value["database"] !== "string" ||
239
+ !/^[a-z][a-z0-9]{19}$/u.test(value["database"]) ||
261
240
  (value["label"] !== null && accessLabel(value["label"]) !== value["label"]) ||
262
241
  !["active", "expired", "revoked"].includes(String(value["state"])) ||
263
242
  !timestamp(value["issued_at"]) ||