-
Notifications
You must be signed in to change notification settings - Fork 475
feat(cli): port services #5468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,397
−48
Merged
feat(cli): port services #5468
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { Data } from "effect"; | ||
|
|
||
| export class LegacyServicesEnvNotSupportedError extends Data.TaggedError( | ||
| "LegacyServicesEnvNotSupportedError", | ||
| )<{ | ||
| readonly message: string; | ||
| }> {} |
112 changes: 108 additions & 4 deletions
112
apps/cli/src/legacy/commands/services/services.handler.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,112 @@ | ||
| import { Effect } from "effect"; | ||
| import { LegacyGoProxy } from "../../../shared/legacy/go-proxy.service.ts"; | ||
| import { Effect, Exit, FileSystem, Option, Path } from "effect"; | ||
| import { LegacyCliConfig } from "../../config/legacy-cli-config.service.ts"; | ||
| import { LegacyCredentials } from "../../auth/legacy-credentials.service.ts"; | ||
| import { LegacyLinkedProjectCache } from "../../telemetry/legacy-linked-project-cache.service.ts"; | ||
| import { LegacyTelemetryState } from "../../telemetry/legacy-telemetry-state.service.ts"; | ||
| import { LegacyOutputFlag } from "../../../shared/legacy/global-flags.ts"; | ||
| import { Output } from "../../../shared/output/output.service.ts"; | ||
| import { encodeGoJson, encodeToml, encodeYaml } from "../../shared/legacy-go-output.encoders.ts"; | ||
| import { | ||
| encodeLegacyTomlRows, | ||
| fetchLinkedServiceVersions, | ||
| formatServicesWarning, | ||
| listLocalServiceVersions, | ||
| mergeRemoteServiceVersions, | ||
| renderServicesTable, | ||
| renderServicesWarning, | ||
| } from "../../../shared/services/services.shared.ts"; | ||
| import type { LegacyServicesFlags } from "./services.command.ts"; | ||
| import { LegacyServicesEnvNotSupportedError } from "./services.errors.ts"; | ||
|
|
||
| export const legacyServices = Effect.fn("legacy.services")(function* (_flags: LegacyServicesFlags) { | ||
| const proxy = yield* LegacyGoProxy; | ||
| yield* proxy.exec(["services"]); | ||
| const output = yield* Output; | ||
| const legacyOutput = yield* LegacyOutputFlag; | ||
| const cliConfig = yield* LegacyCliConfig; | ||
| const credentials = yield* LegacyCredentials; | ||
| const linkedProjectCache = yield* LegacyLinkedProjectCache; | ||
| const telemetryState = yield* LegacyTelemetryState; | ||
| const fs = yield* FileSystem.FileSystem; | ||
| const path = yield* Path.Path; | ||
|
|
||
| const projectRefPath = path.join(cliConfig.workdir, "supabase", ".temp", "project-ref"); | ||
| const linkedProjectRef = yield* Effect.gen(function* () { | ||
| if (Option.isSome(cliConfig.projectId)) { | ||
| return cliConfig.projectId; | ||
| } | ||
|
|
||
| const exists = yield* fs.exists(projectRefPath).pipe(Effect.orElseSucceed(() => false)); | ||
| if (!exists) { | ||
| return Option.none<string>(); | ||
| } | ||
|
|
||
| const content = yield* fs.readFileString(projectRefPath).pipe(Effect.orElseSucceed(() => "")); | ||
| const trimmed = content.trim(); | ||
| return trimmed.length === 0 ? Option.none<string>() : Option.some(trimmed); | ||
| }); | ||
|
|
||
| // Mirror Go's PersistentPostRun (`apps/cli-go/cmd/root.go:176`): when a project | ||
| // ref is resolved, refresh the linked-project cache on success and failure so | ||
| // PostHog org/project groups stay attached. Persist the telemetry state too. | ||
| const cacheLinkedProject = Option.match(linkedProjectRef, { | ||
| onNone: () => Effect.void, | ||
| onSome: (ref) => linkedProjectCache.cache(ref), | ||
| }); | ||
|
|
||
| yield* Effect.gen(function* () { | ||
| const accessTokenExit = yield* credentials.getAccessToken.pipe(Effect.exit); | ||
| const accessToken = Exit.isSuccess(accessTokenExit) ? accessTokenExit.value : Option.none(); | ||
|
|
||
| let rows = listLocalServiceVersions(); | ||
| if (Option.isSome(linkedProjectRef) && Option.isSome(accessToken)) { | ||
| const remote = yield* fetchLinkedServiceVersions({ | ||
| apiUrl: cliConfig.apiUrl, | ||
| projectHost: cliConfig.projectHost, | ||
| projectRef: linkedProjectRef.value, | ||
| accessToken: accessToken.value, | ||
| userAgent: cliConfig.userAgent, | ||
| }); | ||
| rows = mergeRemoteServiceVersions(remote); | ||
| } | ||
|
|
||
| const warning = renderServicesWarning(rows); | ||
| if (warning !== undefined) { | ||
| yield* output.raw(formatServicesWarning(warning, output.format === "text"), "stderr"); | ||
| } | ||
|
|
||
| const goOutput = Option.getOrUndefined(legacyOutput); | ||
|
|
||
| if (goOutput === "env") { | ||
| return yield* Effect.fail( | ||
| new LegacyServicesEnvNotSupportedError({ | ||
| message: "--output env flag is not supported", | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| if (goOutput === "json") { | ||
| yield* output.raw(encodeGoJson(rows)); | ||
| return; | ||
| } | ||
|
|
||
| if (goOutput === "yaml") { | ||
| yield* output.raw(encodeYaml(rows)); | ||
| return; | ||
| } | ||
|
|
||
| if (goOutput === "toml") { | ||
| yield* output.raw(encodeToml(encodeLegacyTomlRows(rows))); | ||
| return; | ||
| } | ||
|
|
||
| // goOutput is undefined or "pretty" — defer to the TS --output-format flag for | ||
| // machine output, otherwise render the Go `--output pretty` table. Guarding the | ||
| // table behind this (rather than treating "pretty" as force-table) keeps | ||
| // `--output pretty --output-format json` emitting JSON, per CLI-1546. | ||
| if (output.format === "json" || output.format === "stream-json") { | ||
| yield* output.success("", { services: rows }); | ||
| return; | ||
| } | ||
|
|
||
| yield* output.raw(renderServicesTable(rows)); | ||
| }).pipe(Effect.ensuring(cacheLinkedProject), Effect.ensuring(telemetryState.flush)); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion(non-blocking): use LegacyProjectRefResolver.resolveOptional here instead of re-reading .temp/project-ref inline. It already does this projectId/ref-file chain via legacyTempPaths() and mirrors Go's flags.LoadProjectRef.