From 576145f438369a23b2e33ff619b84c9982dc87b7 Mon Sep 17 00:00:00 2001 From: Eric Black Date: Thu, 23 Oct 2025 15:03:00 -0700 Subject: [PATCH 1/2] Update how types are exported --- src/index.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/index.ts b/src/index.ts index a259352..262529f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,10 @@ import {APIClient} from '@heroku-cli/command' +import type * as DataApiTypes from './types/pg/data-api.js' +import type * as TunnelTypes from './types/pg/tunnel.js' + import {AmbiguousError} from './errors/ambiguous.js' import {NotFound} from './errors/not-found.js' -import {AddOnWithRelatedData, ExtendedAddonAttachment, Link} from './types/pg/data-api.js' -import {ConnectionDetails, ConnectionDetailsWithAttachment, TunnelConfig} from './types/pg/tunnel.js' import {getPsqlConfigs, sshTunnel} from './utils/pg/bastion.js' import {getConfigVarNameFromAttachment} from './utils/pg/config-vars.js' import DatabaseResolver from './utils/pg/databases.js' @@ -17,15 +18,14 @@ import {styledObject} from './ux/styled-object.js' import {table} from './ux/table.js' import {wait} from './ux/wait.js' -export const types = { - pg: { - AddOnWithRelatedData: {} as AddOnWithRelatedData, - ConnectionDetails: {} as ConnectionDetails, - ConnectionDetailsWithAttachment: {} as ConnectionDetailsWithAttachment, - ExtendedAddonAttachment: {} as ExtendedAddonAttachment, - Link: {} as Link, - TunnelConfig: {} as TunnelConfig, - }, +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace pg { + export type AddOnWithRelatedData = DataApiTypes.AddOnWithRelatedData + export type ExtendedAddonAttachment = DataApiTypes.ExtendedAddonAttachment + export type Link = DataApiTypes.Link + export type ConnectionDetails = TunnelTypes.ConnectionDetails + export type ConnectionDetailsWithAttachment = TunnelTypes.ConnectionDetailsWithAttachment + export type TunnelConfig = TunnelTypes.TunnelConfig } export const utils = { @@ -42,7 +42,7 @@ export const utils = { appId: string, attachmentId?: string, namespace?: string, - ): Promise { + ): Promise { const databaseResolver = new DatabaseResolver(heroku) return databaseResolver.getDatabase(appId, attachmentId, namespace) }, @@ -50,7 +50,7 @@ export const utils = { host: getHost, psql: { exec( - connectionDetails: ConnectionDetailsWithAttachment, + connectionDetails: TunnelTypes.ConnectionDetailsWithAttachment, query: string, psqlCmdArgs: string[] = [], ): Promise { From 3a896a09ff93017b93b32d6870c8e46d1763ac1a Mon Sep 17 00:00:00 2001 From: Eric Black Date: Wed, 29 Oct 2025 09:58:28 -0700 Subject: [PATCH 2/2] update README to reflect export changes --- README.md | 60 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 3921b75..8c2c470 100644 --- a/README.md +++ b/README.md @@ -80,35 +80,67 @@ testHelpers.expectOutput(output, 'expected output'); ### Types +#### Error Classes + ```js -import { types } from '@heroku/heroku-cli-util'; +import { utils } from '@heroku/heroku-cli-util'; // Error types try { - throw new types.errors.AmbiguousError([{ name: 'foo' }, { name: 'bar' }], 'addon'); + throw new utils.errors.AmbiguousError([{ name: 'foo' }, { name: 'bar' }], 'addon'); } catch (err) { - if (err instanceof types.errors.AmbiguousError) { + if (err instanceof utils.errors.AmbiguousError) { console.error('Ambiguous:', err.message); } } try { - throw new types.errors.NotFound(); + throw new utils.errors.NotFound(); } catch (err) { - if (err instanceof types.errors.NotFound) { + if (err instanceof utils.errors.NotFound) { console.error('Not found:', err.message); } } +``` + +#### PostgreSQL Types (TypeScript) + +Import PG types using the `pg` namespace: + +```typescript +import type { pg } from '@heroku/heroku-cli-util'; + +// Use the types +const connection: pg.ConnectionDetails = { + database: 'mydb', + host: 'localhost', + password: 'pass', + pathname: '/mydb', + port: '5432', + url: 'postgres://...', + user: 'admin' +}; + +function processDatabase(details: pg.ConnectionDetailsWithAttachment) { + // ... +} + +const addon: pg.AddOnWithRelatedData = { /* ... */ }; +const link: pg.Link = { /* ... */ }; +const tunnel: pg.TunnelConfig = { /* ... */ }; +``` -// PG types (for TypeScript) -/** - * types.pg.ExtendedAddonAttachment - * types.pg.AddOnWithRelatedData - * types.pg.ConnectionDetails - * types.pg.ConnectionDetailsWithAttachment - * types.pg.Link - * types.pg.TunnelConfig - */ +Alternatively, you can import types directly: + +```typescript +import type { + ConnectionDetails, + ConnectionDetailsWithAttachment, + AddOnWithRelatedData, + ExtendedAddonAttachment, + Link, + TunnelConfig +} from '@heroku/heroku-cli-util'; ``` ### Database and Utility Helpers