(
apiKey: string | undefined,
databaseId: string | undefined,
baseDir: string,
opts?: { force?: boolean },
)
| 212 | } |
| 213 | |
| 214 | async link( |
| 215 | apiKey: string | undefined, |
| 216 | databaseId: string | undefined, |
| 217 | baseDir: string, |
| 218 | opts?: { force?: boolean }, |
| 219 | ): Promise<LinkResult> { |
| 220 | if (!opts?.force && isAlreadyLinked(baseDir)) { |
| 221 | throw new LinkApiError('This project is already linked to Prisma Postgres. Use force to re-link.') |
| 222 | } |
| 223 | |
| 224 | try { |
| 225 | return await this.executeLinkFlow(apiKey, databaseId, baseDir) |
| 226 | } catch (err) { |
| 227 | if (!apiKey && isExpiredSessionError(err)) { |
| 228 | console.log(`Session expired. Re-authenticating via browser...`) |
| 229 | await login({ utmMedium: 'command-postgres-link' }) |
| 230 | return await this.executeLinkFlow(apiKey, databaseId, baseDir) |
| 231 | } |
| 232 | throw err |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | private async executeLinkFlow( |
| 237 | apiKey: string | undefined, |
no test coverage detected