@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 +24 -16
- package/lib/index.d.ts +21 -10
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +277 -158
- package/lib/index.js.map +1 -1
- package/package.json +2 -3
- package/src/Deployment.ts +9 -2
- package/src/ManagementApi.ts +85 -3
- package/src/Project.ts +125 -88
- package/src/Push.ts +74 -46
- package/src/State.ts +281 -159
- package/src/index.ts +1 -1
- package/src/{component/_generated/api.ts → store/convex/_generated/api.d.ts} +9 -8
- package/src/store/convex/_generated/api.js +23 -0
- package/src/{component/_generated/server.ts → store/convex/_generated/server.d.ts} +18 -25
- package/src/store/convex/_generated/server.js +101 -0
- package/src/{component → store/convex}/state.ts +96 -46
- package/src/store/convex/version.ts +6 -0
- package/src/store/package.json +8 -0
- package/src/component/_generated/component.ts +0 -92
- package/src/component/convex.config.ts +0 -5
- /package/src/{component/_generated/dataModel.ts → store/convex/_generated/dataModel.d.ts} +0 -0
- /package/src/{component → store/convex}/schema.ts +0 -0
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
|
|
96
|
-
project, so
|
|
97
|
-
[docs/design/convex-state.md](docs/design/convex-state.md) records the
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
/**
|
|
81
|
-
|
|
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
|
-
/**
|
|
345
|
-
export declare const
|
|
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
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
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: (
|
|
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
|
package/lib/index.d.ts.map
CHANGED
|
@@ -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":"
|
|
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,Q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