(
apiKey: string | undefined,
databaseId: string | undefined,
baseDir: string,
)
| 234 | } |
| 235 | |
| 236 | private async executeLinkFlow( |
| 237 | apiKey: string | undefined, |
| 238 | databaseId: string | undefined, |
| 239 | baseDir: string, |
| 240 | ): Promise<LinkResult> { |
| 241 | const client = await resolveApiClient(apiKey) |
| 242 | |
| 243 | let workspaceId: string | null = null |
| 244 | let projectId: string | null = null |
| 245 | |
| 246 | if (!databaseId) { |
| 247 | const resolved = await resolveDatabase(client) |
| 248 | databaseId = resolved.databaseId |
| 249 | workspaceId = resolved.workspaceId |
| 250 | projectId = resolved.projectId |
| 251 | } else { |
| 252 | workspaceId = apiKey ? extractWorkspaceIdFromToken(apiKey) : null |
| 253 | projectId = await resolveProjectForDatabase(client, databaseId) |
| 254 | } |
| 255 | |
| 256 | const connection = await createDevConnection(client, databaseId) |
| 257 | const localFilesResult = writeLocalFiles(baseDir, connection) |
| 258 | const hasModels = getModelNames(baseDir).length > 0 |
| 259 | const environmentId = databaseId.replace(/^db_/, '') |
| 260 | |
| 261 | return { |
| 262 | workspaceId: workspaceId ?? 'unknown', |
| 263 | projectId: projectId ?? 'unknown', |
| 264 | environmentId, |
| 265 | databaseId, |
| 266 | connectionString: connection.connectionString, |
| 267 | localFilesResult, |
| 268 | hasModels, |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | private static formatError(err: unknown): HelpError { |
| 273 | if (err instanceof LinkApiError) { |
no test coverage detected