@samebase/alchemy-convex 0.5.0 → 0.6.1

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/README.md CHANGED
@@ -92,24 +92,32 @@ values explicitly: `Convex.providers(Convex.fromValues({ accessToken, deployKey
92
92
 
93
93
  ## State in Convex
94
94
 
95
- `state: Convex.state()` keeps the Alchemy state of every stage in the production deployment of the
96
- project, so the stack needs no Cloudflare token.
97
- [docs/design/convex-state.md](docs/design/convex-state.md) records the decisions.
95
+ `state: Convex.state({ team })` keeps the Alchemy state of every stack and stage of a Convex team in
96
+ one project of that team, `alchemy-state`, so a repository holds one secret and a stack can create
97
+ and destroy its own project. [docs/design/convex-state.md](docs/design/convex-state.md) records the
98
+ decisions and the measurements.
98
99
 
99
- 1. Mount the state component in `convex/convex.config.ts` with its default name:
100
-
101
- ```ts
102
- import alchemyState from "@samebase/alchemy-convex/convex.config";
103
- app.use(alchemyState);
104
- ```
105
-
106
- 2. Set `CONVEX_STATE_DEPLOY_KEY` in every run, a preview run too, to a production deploy key. A key
107
- with only the actions `deployment:data:view` and `deployment:data:write` is sufficient.
100
+ ```ts
101
+ export default Alchemy.Stack(
102
+ process.env["GITHUB_REPOSITORY"] ?? "my-org/my-app", // the stack name: the repository
103
+ { providers: Convex.providers(), state: Convex.state({ team: "my-team" }) },
104
+ Effect.gen(function* () {
105
+ /* ... */
106
+ }),
107
+ );
108
+ ```
108
109
 
109
- The first run starts with empty state, keeps it in memory until `Convex.Deployment` has pushed the
110
- component, and then writes it. A run whose push does not mount the component fails at the end.
111
- Rows are in the `alchemyState` component tables `resources` and `outputs` in the dashboard. The
112
- store has no lock: run one deploy of a stage at a time, such as with a CI concurrency group.
110
+ Every run needs the team token in `CONVEX_ACCESS_TOKEN`, or the Convex CLI login on a laptop. A
111
+ team access token names its team, so `Convex.state()` needs no `team` with one; a `team` slug that
112
+ is set must be the slug of that team, checked against its projects, and a token of another team
113
+ fails the run. The Convex CLI login needs the slug or the id. The first run of a team creates
114
+ the project `alchemy-state` and pushes the store functions to its
115
+ production deployment with the Convex CLI of the app; a later version of this package pushes a
116
+ newer store when it finds an older one, and never an older one over a newer one. Each run makes a
117
+ deploy key of that deployment that can only run the store's internal functions, and deletes it at
118
+ the end. Rows are in the tables `resources` and `outputs` in the dashboard, under the stack name.
119
+ The store has no lock: run one deploy of a stage at a time, such as with a CI concurrency group.
120
+ The names of the store functions are a wire contract: never renamed or removed.
113
121
 
114
122
  ## Resources
115
123
 
package/lib/index.d.ts CHANGED
@@ -5,8 +5,9 @@ import * as Redacted from "effect/Redacted";
5
5
  import * as Schema from "effect/Schema";
6
6
  import { Resource } from "alchemy";
7
7
  import * as Provider from "alchemy/Provider";
8
- import "effect/process/ChildProcessSpawner";
8
+ import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
9
9
  import { createDeploymentClient, createManagementClient } from "@convex-dev/platform";
10
+ import "effect/Scope";
10
11
  import { State, StateStoreError } from "alchemy/State";
11
12
  import { components } from "@convex-dev/platform/managementApi";
12
13
  //#region src/Credentials.d.ts
@@ -77,8 +78,14 @@ interface ManagementApiService {
77
78
  readonly requestVoid: (operation: string, run: (client: ManagementClient) => Promise<FetchResult<unknown>>) => Effect.Effect<void, ConvexApiError>;
78
79
  /** Run one deployment-scoped call authenticated with a deploy key. */
79
80
  readonly deploymentRequest: <T>(operation: string, deploymentUrlOrName: string, deployKey: Redacted.Redacted<string>, run: (client: DeploymentClient) => Promise<FetchResult<T>>) => Effect.Effect<T, ConvexApiError>;
80
- /** Team id for a slug or numeric id. */
81
- readonly resolveTeamId: (team: string | number) => Effect.Effect<number, ConvexApiError>;
81
+ /**
82
+ * Team id for a numeric id, a slug, or nothing. A team access token names
83
+ * its team (`GET /token_details`); a slug is then checked against the
84
+ * `teamSlug` of the team's projects, so a token of another team fails. The
85
+ * Convex CLI login and a personal token answer 403 there, so a slug goes to
86
+ * the dashboard's team list, and nothing is an error.
87
+ */
88
+ readonly resolveTeamId: (team: string | number | undefined) => Effect.Effect<number, ConvexApiError>;
82
89
  /**
83
90
  * True when a deploy key that Convex returned carries the token of the
84
91
  * Management API credential itself. With an OAuth token, create_deploy_key
@@ -341,15 +348,19 @@ export declare class ProjectNotFound extends ProjectNotFound_base {
341
348
  }
342
349
  //#endregion
343
350
  //#region src/State.d.ts
344
- /** Environment variable with the deploy key of the deployment that holds the state. */
345
- export declare const STATE_DEPLOY_KEY_ENV = "CONVEX_STATE_DEPLOY_KEY";
351
+ /** The name of the state project in each team. */
352
+ export declare const STORE_PROJECT_NAME = "alchemy-state";
346
353
  /**
347
- * Alchemy state in the alchemyState component of the deployment that the
348
- * deploy key in CONVEX_STATE_DEPLOY_KEY names: the production deployment of
349
- * the project. The key needs the actions `deployment:data:view` and
350
- * `deployment:data:write`.
354
+ * Alchemy state in the `alchemy-state` project of `team`, with the team token
355
+ * in CONVEX_ACCESS_TOKEN or the Convex CLI login. A team access token names
356
+ * its team, so `team` is optional with one; the Convex CLI login needs the
357
+ * slug or the id. The first use of the run finds or creates the project and
358
+ * pushes the store when it is missing or older. `alchemy plan` on another
359
+ * stack never touches Convex.
351
360
  */
352
- export declare const state: () => Layer.Layer<State>;
361
+ export declare const state: (options?: {
362
+ readonly team?: string | number;
363
+ }) => Layer.Layer<State, never, ChildProcessSpawner.ChildProcessSpawner>;
353
364
  //#endregion
354
365
  export type { DeploymentAttributes, DeploymentProps, DeploymentRegion, EnvValue, ProjectAttributes, ProjectProps, Source };
355
366
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/Credentials.ts","../src/ManagementApi.ts","../src/Providers.ts","../src/Push.ts","../src/Deployment.ts","../src/Project.ts","../src/State.ts"],"mappings":";;;;;;;;;;;;UA6BiB;;WAEN,aAAa,SAAS;;WAEtB;;UAGM;;WAEN,aAAa,OAAO,OAAO;;WAE3B,gBAAgB,OAAO;;WAEvB,WAAW,OAAO,OAAO,SAAS;;;qBAG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A;;WAEA;;WAEA;;UAGM,6BAA6B;;WAEnC;;WAEA;;YAGC,aAAa,8BAEvB,iBACA,6BAEA;qBAEW,8BAAU,cAAA;;;;;;;;;qBAKV,iCAAiC;MAU/B;;;;;;qBAMF,qCAAqC;MAInC;;;;;;;;;qBAMF,4BAA4B;MAS1B;;;;;KChJH,mBAAmB;KAEnB;;WAGG;;WAEA;;WAEA,mBAAmB;;WAEnB;;;WAIA;;WAEA;;UAGE;WACN;WACA;WACA;WACA;WACA;WACA;;YAGC,UAAU,2BAA2B,cAAc,0BAA0B;qBAC5E,2BAAO,cAAA;;;;;;;qBAGP,0BAA0B;MAIxB;;;;;;;;;;;;qBASF,gCAAgC;MAS9B;;;;;;;;qBAOF,yBAAyB;MAKvB;;;;;;qBAMF,+BAA+B;MAI7B;;;;;;;qBAMF,wBAAwB;MAItB;;;;;qBC7EF;;;;;;;qBAgQA,aAAY,MAAM,MAAM"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/Credentials.ts","../src/ManagementApi.ts","../src/Providers.ts","../src/Push.ts","../src/Deployment.ts","../src/Project.ts","../src/State.ts"],"mappings":";;;;;;;;;;;;;UA6BiB;;WAEN,aAAa,SAAS;;WAEtB;;UAGM;;WAEN,aAAa,OAAO,OAAO;;WAE3B,gBAAgB,OAAO;;WAEvB,WAAW,OAAO,OAAO,SAAS;;;qBAGhC,oBAAoB;;qBAKpB;;qBAGA;;;;qBAOA,yBAAyB;;;;;;;;;qBAiCzB,kBAAiB,MAAM,MAAM;;qBA0B7B,aAAc;WAChB,cAAc,SAAS;WACvB,YAAY,SAAS;MAC5B,MAAM,MAAM;;;KC3GJ,mBAAmB,kBAAkB;KACrC,mBAAmB,kBAAkB;;UAGhC,YAAY;WAClB,OAAO;WACP;WACA,UAAU;;;;;;;;;;;;;qBAQR,uBAAuB;UAuBnB;;WAEN,UAAU,GACjB,mBACA,MAAM,QAAQ,qBAAqB,QAAQ,YAAY,QACpD,OAAO,OAAO,GAAG;;WAEb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