@gaganref/confect-alchemy 10.6.0-fork.29 → 10.6.0-fork.30
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/dist/Backend.d.ts +64 -5
- package/dist/Backend.d.ts.map +1 -1
- package/dist/Backend.js +187 -3
- package/dist/Backend.js.map +1 -1
- package/dist/Code.d.ts +14 -2
- package/dist/Code.d.ts.map +1 -1
- package/dist/Code.js +2 -2
- package/dist/Code.js.map +1 -1
- package/dist/Confect.d.ts +1 -1
- package/dist/Confect.d.ts.map +1 -1
- package/dist/Confect.js +8 -3
- package/dist/Confect.js.map +1 -1
- package/dist/Convex.d.ts +1 -1
- package/dist/Convex.d.ts.map +1 -1
- package/dist/Convex.js +4 -1
- package/dist/Convex.js.map +1 -1
- package/dist/ConvexClient.js +4 -4
- package/dist/CustomDomain.js +3 -3
- package/dist/DeployKey.js +3 -3
- package/dist/Deployment.js +2 -2
- package/dist/EnvironmentVariables.d.ts.map +1 -1
- package/dist/EnvironmentVariables.js +20 -13
- package/dist/EnvironmentVariables.js.map +1 -1
- package/dist/LogStream.js +5 -5
- package/dist/Project.js +2 -2
- package/dist/UsageLimit.js +2 -2
- package/dist/internal/CodeDeployment.d.ts +28 -1
- package/dist/internal/CodeDeployment.d.ts.map +1 -1
- package/dist/internal/CodeDeployment.js +85 -2
- package/dist/internal/CodeDeployment.js.map +1 -1
- package/dist/internal/CommandRunner.js +4 -4
- package/dist/internal/FileLock.js +1 -1
- package/dist/internal/FunctionsDirectory.d.ts +12 -0
- package/dist/internal/FunctionsDirectory.d.ts.map +1 -0
- package/dist/internal/FunctionsDirectory.js +22 -0
- package/dist/internal/FunctionsDirectory.js.map +1 -0
- package/dist/internal/LocalBackend.d.ts +7 -0
- package/dist/internal/LocalBackend.d.ts.map +1 -1
- package/dist/internal/LocalBackend.js +10 -3
- package/dist/internal/LocalBackend.js.map +1 -1
- package/dist/internal/MountInit.d.ts.map +1 -1
- package/dist/internal/MountInit.js +4 -6
- package/dist/internal/MountInit.js.map +1 -1
- package/dist/internal/PushLock.js +1 -1
- package/dist/internal/ResourceIdentity.js +1 -1
- package/dist/internal/Zip.js +1 -1
- package/package.json +3 -3
- package/src/Backend.ts +422 -12
- package/src/Code.ts +13 -0
- package/src/Confect.ts +7 -1
- package/src/Convex.ts +7 -1
- package/src/EnvironmentVariables.ts +27 -12
- package/src/internal/CodeDeployment.ts +115 -0
- package/src/internal/FunctionsDirectory.ts +27 -0
- package/src/internal/LocalBackend.ts +7 -0
- package/src/internal/MountInit.ts +3 -13
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
import * as HealthModule from "@confect/core/HealthModule";
|
|
1
2
|
import type { ProviderMode } from "alchemy/ProviderMode";
|
|
2
3
|
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as FileSystem from "effect/FileSystem";
|
|
5
|
+
import * as Option from "effect/Option";
|
|
3
6
|
import * as Path from "effect/Path";
|
|
4
7
|
import * as Redacted from "effect/Redacted";
|
|
5
8
|
import * as Result from "effect/Result";
|
|
6
9
|
import * as Schema from "effect/Schema";
|
|
7
10
|
import type { CodeProps } from "../Code.js";
|
|
11
|
+
import { ConvexClient } from "../ConvexClient.js";
|
|
8
12
|
import { CommandRunner, type PushTarget } from "./CommandRunner.js";
|
|
9
13
|
import * as Loopback from "./Loopback.js";
|
|
14
|
+
import { functionsDirectory } from "./FunctionsDirectory.js";
|
|
10
15
|
import * as MountInit from "./MountInit.js";
|
|
11
16
|
import { PushLock } from "./PushLock.js";
|
|
12
17
|
|
|
@@ -17,6 +22,93 @@ export class InvalidDeploymentTarget extends Schema.TaggedError<
|
|
|
17
22
|
reason: Schema.Literals(["deployment", "deployKey"]),
|
|
18
23
|
}) {}
|
|
19
24
|
|
|
25
|
+
export class HealthCheckFailed extends Schema.TaggedError<
|
|
26
|
+
HealthCheckFailed,
|
|
27
|
+
{ readonly brand: unique symbol }
|
|
28
|
+
>()("HealthCheckFailed", {
|
|
29
|
+
expected: Schema.String,
|
|
30
|
+
answered: Schema.optional(Schema.String),
|
|
31
|
+
detail: Schema.optional(Schema.String),
|
|
32
|
+
}) {
|
|
33
|
+
override get message() {
|
|
34
|
+
return this.answered === undefined
|
|
35
|
+
? `health: the pushed code gave no manifest digest (${this.detail ?? "no answer"}); expected ${this.expected}`
|
|
36
|
+
: `health: the pushed code was generated with ${this.answered}, not ${this.expected}`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Prepare's health module is edited, missing, or generated for another
|
|
42
|
+
* manifest. Nothing was pushed.
|
|
43
|
+
*/
|
|
44
|
+
export class StaleManifest extends Schema.TaggedError<
|
|
45
|
+
StaleManifest,
|
|
46
|
+
{ readonly brand: unique symbol }
|
|
47
|
+
>()("StaleManifest", {
|
|
48
|
+
expected: Schema.String,
|
|
49
|
+
reason: Schema.Literals(["DifferentDigest", "NotGenerated"]),
|
|
50
|
+
generated: Schema.optionalKey(Schema.String),
|
|
51
|
+
healthModulePath: Schema.optionalKey(Schema.String),
|
|
52
|
+
}) {
|
|
53
|
+
override get message() {
|
|
54
|
+
return this.reason === "NotGenerated"
|
|
55
|
+
? `The health module ${this.healthModulePath ?? "at the configured functions directory"} is not as codegen writes it, so nothing was pushed. Do not edit or format the file; regenerate it with confect codegen. The CLI that generates it and the Alchemy package that reads it must be on the same Confect release.`
|
|
56
|
+
: `prepare generated manifest ${this.generated}, but the stack imported manifest ${this.expected}, so nothing was pushed. Run confect codegen, commit the generated files and deploy again.`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const HEALTH = "confectHealth:digest";
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The digest prepare wrote into the health module, which is what the push would
|
|
64
|
+
* deploy; none when the module is missing or unreadable.
|
|
65
|
+
*/
|
|
66
|
+
const generatedDigest = Effect.fn("Code.generatedDigest")(
|
|
67
|
+
function* (cwd: string) {
|
|
68
|
+
const fs = yield* FileSystem.FileSystem;
|
|
69
|
+
const path = yield* Path.Path;
|
|
70
|
+
const functions = yield* functionsDirectory(cwd);
|
|
71
|
+
const file = path.join(cwd, functions, "confectHealth.ts");
|
|
72
|
+
const digest = yield* fs
|
|
73
|
+
.readFileString(file)
|
|
74
|
+
.pipe(
|
|
75
|
+
Effect.map(HealthModule.read),
|
|
76
|
+
Effect.orElseSucceed(Option.none<string>),
|
|
77
|
+
);
|
|
78
|
+
return { path: file, digest };
|
|
79
|
+
},
|
|
80
|
+
Effect.orElseSucceed(() => ({
|
|
81
|
+
path: undefined,
|
|
82
|
+
digest: Option.none<string>(),
|
|
83
|
+
})),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Ask the pushed code which manifest digest codegen wrote into it, and fail
|
|
88
|
+
* unless it is `expected`.
|
|
89
|
+
*/
|
|
90
|
+
const checkHealth = Effect.fn("Code.checkHealth")(function* (
|
|
91
|
+
url: string,
|
|
92
|
+
key: Redacted.Redacted<string>,
|
|
93
|
+
expected: string,
|
|
94
|
+
) {
|
|
95
|
+
const client = yield* ConvexClient;
|
|
96
|
+
const answer = yield* client.runFunction(url, key, HEALTH, {}).pipe(
|
|
97
|
+
Effect.mapError((error) =>
|
|
98
|
+
HealthCheckFailed.make({ expected, detail: error._tag }),
|
|
99
|
+
),
|
|
100
|
+
Effect.timeoutOrElse({
|
|
101
|
+
duration: "30 seconds",
|
|
102
|
+
orElse: () =>
|
|
103
|
+
Effect.fail(HealthCheckFailed.make({ expected, detail: "timeout" })),
|
|
104
|
+
}),
|
|
105
|
+
);
|
|
106
|
+
if (typeof answer !== "string")
|
|
107
|
+
return yield* HealthCheckFailed.make({ expected, detail: "not a string" });
|
|
108
|
+
if (answer !== expected)
|
|
109
|
+
return yield* HealthCheckFailed.make({ expected, answered: answer });
|
|
110
|
+
});
|
|
111
|
+
|
|
20
112
|
const deploymentName = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
21
113
|
|
|
22
114
|
const cloudTarget = (
|
|
@@ -83,6 +175,23 @@ export const deploy = Effect.fn("Code.deploy")(function* (
|
|
|
83
175
|
Effect.gen(function* () {
|
|
84
176
|
if (props.prepare !== undefined)
|
|
85
177
|
yield* runner.prepare(props.prepare, props.cwd);
|
|
178
|
+
if (props.manifestDigest !== undefined) {
|
|
179
|
+
const { path: file, digest: generated } = yield* generatedDigest(
|
|
180
|
+
path.resolve(props.cwd ?? "."),
|
|
181
|
+
);
|
|
182
|
+
if (Option.getOrUndefined(generated) !== props.manifestDigest)
|
|
183
|
+
return yield* StaleManifest.make({
|
|
184
|
+
expected: props.manifestDigest,
|
|
185
|
+
...(file === undefined ? {} : { healthModulePath: file }),
|
|
186
|
+
reason: Option.isNone(generated)
|
|
187
|
+
? "NotGenerated"
|
|
188
|
+
: "DifferentDigest",
|
|
189
|
+
...Option.match(generated, {
|
|
190
|
+
onNone: () => ({}),
|
|
191
|
+
onSome: (digest) => ({ generated: digest }),
|
|
192
|
+
}),
|
|
193
|
+
});
|
|
194
|
+
}
|
|
86
195
|
yield* runner.deploy(target, props.cwd);
|
|
87
196
|
// WORKAROUND: Convex has no component `init` or install `args` in a
|
|
88
197
|
// stable release, so each push runs every mount's `init` itself, inside
|
|
@@ -95,6 +204,12 @@ export const deploy = Effect.fn("Code.deploy")(function* (
|
|
|
95
204
|
props.deployKey,
|
|
96
205
|
path.resolve(props.cwd ?? "."),
|
|
97
206
|
);
|
|
207
|
+
if (props.manifestDigest !== undefined)
|
|
208
|
+
yield* checkHealth(
|
|
209
|
+
props.deployment.url,
|
|
210
|
+
props.deployKey,
|
|
211
|
+
props.manifestDigest,
|
|
212
|
+
);
|
|
98
213
|
}),
|
|
99
214
|
);
|
|
100
215
|
return { name: props.deployment.name, url: props.deployment.url };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as FileSystem from "effect/FileSystem";
|
|
3
|
+
import * as Path from "effect/Path";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
|
|
6
|
+
const ConvexJson = Schema.fromJsonString(
|
|
7
|
+
Schema.Struct({ functions: Schema.optional(Schema.String) }),
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The backend's Convex directory relative to `cwd`, which `convex.json` may
|
|
12
|
+
* move from `convex`.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export const functionsDirectory = Effect.fn("FunctionsDirectory.resolve")(
|
|
17
|
+
function* (cwd: string) {
|
|
18
|
+
const fs = yield* FileSystem.FileSystem;
|
|
19
|
+
const path = yield* Path.Path;
|
|
20
|
+
const config = path.join(cwd, "convex.json");
|
|
21
|
+
if (!(yield* fs.exists(config))) return "convex";
|
|
22
|
+
const { functions } = yield* fs
|
|
23
|
+
.readFileString(config)
|
|
24
|
+
.pipe(Effect.flatMap(Schema.decodeEffect(ConvexJson)));
|
|
25
|
+
return functions ?? "convex";
|
|
26
|
+
},
|
|
27
|
+
);
|
|
@@ -211,6 +211,11 @@ export const adminKey = Effect.fn("LocalBackend.adminKey")(function* (
|
|
|
211
211
|
return Redacted.make(identity.value.adminKey);
|
|
212
212
|
});
|
|
213
213
|
|
|
214
|
+
/**
|
|
215
|
+
* Remove a local deployment's retained data.
|
|
216
|
+
*
|
|
217
|
+
* @stability unstable
|
|
218
|
+
*/
|
|
214
219
|
export const remove = Effect.fn("LocalBackend.remove")(function* (
|
|
215
220
|
deploymentName: string,
|
|
216
221
|
directory: string,
|
|
@@ -274,6 +279,8 @@ const install = Effect.fn("LocalBackend.install")(function* (
|
|
|
274
279
|
* picks two free loopback ports; later boots reuse all of them, so stored
|
|
275
280
|
* credentials and URLs stay valid. A saved port that something else now holds
|
|
276
281
|
* is an error rather than a move, because resources keep the URL.
|
|
282
|
+
*
|
|
283
|
+
* @stability unstable
|
|
277
284
|
*/
|
|
278
285
|
export const boot = Effect.fn("LocalBackend.boot")(function* (
|
|
279
286
|
deploymentName: string,
|
|
@@ -4,6 +4,7 @@ import * as Path from "effect/Path";
|
|
|
4
4
|
import type * as Redacted from "effect/Redacted";
|
|
5
5
|
import * as Schema from "effect/Schema";
|
|
6
6
|
import { ConvexClient, ConvexFunctionError } from "../ConvexClient.js";
|
|
7
|
+
import { functionsDirectory } from "./FunctionsDirectory.js";
|
|
7
8
|
|
|
8
9
|
export class MountInitFailed extends Schema.TaggedError<
|
|
9
10
|
MountInitFailed,
|
|
@@ -29,26 +30,15 @@ const Steps = Schema.Array(
|
|
|
29
30
|
|
|
30
31
|
const STEPS = "confectDeploy:steps";
|
|
31
32
|
|
|
32
|
-
const ConvexJson = Schema.fromJsonString(
|
|
33
|
-
Schema.Struct({ functions: Schema.optional(Schema.String) }),
|
|
34
|
-
);
|
|
35
|
-
|
|
36
33
|
/**
|
|
37
|
-
* Whether codegen wrote `confectDeploy.ts` into the backend's Convex directory
|
|
38
|
-
* which `convex.json` may move.
|
|
34
|
+
* Whether codegen wrote `confectDeploy.ts` into the backend's Convex directory.
|
|
39
35
|
*/
|
|
40
36
|
const hasDeployModule = Effect.fn("MountInit.hasDeployModule")(function* (
|
|
41
37
|
cwd: string,
|
|
42
38
|
) {
|
|
43
39
|
const fs = yield* FileSystem.FileSystem;
|
|
44
40
|
const path = yield* Path.Path;
|
|
45
|
-
const
|
|
46
|
-
const functions = (yield* fs.exists(config))
|
|
47
|
-
? ((yield* fs
|
|
48
|
-
.readFileString(config)
|
|
49
|
-
.pipe(Effect.flatMap(Schema.decodeEffect(ConvexJson)))).functions ??
|
|
50
|
-
"convex")
|
|
51
|
-
: "convex";
|
|
41
|
+
const functions = yield* functionsDirectory(cwd);
|
|
52
42
|
return yield* fs.exists(path.join(cwd, functions, "confectDeploy.ts"));
|
|
53
43
|
});
|
|
54
44
|
|