@samebase/alchemy-convex 0.26.0 → 0.27.0

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.
package/src/cli.ts CHANGED
@@ -2,18 +2,14 @@
2
2
  // The commands of the package:
3
3
  //
4
4
  // alchemy-convex hub-client --team <team> --app <app> --callback-path <path> [--env-prefix HUB]
5
- // alchemy-convex hub-client --shared --stack <owner/name> --app <app> --callback-path <path>
6
- // [--env-prefix HUB] [--team <team>]
7
5
  // alchemy-convex stack-comment [--team <team>]
8
6
  //
9
7
  // hub-client runs in the directory of a Convex app at each dev start, and renews the client of the
10
8
  // identity hub of the team that the development deployment of that directory has, or gives it a new
11
- // one: see registerDevelopmentClient. With --shared, the client is on the central identity hub, and
12
- // the initial access token of the stack's production client is the proof: see
13
- // registerSharedDevelopmentClient. It never stops a dev start. stack-comment runs as a step of a pull
14
- // request workflow after the deploys, and keeps one comment with the stacks of the repository: see
15
- // src/StackComment.ts. It needs GITHUB_TOKEN and, with a team access token, no --team. All use
16
- // CONVEX_ACCESS_TOKEN or the Convex CLI login.
9
+ // one: see registerDevelopmentClient. stack-comment runs as a step of a pull request workflow after
10
+ // the deploys, and keeps one comment with the stacks of the repository: see src/StackComment.ts. It
11
+ // needs GITHUB_TOKEN and, with a team access token, no --team. Both use CONVEX_ACCESS_TOKEN or the
12
+ // Convex CLI login.
17
13
  import { execFileSync } from "node:child_process";
18
14
  import { parseArgs } from "node:util";
19
15
  import * as NodeServices from "@effect/platform-node/NodeServices";
@@ -23,7 +19,6 @@ import { fromConfig } from "./Credentials.ts";
23
19
  import { registerDevelopmentClient } from "./HubClient.ts";
24
20
  import { ManagementApiLive } from "./ManagementApi.ts";
25
21
  import { installedCli } from "./Push.ts";
26
- import { registerSharedDevelopmentClient } from "./SharedHubClient.ts";
27
22
  import { updateStackComment } from "./StackComment.ts";
28
23
  import { state } from "./State.ts";
29
24
 
@@ -34,60 +29,31 @@ const { positionals, values } = parseArgs({
34
29
  app: { type: "string" },
35
30
  "callback-path": { type: "string" },
36
31
  "env-prefix": { type: "string" },
37
- shared: { type: "boolean" },
38
- stack: { type: "string" },
39
32
  },
40
33
  });
41
- const { team, app, "callback-path": callbackPath, "env-prefix": envPrefix, shared, stack } = values;
34
+ const { team, app, "callback-path": callbackPath, "env-prefix": envPrefix } = values;
42
35
  const USAGE = `Usage:
43
36
  alchemy-convex hub-client --team <team> --app <app> --callback-path <path> [--env-prefix HUB]
44
- alchemy-convex hub-client --shared --stack <owner/name> --app <app> --callback-path <path> [--env-prefix HUB] [--team <team>]
45
37
  alchemy-convex stack-comment [--team <team>]`;
46
38
 
47
- /** The installed Convex CLI on the deployment of this directory. Secrets go on standard input. */
48
- const convexOfThisDirectory = installedCli(process.cwd()).pipe(
49
- Effect.map(
50
- ([command, ...prefix]) =>
51
- (args: readonly string[], input?: string) =>
39
+ const hubClient = (hub: { team: string; app: string; callbackPath: string; envPrefix?: string }) =>
40
+ Effect.gen(function* () {
41
+ const [command, ...prefix] = yield* installedCli(process.cwd());
42
+ const callbackUrl = yield* registerDevelopmentClient({
43
+ ...hub,
44
+ convex: (args, input) =>
52
45
  execFileSync(command, [...prefix, ...args], {
53
46
  encoding: "utf8",
54
47
  input,
55
48
  stdio: ["pipe", "pipe", "inherit"],
56
49
  }).trim(),
57
- ),
58
- );
59
-
60
- const managementApi = ManagementApiLive().pipe(Layer.provide(fromConfig()));
61
-
62
- const hubClient = (hub: { team: string; app: string; callbackPath: string; envPrefix?: string }) =>
63
- Effect.gen(function* () {
64
- const callbackUrl = yield* registerDevelopmentClient({
65
- ...hub,
66
- convex: yield* convexOfThisDirectory,
67
50
  });
68
51
  console.log(
69
52
  callbackUrl === undefined
70
53
  ? "Hub client renewed."
71
54
  : `Hub client registered for ${callbackUrl}.`,
72
55
  );
73
- }).pipe(Effect.provide(managementApi));
74
-
75
- const sharedHubClient = (hub: {
76
- stack: string;
77
- app: string;
78
- callbackPath: string;
79
- envPrefix?: string;
80
- team?: string;
81
- }) =>
82
- convexOfThisDirectory.pipe(
83
- Effect.flatMap((convex) =>
84
- registerSharedDevelopmentClient({ ...hub, cwd: process.cwd(), convex }),
85
- ),
86
- // Without the Convex CLI, the dev start goes on too.
87
- Effect.catchTag("ConvexCliNotFound", (error) => Effect.succeed(error.message)),
88
- Effect.tap((line) => Effect.sync(() => console.log(line))),
89
- Effect.provide(managementApi),
90
- );
56
+ }).pipe(Effect.provide(ManagementApiLive().pipe(Layer.provide(fromConfig()))));
91
57
 
92
58
  const stackComment = (options: { team?: string }) =>
93
59
  updateStackComment.pipe(
@@ -95,26 +61,16 @@ const stackComment = (options: { team?: string }) =>
95
61
  Effect.provide(state(options).pipe(Layer.provide(NodeServices.layer))),
96
62
  );
97
63
 
98
- const prefix = envPrefix === undefined ? {} : { envPrefix };
99
64
  const subcommand = positionals.join(" ");
100
65
  const program: Effect.Effect<unknown, unknown> | undefined =
101
66
  subcommand === "stack-comment"
102
67
  ? stackComment(team === undefined ? {} : { team })
103
- : subcommand !== "hub-client" || app === undefined || callbackPath === undefined
104
- ? undefined
105
- : shared === true
106
- ? stack === undefined
107
- ? undefined
108
- : sharedHubClient({
109
- stack,
110
- app,
111
- callbackPath,
112
- ...prefix,
113
- ...(team === undefined ? {} : { team }),
114
- })
115
- : team === undefined
116
- ? undefined
117
- : hubClient({ team, app, callbackPath, ...prefix });
68
+ : subcommand === "hub-client" &&
69
+ team !== undefined &&
70
+ app !== undefined &&
71
+ callbackPath !== undefined
72
+ ? hubClient({ team, app, callbackPath, ...(envPrefix === undefined ? {} : { envPrefix }) })
73
+ : undefined;
118
74
  if (program === undefined) {
119
75
  console.error(USAGE);
120
76
  process.exit(1);