@gaganref/confect-alchemy 10.3.1-fork.96 → 10.6.0-fork.2
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 +1 -1
- package/dist/Backend.d.ts.map +1 -1
- package/dist/Backend.js +2 -3
- package/dist/Backend.js.map +1 -1
- package/dist/Code.d.ts +16 -3
- package/dist/Code.d.ts.map +1 -1
- package/dist/Code.js +13 -3
- package/dist/Code.js.map +1 -1
- package/dist/Confect.d.ts.map +1 -1
- package/dist/Confect.js +1 -2
- package/dist/Convex.d.ts.map +1 -1
- package/dist/Convex.js +3 -4
- package/dist/ConvexClient.d.ts +14 -4
- package/dist/ConvexClient.d.ts.map +1 -1
- package/dist/ConvexClient.js +44 -36
- package/dist/ConvexClient.js.map +1 -1
- package/dist/DeployKey.d.ts +22 -12
- package/dist/DeployKey.d.ts.map +1 -1
- package/dist/DeployKey.js +41 -29
- package/dist/DeployKey.js.map +1 -1
- package/dist/Deployment.d.ts +19 -10
- package/dist/Deployment.d.ts.map +1 -1
- package/dist/Deployment.js +22 -19
- package/dist/Deployment.js.map +1 -1
- package/dist/EnvironmentVariables.d.ts +23 -31
- package/dist/EnvironmentVariables.d.ts.map +1 -1
- package/dist/EnvironmentVariables.js +21 -20
- package/dist/EnvironmentVariables.js.map +1 -1
- package/dist/Project.d.ts +15 -10
- package/dist/Project.d.ts.map +1 -1
- package/dist/Project.js +23 -22
- package/dist/Project.js.map +1 -1
- package/dist/Providers.d.ts +3 -1
- package/dist/Providers.d.ts.map +1 -1
- package/dist/Providers.js +19 -18
- package/dist/Providers.js.map +1 -1
- package/dist/_virtual/_rolldown/runtime.js +5 -6
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/CodeDeployment.d.ts +6 -1
- package/dist/internal/CodeDeployment.d.ts.map +1 -1
- package/dist/internal/CodeDeployment.js +10 -8
- package/dist/internal/CodeDeployment.js.map +1 -1
- package/dist/internal/CommandRunner.d.ts +6 -1
- package/dist/internal/CommandRunner.d.ts.map +1 -1
- package/dist/internal/CommandRunner.js +11 -9
- package/dist/internal/CommandRunner.js.map +1 -1
- package/dist/internal/FileLock.d.ts +7 -3
- package/dist/internal/FileLock.d.ts.map +1 -1
- package/dist/internal/FileLock.js +10 -8
- package/dist/internal/FileLock.js.map +1 -1
- package/dist/internal/Lifecycle.d.ts +3 -1
- package/dist/internal/Lifecycle.d.ts.map +1 -1
- package/dist/internal/Lifecycle.js +3 -4
- package/dist/internal/Lifecycle.js.map +1 -1
- package/dist/internal/LocalBackend.d.ts +7 -3
- package/dist/internal/LocalBackend.d.ts.map +1 -1
- package/dist/internal/LocalBackend.js +26 -18
- package/dist/internal/LocalBackend.js.map +1 -1
- package/dist/internal/LocalSidecar.d.ts +4 -1
- package/dist/internal/LocalSidecar.d.ts.map +1 -1
- package/dist/internal/LocalSidecar.js +4 -2
- package/dist/internal/LocalSidecar.js.map +1 -1
- package/dist/internal/Loopback.d.ts.map +1 -1
- package/dist/internal/Loopback.js +1 -2
- package/dist/internal/MountInit.d.ts +5 -1
- package/dist/internal/MountInit.d.ts.map +1 -1
- package/dist/internal/MountInit.js +5 -4
- package/dist/internal/MountInit.js.map +1 -1
- package/dist/internal/PushLock.d.ts +7 -3
- package/dist/internal/PushLock.d.ts.map +1 -1
- package/dist/internal/PushLock.js +7 -6
- package/dist/internal/PushLock.js.map +1 -1
- package/dist/internal/ResourceIdentity.d.ts.map +1 -1
- package/dist/internal/ResourceIdentity.js +5 -3
- package/dist/internal/ResourceIdentity.js.map +1 -1
- package/dist/internal/UserCache.d.ts +2 -0
- package/dist/internal/UserCache.d.ts.map +1 -1
- package/dist/internal/UserCache.js +5 -4
- package/dist/internal/UserCache.js.map +1 -1
- package/dist/internal/Zip.d.ts +5 -1
- package/dist/internal/Zip.d.ts.map +1 -1
- package/dist/internal/Zip.js +9 -8
- package/dist/internal/Zip.js.map +1 -1
- package/package.json +5 -5
- package/src/Backend.ts +7 -6
- package/src/Code.ts +11 -0
- package/src/ConvexClient.ts +87 -74
- package/src/DeployKey.ts +73 -44
- package/src/Deployment.ts +50 -37
- package/src/EnvironmentVariables.ts +30 -27
- package/src/Project.ts +42 -41
- package/src/Providers.ts +2 -0
- package/src/index.ts +3 -0
- package/src/internal/CodeDeployment.ts +17 -11
- package/src/internal/CommandRunner.ts +27 -26
- package/src/internal/FileLock.ts +15 -12
- package/src/internal/Lifecycle.ts +11 -7
- package/src/internal/LocalBackend.ts +45 -39
- package/src/internal/LocalSidecar.ts +3 -0
- package/src/internal/MountInit.ts +8 -6
- package/src/internal/PushLock.ts +13 -11
- package/src/internal/ResourceIdentity.ts +12 -5
- package/src/internal/UserCache.ts +13 -4
- package/src/internal/Zip.ts +13 -8
package/src/Deployment.ts
CHANGED
|
@@ -18,6 +18,7 @@ import type { Providers } from "./Providers.js";
|
|
|
18
18
|
import { resourceName } from "./internal/ResourceIdentity.js";
|
|
19
19
|
import { checkpointCreate, shouldAdopt } from "./internal/Lifecycle.js";
|
|
20
20
|
import { boot, dataDirectories, remove } from "./internal/LocalBackend.js";
|
|
21
|
+
import * as Array from "effect/Array";
|
|
21
22
|
|
|
22
23
|
export interface DeploymentProps {
|
|
23
24
|
readonly projectId: number;
|
|
@@ -49,25 +50,28 @@ export const Deployment = Resource<Deployment>("Convex.Deployment", {
|
|
|
49
50
|
defaultRemovalPolicy: "retain",
|
|
50
51
|
});
|
|
51
52
|
|
|
52
|
-
export class DeploymentIdentityChange extends Schema.TaggedError<
|
|
53
|
-
|
|
54
|
-
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
) {}
|
|
53
|
+
export class DeploymentIdentityChange extends Schema.TaggedError<
|
|
54
|
+
DeploymentIdentityChange,
|
|
55
|
+
{ readonly brand: unique symbol }
|
|
56
|
+
>()("DeploymentIdentityChange", {
|
|
57
|
+
deploymentName: Schema.String,
|
|
58
|
+
field: Schema.String,
|
|
59
|
+
current: Schema.String,
|
|
60
|
+
requested: Schema.String,
|
|
61
|
+
}) {}
|
|
61
62
|
|
|
62
|
-
export class UnsupportedLocalDeployment extends Schema.TaggedError<
|
|
63
|
-
|
|
64
|
-
{
|
|
65
|
-
) {}
|
|
63
|
+
export class UnsupportedLocalDeployment extends Schema.TaggedError<
|
|
64
|
+
UnsupportedLocalDeployment,
|
|
65
|
+
{ readonly brand: unique symbol }
|
|
66
|
+
>()("UnsupportedLocalDeployment", { deploymentName: Schema.String }) {}
|
|
66
67
|
|
|
67
|
-
export class AmbiguousDeployment extends Schema.TaggedError<
|
|
68
|
-
|
|
69
|
-
{
|
|
70
|
-
) {
|
|
68
|
+
export class AmbiguousDeployment extends Schema.TaggedError<
|
|
69
|
+
AmbiguousDeployment,
|
|
70
|
+
{ readonly brand: unique symbol }
|
|
71
|
+
>()("AmbiguousDeployment", {
|
|
72
|
+
projectId: Schema.Finite,
|
|
73
|
+
reference: Schema.String,
|
|
74
|
+
}) {}
|
|
71
75
|
|
|
72
76
|
export const provider = Effect.gen(function* () {
|
|
73
77
|
const client = yield* ConvexClient;
|
|
@@ -75,7 +79,7 @@ export const provider = Effect.gen(function* () {
|
|
|
75
79
|
deployment: PlatformDeploymentResponse,
|
|
76
80
|
) {
|
|
77
81
|
if (deployment.kind !== "cloud")
|
|
78
|
-
return yield*
|
|
82
|
+
return yield* UnsupportedLocalDeployment.make({
|
|
79
83
|
deploymentName: deployment.name,
|
|
80
84
|
});
|
|
81
85
|
return {
|
|
@@ -91,12 +95,14 @@ export const provider = Effect.gen(function* () {
|
|
|
91
95
|
projectId: number,
|
|
92
96
|
reference: string,
|
|
93
97
|
) {
|
|
94
|
-
const
|
|
98
|
+
const deployments = yield* client.listDeployments(projectId);
|
|
99
|
+
const matches = Array.filter(
|
|
100
|
+
deployments,
|
|
95
101
|
(deployment) =>
|
|
96
102
|
deployment.kind === "cloud" && deployment.reference === reference,
|
|
97
103
|
);
|
|
98
104
|
if (matches.length > 1)
|
|
99
|
-
return yield*
|
|
105
|
+
return yield* AmbiguousDeployment.make({ projectId, reference });
|
|
100
106
|
return matches[0];
|
|
101
107
|
});
|
|
102
108
|
const validate = Effect.fn("Deployment.validate")(function* (
|
|
@@ -105,7 +111,7 @@ export const provider = Effect.gen(function* () {
|
|
|
105
111
|
) {
|
|
106
112
|
for (const field of ["projectId", "type", "region"] as const) {
|
|
107
113
|
if (news[field] !== undefined && current[field] !== news[field])
|
|
108
|
-
return yield*
|
|
114
|
+
return yield* DeploymentIdentityChange.make({
|
|
109
115
|
deploymentName: current.name,
|
|
110
116
|
field,
|
|
111
117
|
current: String(current[field]),
|
|
@@ -115,12 +121,12 @@ export const provider = Effect.gen(function* () {
|
|
|
115
121
|
});
|
|
116
122
|
return {
|
|
117
123
|
diff: Effect.fn("Deployment.diff")(function* ({ news, output }) {
|
|
118
|
-
if (!isResolved(news) ||
|
|
124
|
+
if (!isResolved(news) || output === undefined) return;
|
|
119
125
|
yield* validate(output, news);
|
|
120
126
|
const deployment = yield* client
|
|
121
127
|
.getDeployment(output.name)
|
|
122
128
|
.pipe(Effect.catchTag("ConvexNotFound", () => Effect.void));
|
|
123
|
-
if (
|
|
129
|
+
if (deployment === undefined) return { action: "update" };
|
|
124
130
|
const current = yield* attributes(deployment);
|
|
125
131
|
yield* validate(current, news);
|
|
126
132
|
if ((news.reference ?? output.reference) !== current.reference)
|
|
@@ -132,18 +138,22 @@ export const provider = Effect.gen(function* () {
|
|
|
132
138
|
olds,
|
|
133
139
|
output,
|
|
134
140
|
}) {
|
|
135
|
-
if (output) {
|
|
141
|
+
if (output !== undefined) {
|
|
136
142
|
const deployment = yield* client
|
|
137
143
|
.getDeployment(output.name)
|
|
138
144
|
.pipe(Effect.catchTag("ConvexNotFound", () => Effect.void));
|
|
139
|
-
return deployment
|
|
145
|
+
return deployment !== undefined
|
|
146
|
+
? yield* attributes(deployment)
|
|
147
|
+
: undefined;
|
|
140
148
|
}
|
|
141
149
|
if (olds.projectId === undefined) return;
|
|
142
150
|
const deployment = yield* find(
|
|
143
151
|
olds.projectId,
|
|
144
152
|
olds.reference ?? (yield* resourceName("deployment", fqn, instanceId)),
|
|
145
153
|
);
|
|
146
|
-
return deployment
|
|
154
|
+
return deployment !== undefined
|
|
155
|
+
? yield* Effect.map(attributes(deployment), Unowned)
|
|
156
|
+
: undefined;
|
|
147
157
|
}),
|
|
148
158
|
reconcile: Effect.fn("Deployment.reconcile")(function* ({
|
|
149
159
|
fqn,
|
|
@@ -151,26 +161,27 @@ export const provider = Effect.gen(function* () {
|
|
|
151
161
|
news,
|
|
152
162
|
output,
|
|
153
163
|
}) {
|
|
154
|
-
if (
|
|
155
|
-
if (output) yield* validate(output, news);
|
|
156
|
-
let deployment =
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
164
|
+
if (output === undefined) yield* checkpointCreate(fqn, instanceId, news);
|
|
165
|
+
if (output !== undefined) yield* validate(output, news);
|
|
166
|
+
let deployment =
|
|
167
|
+
output !== undefined
|
|
168
|
+
? yield* client
|
|
169
|
+
.getDeployment(output.name)
|
|
170
|
+
.pipe(Effect.catchTag("ConvexNotFound", () => Effect.void))
|
|
171
|
+
: undefined;
|
|
161
172
|
const reference =
|
|
162
173
|
news.reference ??
|
|
163
174
|
output?.reference ??
|
|
164
175
|
(yield* resourceName("deployment", fqn, instanceId));
|
|
165
|
-
if (
|
|
176
|
+
if (deployment === undefined) {
|
|
166
177
|
const existing = yield* find(news.projectId, reference);
|
|
167
|
-
if (existing && !(yield* shouldAdopt(fqn)))
|
|
178
|
+
if (existing !== undefined && !(yield* shouldAdopt(fqn)))
|
|
168
179
|
return yield* new OwnedBySomeoneElse({
|
|
169
180
|
message: "An existing deployment requires explicit adoption.",
|
|
170
181
|
resourceType: Deployment.Type,
|
|
171
182
|
physicalName: reference,
|
|
172
183
|
});
|
|
173
|
-
if (existing) {
|
|
184
|
+
if (existing !== undefined) {
|
|
174
185
|
const adopted = yield* attributes(existing);
|
|
175
186
|
yield* validate(adopted, news);
|
|
176
187
|
yield* checkpointCreate(fqn, instanceId, news, adopted);
|
|
@@ -187,7 +198,7 @@ export const provider = Effect.gen(function* () {
|
|
|
187
198
|
yield* validate(current, news);
|
|
188
199
|
if (current.reference !== reference) {
|
|
189
200
|
const existing = yield* find(news.projectId, reference);
|
|
190
|
-
if (existing && existing.name !== current.name)
|
|
201
|
+
if (existing !== undefined && existing.name !== current.name)
|
|
191
202
|
return yield* new OwnedBySomeoneElse({
|
|
192
203
|
message: "The requested deployment reference is already in use.",
|
|
193
204
|
resourceType: Deployment.Type,
|
|
@@ -219,6 +230,8 @@ interface LocalConfig {
|
|
|
219
230
|
* reloads of the stack and stops when the dev session ends. Its data lives in
|
|
220
231
|
* `.alchemy/convex/<stack>/<stage>/<name>` and is removed only when the
|
|
221
232
|
* deployment is destroyed.
|
|
233
|
+
*
|
|
234
|
+
* @stability unstable
|
|
222
235
|
*/
|
|
223
236
|
export const localLayer = LocalProvider.make(
|
|
224
237
|
Deployment,
|
|
@@ -11,6 +11,8 @@ import * as Schema from "effect/Schema";
|
|
|
11
11
|
import * as ConvexClient from "./ConvexClient.js";
|
|
12
12
|
import type { Providers } from "./Providers.js";
|
|
13
13
|
import { checkpointCreate, shouldAdopt } from "./internal/Lifecycle.js";
|
|
14
|
+
import * as Arr from "effect/Array";
|
|
15
|
+
import * as Rec from "effect/Record";
|
|
14
16
|
|
|
15
17
|
export interface EnvironmentVariablesProps {
|
|
16
18
|
readonly url: string;
|
|
@@ -39,10 +41,10 @@ export const EnvironmentVariables = Resource<EnvironmentVariables>(
|
|
|
39
41
|
"Convex.EnvironmentVariables",
|
|
40
42
|
);
|
|
41
43
|
|
|
42
|
-
export class EnvironmentTargetChange extends Schema.TaggedError<
|
|
43
|
-
|
|
44
|
-
{
|
|
45
|
-
) {}
|
|
44
|
+
export class EnvironmentTargetChange extends Schema.TaggedError<
|
|
45
|
+
EnvironmentTargetChange,
|
|
46
|
+
{ readonly brand: unique symbol }
|
|
47
|
+
>()("EnvironmentTargetChange", { url: Schema.String }) {}
|
|
46
48
|
|
|
47
49
|
export const provider = Effect.gen(function* () {
|
|
48
50
|
const client = yield* ConvexClient.ConvexClient;
|
|
@@ -51,34 +53,34 @@ export const provider = Effect.gen(function* () {
|
|
|
51
53
|
const valueAt = (
|
|
52
54
|
variables: Readonly<Record<string, Redacted.Redacted<string>>>,
|
|
53
55
|
name: string,
|
|
54
|
-
) => (
|
|
56
|
+
) => (Rec.has(variables, name) ? variables[name] : undefined);
|
|
55
57
|
const select = (
|
|
56
58
|
variables: Readonly<Record<string, Redacted.Redacted<string>>>,
|
|
57
59
|
names: ReadonlyArray<string>,
|
|
58
60
|
) =>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
!
|
|
61
|
+
Rec.fromEntries(
|
|
62
|
+
Arr.flatMap(names, (name) =>
|
|
63
|
+
!Rec.has(variables, name) ? [] : [[name, variables[name]]],
|
|
62
64
|
),
|
|
63
65
|
);
|
|
64
66
|
return {
|
|
65
67
|
diff: Effect.fn("EnvironmentVariables.diff")(function* ({ news, output }) {
|
|
66
|
-
if (!isResolved(news) ||
|
|
68
|
+
if (!isResolved(news) || output === undefined) return;
|
|
67
69
|
if (news.url !== output.url)
|
|
68
|
-
return yield*
|
|
70
|
+
return yield* EnvironmentTargetChange.make({
|
|
69
71
|
url: output.url,
|
|
70
72
|
});
|
|
71
|
-
const names =
|
|
73
|
+
const names = Rec.keys(news.variables);
|
|
72
74
|
if (
|
|
73
75
|
names.length !== output.ownedNames.length ||
|
|
74
|
-
|
|
76
|
+
Arr.some(names, (name) => !output.ownedNames.includes(name))
|
|
75
77
|
)
|
|
76
78
|
return { action: "update" };
|
|
77
79
|
const variables = yield* client.listEnvironmentVariables(
|
|
78
80
|
news.url,
|
|
79
81
|
news.deployKey,
|
|
80
82
|
);
|
|
81
|
-
for (const [name, value] of
|
|
83
|
+
for (const [name, value] of Rec.toEntries(news.variables)) {
|
|
82
84
|
const observed = valueAt(variables, name);
|
|
83
85
|
if (
|
|
84
86
|
observed === undefined ||
|
|
@@ -94,10 +96,11 @@ export const provider = Effect.gen(function* () {
|
|
|
94
96
|
url,
|
|
95
97
|
olds.deployKey,
|
|
96
98
|
);
|
|
97
|
-
const ownedNames = output?.ownedNames ??
|
|
99
|
+
const ownedNames = output?.ownedNames ?? Rec.keys(olds.variables);
|
|
98
100
|
const variables = select(observed, ownedNames);
|
|
99
|
-
if (output
|
|
100
|
-
|
|
101
|
+
if (output !== undefined)
|
|
102
|
+
return { ...output, deployKey: olds.deployKey, variables };
|
|
103
|
+
if (Rec.keys(variables).length === 0) return undefined;
|
|
101
104
|
return Unowned({
|
|
102
105
|
url,
|
|
103
106
|
deployKey: olds.deployKey,
|
|
@@ -112,17 +115,17 @@ export const provider = Effect.gen(function* () {
|
|
|
112
115
|
news,
|
|
113
116
|
output,
|
|
114
117
|
}) {
|
|
115
|
-
if (
|
|
116
|
-
if (output && output.url !== news.url)
|
|
117
|
-
return yield*
|
|
118
|
+
if (output === undefined) yield* checkpointCreate(fqn, instanceId, news);
|
|
119
|
+
if (output !== undefined && output.url !== news.url)
|
|
120
|
+
return yield* EnvironmentTargetChange.make({
|
|
118
121
|
url: output.url,
|
|
119
122
|
});
|
|
120
123
|
const observed = yield* client.listEnvironmentVariables(
|
|
121
124
|
news.url,
|
|
122
125
|
news.deployKey,
|
|
123
126
|
);
|
|
124
|
-
const ownedNames =
|
|
125
|
-
if (
|
|
127
|
+
const ownedNames = Rec.keys(news.variables);
|
|
128
|
+
if (output === undefined && (yield* shouldAdopt(fqn))) {
|
|
126
129
|
const variables = select(observed, ownedNames);
|
|
127
130
|
output = {
|
|
128
131
|
url: news.url,
|
|
@@ -146,8 +149,8 @@ export const provider = Effect.gen(function* () {
|
|
|
146
149
|
physicalName: name,
|
|
147
150
|
});
|
|
148
151
|
}
|
|
149
|
-
const desired =
|
|
150
|
-
|
|
152
|
+
const desired = Rec.fromEntries(
|
|
153
|
+
Arr.map(Rec.toEntries(news.variables), ([name, value]) => [
|
|
151
154
|
name,
|
|
152
155
|
redacted(value),
|
|
153
156
|
]),
|
|
@@ -156,7 +159,7 @@ export const provider = Effect.gen(function* () {
|
|
|
156
159
|
name: string;
|
|
157
160
|
value?: Redacted.Redacted<string>;
|
|
158
161
|
}> = [];
|
|
159
|
-
for (const [name, value] of
|
|
162
|
+
for (const [name, value] of Rec.toEntries(desired)) {
|
|
160
163
|
const current = valueAt(observed, name);
|
|
161
164
|
if (
|
|
162
165
|
current === undefined ||
|
|
@@ -165,8 +168,9 @@ export const provider = Effect.gen(function* () {
|
|
|
165
168
|
changes.push({ name, value });
|
|
166
169
|
}
|
|
167
170
|
for (const name of previousNames) {
|
|
168
|
-
if (
|
|
169
|
-
const original =
|
|
171
|
+
if (Rec.has(desired, name)) continue;
|
|
172
|
+
const original =
|
|
173
|
+
output !== undefined ? valueAt(output.originals, name) : undefined;
|
|
170
174
|
const current = valueAt(observed, name);
|
|
171
175
|
if (original !== undefined) {
|
|
172
176
|
if (
|
|
@@ -229,7 +233,6 @@ export const localProvider = Effect.map(
|
|
|
229
233
|
({
|
|
230
234
|
...service,
|
|
231
235
|
delete: (input) =>
|
|
232
|
-
// oxlint-disable-next-line effecttsgo/any-unknown-in-error-context -- Alchemy's provider input type erases the delete error channel.
|
|
233
236
|
service.delete(input).pipe(
|
|
234
237
|
Effect.catchIf(
|
|
235
238
|
(error) =>
|
package/src/Project.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { ConvexClient } from "./ConvexClient.js";
|
|
|
9
9
|
import type { Providers } from "./Providers.js";
|
|
10
10
|
import { resourceName } from "./internal/ResourceIdentity.js";
|
|
11
11
|
import { checkpointCreate, shouldAdopt } from "./internal/Lifecycle.js";
|
|
12
|
+
import * as Array from "effect/Array";
|
|
12
13
|
|
|
13
14
|
export interface ProjectProps {
|
|
14
15
|
readonly teamId: number;
|
|
@@ -33,23 +34,23 @@ export const Project = Resource<Project>("Convex.Project", {
|
|
|
33
34
|
defaultRemovalPolicy: "retain",
|
|
34
35
|
});
|
|
35
36
|
|
|
36
|
-
export class ProjectTeamChange extends Schema.TaggedError<
|
|
37
|
-
|
|
38
|
-
{
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
) {}
|
|
37
|
+
export class ProjectTeamChange extends Schema.TaggedError<
|
|
38
|
+
ProjectTeamChange,
|
|
39
|
+
{ readonly brand: unique symbol }
|
|
40
|
+
>()("ProjectTeamChange", {
|
|
41
|
+
projectId: Schema.Finite,
|
|
42
|
+
teamId: Schema.Finite,
|
|
43
|
+
requestedTeamId: Schema.Finite,
|
|
44
|
+
}) {}
|
|
44
45
|
|
|
45
|
-
export class AmbiguousProject extends Schema.TaggedError<
|
|
46
|
-
|
|
47
|
-
{
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
) {}
|
|
46
|
+
export class AmbiguousProject extends Schema.TaggedError<
|
|
47
|
+
AmbiguousProject,
|
|
48
|
+
{ readonly brand: unique symbol }
|
|
49
|
+
>()("AmbiguousProject", {
|
|
50
|
+
teamId: Schema.Finite,
|
|
51
|
+
projectName: Schema.String,
|
|
52
|
+
projectIds: Schema.Array(Schema.Finite),
|
|
53
|
+
}) {}
|
|
53
54
|
|
|
54
55
|
export const provider = Effect.gen(function* () {
|
|
55
56
|
const client = yield* ConvexClient;
|
|
@@ -68,22 +69,21 @@ export const provider = Effect.gen(function* () {
|
|
|
68
69
|
teamId: number,
|
|
69
70
|
name: string,
|
|
70
71
|
) {
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
);
|
|
72
|
+
const projects = yield* client.listProjects(teamId);
|
|
73
|
+
const matches = Array.filter(projects, (project) => project.name === name);
|
|
74
74
|
if (matches.length > 1)
|
|
75
|
-
return yield*
|
|
75
|
+
return yield* AmbiguousProject.make({
|
|
76
76
|
teamId,
|
|
77
|
-
name,
|
|
78
|
-
projectIds:
|
|
77
|
+
projectName: name,
|
|
78
|
+
projectIds: Array.map(matches, (project) => project.id),
|
|
79
79
|
});
|
|
80
80
|
return matches[0];
|
|
81
81
|
});
|
|
82
82
|
return {
|
|
83
83
|
diff: Effect.fn("Project.diff")(function* ({ news, output }) {
|
|
84
|
-
if (!isResolved(news) ||
|
|
84
|
+
if (!isResolved(news) || output === undefined) return;
|
|
85
85
|
if (output.teamId !== news.teamId)
|
|
86
|
-
return yield*
|
|
86
|
+
return yield* ProjectTeamChange.make({
|
|
87
87
|
projectId: output.projectId,
|
|
88
88
|
teamId: output.teamId,
|
|
89
89
|
requestedTeamId: news.teamId,
|
|
@@ -91,9 +91,9 @@ export const provider = Effect.gen(function* () {
|
|
|
91
91
|
const project = yield* client
|
|
92
92
|
.getProject(output.projectId)
|
|
93
93
|
.pipe(Effect.catchTag("ConvexNotFound", () => Effect.void));
|
|
94
|
-
if (
|
|
94
|
+
if (project === undefined) return { action: "update" };
|
|
95
95
|
if (project.teamId !== news.teamId)
|
|
96
|
-
return yield*
|
|
96
|
+
return yield* ProjectTeamChange.make({
|
|
97
97
|
projectId: project.id,
|
|
98
98
|
teamId: project.teamId,
|
|
99
99
|
requestedTeamId: news.teamId,
|
|
@@ -107,18 +107,18 @@ export const provider = Effect.gen(function* () {
|
|
|
107
107
|
olds,
|
|
108
108
|
output,
|
|
109
109
|
}) {
|
|
110
|
-
if (output) {
|
|
110
|
+
if (output !== undefined) {
|
|
111
111
|
const project = yield* client
|
|
112
112
|
.getProject(output.projectId)
|
|
113
113
|
.pipe(Effect.catchTag("ConvexNotFound", () => Effect.void));
|
|
114
|
-
return project ? attributes(project) : undefined;
|
|
114
|
+
return project !== undefined ? attributes(project) : undefined;
|
|
115
115
|
}
|
|
116
116
|
if (olds.teamId === undefined) return;
|
|
117
117
|
const project = yield* find(
|
|
118
118
|
olds.teamId,
|
|
119
119
|
olds.name ?? (yield* resourceName("project", fqn, instanceId)),
|
|
120
120
|
);
|
|
121
|
-
return project ? Unowned(attributes(project)) : undefined;
|
|
121
|
+
return project !== undefined ? Unowned(attributes(project)) : undefined;
|
|
122
122
|
}),
|
|
123
123
|
reconcile: Effect.fn("Project.reconcile")(function* ({
|
|
124
124
|
fqn,
|
|
@@ -126,31 +126,32 @@ export const provider = Effect.gen(function* () {
|
|
|
126
126
|
news,
|
|
127
127
|
output,
|
|
128
128
|
}) {
|
|
129
|
-
if (
|
|
130
|
-
if (output && output.teamId !== news.teamId)
|
|
131
|
-
return yield*
|
|
129
|
+
if (output === undefined) yield* checkpointCreate(fqn, instanceId, news);
|
|
130
|
+
if (output !== undefined && output.teamId !== news.teamId)
|
|
131
|
+
return yield* ProjectTeamChange.make({
|
|
132
132
|
projectId: output.projectId,
|
|
133
133
|
teamId: output.teamId,
|
|
134
134
|
requestedTeamId: news.teamId,
|
|
135
135
|
});
|
|
136
|
-
let project =
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
let project =
|
|
137
|
+
output !== undefined
|
|
138
|
+
? yield* client
|
|
139
|
+
.getProject(output.projectId)
|
|
140
|
+
.pipe(Effect.catchTag("ConvexNotFound", () => Effect.void))
|
|
141
|
+
: undefined;
|
|
141
142
|
const name =
|
|
142
143
|
news.name ??
|
|
143
144
|
output?.name ??
|
|
144
145
|
(yield* resourceName("project", fqn, instanceId));
|
|
145
|
-
if (
|
|
146
|
+
if (project === undefined) {
|
|
146
147
|
const existing = yield* find(news.teamId, name);
|
|
147
|
-
if (existing && !(yield* shouldAdopt(fqn)))
|
|
148
|
+
if (existing !== undefined && !(yield* shouldAdopt(fqn)))
|
|
148
149
|
return yield* new OwnedBySomeoneElse({
|
|
149
150
|
message: "An existing project requires explicit adoption.",
|
|
150
151
|
resourceType: Project.Type,
|
|
151
152
|
physicalName: name,
|
|
152
153
|
});
|
|
153
|
-
if (existing) {
|
|
154
|
+
if (existing !== undefined) {
|
|
154
155
|
project = existing;
|
|
155
156
|
yield* checkpointCreate(fqn, instanceId, news, attributes(existing));
|
|
156
157
|
} else {
|
|
@@ -161,7 +162,7 @@ export const provider = Effect.gen(function* () {
|
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
164
|
if (project.teamId !== news.teamId)
|
|
164
|
-
return yield*
|
|
165
|
+
return yield* ProjectTeamChange.make({
|
|
165
166
|
projectId: project.id,
|
|
166
167
|
teamId: project.teamId,
|
|
167
168
|
requestedTeamId: news.teamId,
|
package/src/Providers.ts
CHANGED
|
@@ -21,6 +21,8 @@ export class Providers extends Provider.ProviderCollection<Providers>()(
|
|
|
21
21
|
* `alchemy deploy` resolves each resource to its cloud provider; `alchemy dev`
|
|
22
22
|
* resolves the same resources to local providers backed by a local Convex
|
|
23
23
|
* backend, so one stack definition serves both.
|
|
24
|
+
*
|
|
25
|
+
* @stability unstable
|
|
24
26
|
*/
|
|
25
27
|
export const providers = (options?: {
|
|
26
28
|
readonly token?: Redacted.Redacted<string>;
|
package/src/index.ts
CHANGED
|
@@ -10,10 +10,12 @@ import * as Loopback from "./Loopback.js";
|
|
|
10
10
|
import * as MountInit from "./MountInit.js";
|
|
11
11
|
import { PushLock } from "./PushLock.js";
|
|
12
12
|
|
|
13
|
-
export class InvalidDeploymentTarget extends Schema.TaggedError<
|
|
14
|
-
|
|
15
|
-
{
|
|
16
|
-
) {
|
|
13
|
+
export class InvalidDeploymentTarget extends Schema.TaggedError<
|
|
14
|
+
InvalidDeploymentTarget,
|
|
15
|
+
{ readonly brand: unique symbol }
|
|
16
|
+
>()("InvalidDeploymentTarget", {
|
|
17
|
+
reason: Schema.Literals(["deployment", "deployKey"]),
|
|
18
|
+
}) {}
|
|
17
19
|
|
|
18
20
|
const deploymentName = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
19
21
|
|
|
@@ -27,13 +29,13 @@ const cloudTarget = (
|
|
|
27
29
|
`^https://${name}(?:\\.[a-z]{2}-[a-z]+-[0-9]+)?\\.convex\\.cloud$`,
|
|
28
30
|
).test(url)
|
|
29
31
|
)
|
|
30
|
-
return Result.fail(
|
|
32
|
+
return Result.fail(InvalidDeploymentTarget.make({ reason: "deployment" }));
|
|
31
33
|
const key =
|
|
32
34
|
/^(?:dev|prod|preview|custom):([a-z0-9]+(?:-[a-z0-9]+)*)\|[a-zA-Z0-9+/=_-]+$/.exec(
|
|
33
35
|
Redacted.value(props.deployKey),
|
|
34
36
|
);
|
|
35
|
-
if (
|
|
36
|
-
return Result.fail(
|
|
37
|
+
if (key === null || key[1] !== name)
|
|
38
|
+
return Result.fail(InvalidDeploymentTarget.make({ reason: "deployKey" }));
|
|
37
39
|
return Result.succeed({
|
|
38
40
|
_tag: "Cloud",
|
|
39
41
|
deploymentName: name,
|
|
@@ -46,12 +48,12 @@ const localTarget = (
|
|
|
46
48
|
): Result.Result<PushTarget, InvalidDeploymentTarget> => {
|
|
47
49
|
const { name, url } = props.deployment;
|
|
48
50
|
if (!deploymentName.test(name) || !Loopback.isOrigin(url))
|
|
49
|
-
return Result.fail(
|
|
51
|
+
return Result.fail(InvalidDeploymentTarget.make({ reason: "deployment" }));
|
|
50
52
|
const key = /^([a-z0-9]+(?:-[a-z0-9]+)*)\|[0-9a-f]+$/.exec(
|
|
51
53
|
Redacted.value(props.deployKey),
|
|
52
54
|
);
|
|
53
|
-
if (
|
|
54
|
-
return Result.fail(
|
|
55
|
+
if (key === null || key[1] !== name)
|
|
56
|
+
return Result.fail(InvalidDeploymentTarget.make({ reason: "deployKey" }));
|
|
55
57
|
return Result.succeed({
|
|
56
58
|
_tag: "SelfHosted",
|
|
57
59
|
deploymentName: name,
|
|
@@ -65,6 +67,9 @@ const targets = { live: cloudTarget, local: localTarget } satisfies Record<
|
|
|
65
67
|
(props: CodeProps) => Result.Result<PushTarget, InvalidDeploymentTarget>
|
|
66
68
|
>;
|
|
67
69
|
|
|
70
|
+
/**
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
68
73
|
export const deploy = Effect.fn("Code.deploy")(function* (
|
|
69
74
|
props: CodeProps,
|
|
70
75
|
mode: ProviderMode = "live",
|
|
@@ -76,7 +81,8 @@ export const deploy = Effect.fn("Code.deploy")(function* (
|
|
|
76
81
|
yield* lock.withLock(
|
|
77
82
|
target.deploymentName,
|
|
78
83
|
Effect.gen(function* () {
|
|
79
|
-
if (props.prepare
|
|
84
|
+
if (props.prepare !== undefined)
|
|
85
|
+
yield* runner.prepare(props.prepare, props.cwd);
|
|
80
86
|
yield* runner.deploy(target, props.cwd);
|
|
81
87
|
// WORKAROUND: Convex has no component `init` or install `args` in a
|
|
82
88
|
// stable release, so each push runs every mount's `init` itself, inside
|