@gaganref/confect-alchemy 10.6.0-fork.3 → 10.6.0-fork.31
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 +4 -1
- package/dist/Convex.d.ts.map +1 -1
- package/dist/Convex.js +10 -1
- package/dist/Convex.js.map +1 -1
- package/dist/ConvexClient.d.ts +92 -3
- package/dist/ConvexClient.d.ts.map +1 -1
- package/dist/ConvexClient.js +149 -27
- package/dist/ConvexClient.js.map +1 -1
- package/dist/CustomDomain.d.ts +156 -0
- package/dist/CustomDomain.d.ts.map +1 -0
- package/dist/CustomDomain.js +255 -0
- package/dist/CustomDomain.js.map +1 -0
- package/dist/DeployKey.js +3 -3
- package/dist/Deployment.d.ts +29 -3
- package/dist/Deployment.d.ts.map +1 -1
- package/dist/Deployment.js +39 -15
- package/dist/Deployment.js.map +1 -1
- package/dist/EnvironmentVariables.d.ts +76 -21
- package/dist/EnvironmentVariables.d.ts.map +1 -1
- package/dist/EnvironmentVariables.js +203 -19
- package/dist/EnvironmentVariables.js.map +1 -1
- package/dist/LogStream.d.ts +134 -0
- package/dist/LogStream.d.ts.map +1 -0
- package/dist/LogStream.js +324 -0
- package/dist/LogStream.js.map +1 -0
- package/dist/Project.js +2 -2
- package/dist/Providers.d.ts.map +1 -1
- package/dist/Providers.js +30 -15
- package/dist/Providers.js.map +1 -1
- package/dist/UsageLimit.d.ts +140 -0
- package/dist/UsageLimit.d.ts.map +1 -0
- package/dist/UsageLimit.js +145 -0
- package/dist/UsageLimit.js.map +1 -0
- 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.d.ts +4 -0
- package/dist/internal/CommandRunner.d.ts.map +1 -1
- package/dist/internal/CommandRunner.js +92 -6
- package/dist/internal/CommandRunner.js.map +1 -1
- 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/Lifecycle.d.ts +1 -0
- package/dist/internal/Lifecycle.d.ts.map +1 -1
- package/dist/internal/Lifecycle.js +24 -2
- package/dist/internal/Lifecycle.js.map +1 -1
- package/dist/internal/LocalBackend.d.ts +9 -0
- package/dist/internal/LocalBackend.d.ts.map +1 -1
- package/dist/internal/LocalBackend.js +14 -5
- package/dist/internal/LocalBackend.js.map +1 -1
- package/dist/internal/LogStream.d.ts +115 -0
- package/dist/internal/LogStream.d.ts.map +1 -0
- package/dist/internal/LogStream.js +123 -0
- package/dist/internal/LogStream.js.map +1 -0
- package/dist/internal/MountInit.d.ts +4 -5
- package/dist/internal/MountInit.d.ts.map +1 -1
- package/dist/internal/MountInit.js +17 -36
- package/dist/internal/MountInit.js.map +1 -1
- package/dist/internal/PushLock.d.ts +1 -0
- package/dist/internal/PushLock.d.ts.map +1 -1
- package/dist/internal/PushLock.js +4 -3
- package/dist/internal/PushLock.js.map +1 -1
- package/dist/internal/ResourceIdentity.js +1 -1
- package/dist/internal/Zip.js +1 -1
- package/package.json +4 -4
- package/src/Backend.ts +422 -12
- package/src/Code.ts +13 -0
- package/src/Confect.ts +7 -1
- package/src/Convex.ts +24 -1
- package/src/ConvexClient.ts +364 -31
- package/src/CustomDomain.ts +453 -0
- package/src/Deployment.ts +74 -12
- package/src/EnvironmentVariables.ts +505 -19
- package/src/LogStream.ts +662 -0
- package/src/Providers.ts +18 -0
- package/src/UsageLimit.ts +253 -0
- package/src/internal/CodeDeployment.ts +115 -0
- package/src/internal/CommandRunner.ts +182 -1
- package/src/internal/FunctionsDirectory.ts +27 -0
- package/src/internal/Lifecycle.ts +21 -1
- package/src/internal/LocalBackend.ts +9 -0
- package/src/internal/LogStream.ts +154 -0
- package/src/internal/MountInit.ts +24 -65
- package/src/internal/PushLock.ts +4 -1
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import type { RequestDestination } from "@convex-dev/platform/managementApi";
|
|
2
|
+
import { OwnedBySomeoneElse, Unowned } from "alchemy/AdoptPolicy";
|
|
3
|
+
import { isResolved } from "alchemy/Diff";
|
|
4
|
+
import type { Input } from "alchemy/Input";
|
|
5
|
+
import * as Output from "alchemy/Output";
|
|
6
|
+
import { State } from "alchemy/State/State";
|
|
7
|
+
import * as Provider from "alchemy/Provider";
|
|
8
|
+
import { Stack } from "alchemy/Stack";
|
|
9
|
+
import { Resource } from "alchemy/Resource";
|
|
10
|
+
import * as Array from "effect/Array";
|
|
11
|
+
import * as Effect from "effect/Effect";
|
|
12
|
+
import * as Option from "effect/Option";
|
|
13
|
+
import * as Record from "effect/Record";
|
|
14
|
+
import * as Schema from "effect/Schema";
|
|
15
|
+
import * as Semaphore from "effect/Semaphore";
|
|
16
|
+
|
|
17
|
+
import { ConvexClient, type CanonicalUrls } from "./ConvexClient.js";
|
|
18
|
+
import type { Providers } from "./Providers.js";
|
|
19
|
+
import {
|
|
20
|
+
checkpointCreate,
|
|
21
|
+
checkpointUpdate,
|
|
22
|
+
shouldAdopt,
|
|
23
|
+
} from "./internal/Lifecycle.js";
|
|
24
|
+
|
|
25
|
+
export interface CustomDomainProps {
|
|
26
|
+
readonly deployment: { readonly name: string; readonly url: string };
|
|
27
|
+
readonly domain: string;
|
|
28
|
+
readonly requestDestination: RequestDestination;
|
|
29
|
+
/**
|
|
30
|
+
* Set the canonical URL after verification. Turning it off resets the default
|
|
31
|
+
* only while this domain is still canonical.
|
|
32
|
+
*/
|
|
33
|
+
readonly canonical?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface CustomDomainAttributes {
|
|
37
|
+
readonly deployment: { readonly name: string; readonly url: string };
|
|
38
|
+
readonly domain: string;
|
|
39
|
+
readonly requestDestination: RequestDestination;
|
|
40
|
+
readonly canonical: boolean;
|
|
41
|
+
readonly verificationTime: number | null;
|
|
42
|
+
/**
|
|
43
|
+
* The HTTPS address of this custom domain, including before verification.
|
|
44
|
+
*/
|
|
45
|
+
readonly url: string;
|
|
46
|
+
/**
|
|
47
|
+
* The canonical URL observed when this resource last changed.
|
|
48
|
+
*/
|
|
49
|
+
readonly canonicalUrl: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type CustomDomain = Resource<
|
|
53
|
+
"Convex.CustomDomain",
|
|
54
|
+
CustomDomainProps,
|
|
55
|
+
CustomDomainAttributes,
|
|
56
|
+
never,
|
|
57
|
+
Providers
|
|
58
|
+
>;
|
|
59
|
+
export const CustomDomain = Resource<CustomDomain>("Convex.CustomDomain");
|
|
60
|
+
|
|
61
|
+
export class CustomDomainNotVisible extends Schema.TaggedError<
|
|
62
|
+
CustomDomainNotVisible,
|
|
63
|
+
{ readonly brand: unique symbol }
|
|
64
|
+
>()("CustomDomainNotVisible", {
|
|
65
|
+
deploymentName: Schema.String,
|
|
66
|
+
domain: Schema.String,
|
|
67
|
+
}) {}
|
|
68
|
+
|
|
69
|
+
const identitySchema = Schema.Struct({
|
|
70
|
+
deploymentName: Schema.String,
|
|
71
|
+
domain: Schema.String,
|
|
72
|
+
requestDestination: Schema.Literals(["convexCloud", "convexSite"]),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const identity = (props: CustomDomainProps) => ({
|
|
76
|
+
deploymentName: props.deployment.name,
|
|
77
|
+
domain: props.domain,
|
|
78
|
+
requestDestination: props.requestDestination,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
export class CustomDomainIdentityChange extends Schema.TaggedError<
|
|
82
|
+
CustomDomainIdentityChange,
|
|
83
|
+
{ readonly brand: unique symbol }
|
|
84
|
+
>()("CustomDomainIdentityChange", {
|
|
85
|
+
oldIdentity: identitySchema,
|
|
86
|
+
newIdentity: identitySchema,
|
|
87
|
+
}) {
|
|
88
|
+
override get message() {
|
|
89
|
+
const old = this.oldIdentity;
|
|
90
|
+
const next = this.newIdentity;
|
|
91
|
+
return `Cannot change custom domain identity from ${old.deploymentName}/${old.domain}/${old.requestDestination} to ${next.deploymentName}/${next.domain}/${next.requestDestination}. Declare a second Convex.CustomDomain with canonical: false, deploy and configure DNS, then move canonical: true after verification and remove the old resource. For the same hostname, remove it from the old deployment before declaring it on the new one.`;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export class ConflictingCanonicalDomains extends Schema.TaggedError<
|
|
96
|
+
ConflictingCanonicalDomains,
|
|
97
|
+
{ readonly brand: unique symbol }
|
|
98
|
+
>()("ConflictingCanonicalDomains", {
|
|
99
|
+
deploymentName: Schema.String,
|
|
100
|
+
requestDestination: Schema.String,
|
|
101
|
+
domains: Schema.Array(Schema.String),
|
|
102
|
+
}) {
|
|
103
|
+
override get message() {
|
|
104
|
+
return `Declare only one canonical custom domain for ${this.deploymentName}/${this.requestDestination}.`;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const validateCanonicalOwner = Effect.fn("CustomDomain.validateCanonicalOwner")(
|
|
109
|
+
function* (fqn: string, props: Partial<CustomDomainProps>) {
|
|
110
|
+
const stack = yield* Effect.serviceOption(Stack);
|
|
111
|
+
if (Option.isNone(stack)) return;
|
|
112
|
+
const declared = stack.value.resources[fqn];
|
|
113
|
+
if (
|
|
114
|
+
declared === undefined ||
|
|
115
|
+
(isResolved(declared.Props.canonical) &&
|
|
116
|
+
declared.Props.canonical !== true)
|
|
117
|
+
)
|
|
118
|
+
return;
|
|
119
|
+
if (
|
|
120
|
+
props.canonical !== true ||
|
|
121
|
+
props.deployment === undefined ||
|
|
122
|
+
props.requestDestination === undefined ||
|
|
123
|
+
props.domain === undefined
|
|
124
|
+
)
|
|
125
|
+
return;
|
|
126
|
+
for (const resource of Record.values(stack.value.resources)) {
|
|
127
|
+
if (resource.Type !== CustomDomain.Type || resource.FQN === fqn) continue;
|
|
128
|
+
let other: Input<CustomDomainProps> = resource.Props;
|
|
129
|
+
if (!isResolved(other)) {
|
|
130
|
+
const state = yield* Effect.serviceOption(State);
|
|
131
|
+
if (Option.isNone(state)) continue;
|
|
132
|
+
const store = yield* state.value;
|
|
133
|
+
const entries = yield* Effect.forEach(
|
|
134
|
+
Record.keys(Output.upstreamAny(other)),
|
|
135
|
+
Effect.fnUntraced(function* (source) {
|
|
136
|
+
const row = yield* store.get({
|
|
137
|
+
stack: stack.value.name,
|
|
138
|
+
stage: stack.value.stage,
|
|
139
|
+
fqn: source,
|
|
140
|
+
});
|
|
141
|
+
return row === undefined ||
|
|
142
|
+
row.kind === "action" ||
|
|
143
|
+
row.attr === undefined
|
|
144
|
+
? undefined
|
|
145
|
+
: ([source, row.attr] as const);
|
|
146
|
+
}),
|
|
147
|
+
);
|
|
148
|
+
const upstream = Record.fromEntries(
|
|
149
|
+
Array.filter(entries, (entry) => entry !== undefined),
|
|
150
|
+
);
|
|
151
|
+
other = yield* Output.evaluateAvailable(other, upstream).pipe(
|
|
152
|
+
Effect.provideService(State, state.value),
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
if (
|
|
156
|
+
isResolved(other) &&
|
|
157
|
+
other.canonical === true &&
|
|
158
|
+
other.deployment.name === props.deployment.name &&
|
|
159
|
+
other.requestDestination === props.requestDestination
|
|
160
|
+
)
|
|
161
|
+
return yield* ConflictingCanonicalDomains.make({
|
|
162
|
+
deploymentName: props.deployment.name,
|
|
163
|
+
requestDestination: props.requestDestination,
|
|
164
|
+
domains: [props.domain, other.domain],
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
const sameIdentity = (
|
|
171
|
+
current: CustomDomainAttributes,
|
|
172
|
+
props: CustomDomainProps,
|
|
173
|
+
) =>
|
|
174
|
+
current.deployment.name === props.deployment.name &&
|
|
175
|
+
current.domain === props.domain &&
|
|
176
|
+
current.requestDestination === props.requestDestination;
|
|
177
|
+
|
|
178
|
+
const validateIdentity = Effect.fn("CustomDomain.validateIdentity")(function* (
|
|
179
|
+
current: CustomDomainAttributes,
|
|
180
|
+
props: CustomDomainProps,
|
|
181
|
+
) {
|
|
182
|
+
if (!sameIdentity(current, props))
|
|
183
|
+
return yield* CustomDomainIdentityChange.make({
|
|
184
|
+
oldIdentity: identity(current),
|
|
185
|
+
newIdentity: identity(props),
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const canonicalUrl = (urls: CanonicalUrls, destination: RequestDestination) =>
|
|
190
|
+
destination === "convexCloud" ? urls.convexCloudUrl : urls.convexSiteUrl;
|
|
191
|
+
|
|
192
|
+
export const provider = Effect.gen(function* () {
|
|
193
|
+
const client = yield* ConvexClient;
|
|
194
|
+
const canonicalLocks = new Map<string, Semaphore.Semaphore>();
|
|
195
|
+
const withCanonicalLock = <A, E, R>(
|
|
196
|
+
deployment: CustomDomainProps["deployment"],
|
|
197
|
+
destination: RequestDestination,
|
|
198
|
+
effect: Effect.Effect<A, E, R>,
|
|
199
|
+
) =>
|
|
200
|
+
Effect.suspend(() => {
|
|
201
|
+
const key = `${deployment.name}/${destination}`;
|
|
202
|
+
let lock = canonicalLocks.get(key);
|
|
203
|
+
if (lock === undefined) {
|
|
204
|
+
lock = Semaphore.makeUnsafe(1);
|
|
205
|
+
canonicalLocks.set(key, lock);
|
|
206
|
+
}
|
|
207
|
+
return lock.withPermit(effect);
|
|
208
|
+
});
|
|
209
|
+
const find = Effect.fn("CustomDomain.find")(function* (
|
|
210
|
+
props: CustomDomainProps,
|
|
211
|
+
) {
|
|
212
|
+
const domains = yield* client
|
|
213
|
+
.listCustomDomains(props.deployment.name)
|
|
214
|
+
.pipe(Effect.catchTag("ConvexNotFound", () => Effect.succeed([])));
|
|
215
|
+
return Option.getOrUndefined(
|
|
216
|
+
Array.findFirst(
|
|
217
|
+
domains,
|
|
218
|
+
(domain) =>
|
|
219
|
+
domain.domain === props.domain &&
|
|
220
|
+
domain.requestDestination === props.requestDestination,
|
|
221
|
+
),
|
|
222
|
+
);
|
|
223
|
+
});
|
|
224
|
+
const resetCanonical = (output: CustomDomainAttributes) =>
|
|
225
|
+
withCanonicalLock(
|
|
226
|
+
output.deployment,
|
|
227
|
+
output.requestDestination,
|
|
228
|
+
Effect.gen(function* () {
|
|
229
|
+
const urls = yield* client
|
|
230
|
+
.getCanonicalUrls(output.deployment.url)
|
|
231
|
+
.pipe(Effect.catchTag("ConvexNotFound", () => Effect.undefined));
|
|
232
|
+
if (
|
|
233
|
+
urls !== undefined &&
|
|
234
|
+
canonicalUrl(urls, output.requestDestination) === output.url
|
|
235
|
+
)
|
|
236
|
+
yield* client
|
|
237
|
+
.updateCanonicalUrl(output.deployment.url, {
|
|
238
|
+
requestDestination: output.requestDestination,
|
|
239
|
+
})
|
|
240
|
+
.pipe(Effect.catchTag("ConvexNotFound", () => Effect.void));
|
|
241
|
+
}),
|
|
242
|
+
);
|
|
243
|
+
return {
|
|
244
|
+
diff: Effect.fn("CustomDomain.diff")(function* ({ fqn, news, output }) {
|
|
245
|
+
if (!isResolved(news)) return;
|
|
246
|
+
if (output !== undefined) yield* validateIdentity(output, news);
|
|
247
|
+
yield* validateCanonicalOwner(fqn, news);
|
|
248
|
+
if (output === undefined) return;
|
|
249
|
+
const current = yield* find(news);
|
|
250
|
+
if (
|
|
251
|
+
output.deployment.url !== news.deployment.url ||
|
|
252
|
+
current === undefined ||
|
|
253
|
+
(current.verificationTime ?? null) !== output.verificationTime ||
|
|
254
|
+
output.canonical !== (news.canonical ?? false)
|
|
255
|
+
)
|
|
256
|
+
return { action: "update" };
|
|
257
|
+
const urls = yield* client.getCanonicalUrls(news.deployment.url);
|
|
258
|
+
if (
|
|
259
|
+
canonicalUrl(urls, news.requestDestination) !== output.canonicalUrl ||
|
|
260
|
+
(news.canonical === true &&
|
|
261
|
+
current.verificationTime != null &&
|
|
262
|
+
canonicalUrl(urls, news.requestDestination) !==
|
|
263
|
+
`https://${news.domain}`)
|
|
264
|
+
)
|
|
265
|
+
return { action: "update" };
|
|
266
|
+
}),
|
|
267
|
+
read: Effect.fn("CustomDomain.read")(function* ({ fqn, olds, output }) {
|
|
268
|
+
if (output === undefined) {
|
|
269
|
+
yield* validateCanonicalOwner(fqn, olds);
|
|
270
|
+
if (
|
|
271
|
+
olds.deployment === undefined ||
|
|
272
|
+
olds.domain === undefined ||
|
|
273
|
+
olds.requestDestination === undefined
|
|
274
|
+
)
|
|
275
|
+
return;
|
|
276
|
+
const current = yield* find({
|
|
277
|
+
deployment: olds.deployment,
|
|
278
|
+
domain: olds.domain,
|
|
279
|
+
requestDestination: olds.requestDestination,
|
|
280
|
+
});
|
|
281
|
+
if (current === undefined) return;
|
|
282
|
+
const urls = yield* client.getCanonicalUrls(olds.deployment.url);
|
|
283
|
+
const attributes = {
|
|
284
|
+
deployment: olds.deployment,
|
|
285
|
+
domain: current.domain,
|
|
286
|
+
requestDestination: current.requestDestination,
|
|
287
|
+
canonical: olds.canonical ?? false,
|
|
288
|
+
verificationTime: current.verificationTime ?? null,
|
|
289
|
+
url: `https://${current.domain}`,
|
|
290
|
+
canonicalUrl: canonicalUrl(urls, current.requestDestination),
|
|
291
|
+
};
|
|
292
|
+
return Unowned(attributes);
|
|
293
|
+
}
|
|
294
|
+
const current = yield* find(output);
|
|
295
|
+
if (current === undefined && !output.canonical) return;
|
|
296
|
+
const urls = yield* client
|
|
297
|
+
.getCanonicalUrls(output.deployment.url)
|
|
298
|
+
.pipe(Effect.catchTag("ConvexNotFound", () => Effect.void));
|
|
299
|
+
if (urls === undefined) return;
|
|
300
|
+
return {
|
|
301
|
+
...output,
|
|
302
|
+
verificationTime: current?.verificationTime ?? null,
|
|
303
|
+
canonicalUrl: canonicalUrl(urls, output.requestDestination),
|
|
304
|
+
};
|
|
305
|
+
}),
|
|
306
|
+
reconcile: Effect.fn("CustomDomain.reconcile")(function* ({
|
|
307
|
+
fqn,
|
|
308
|
+
instanceId,
|
|
309
|
+
news,
|
|
310
|
+
output,
|
|
311
|
+
}) {
|
|
312
|
+
if (output !== undefined) yield* validateIdentity(output, news);
|
|
313
|
+
yield* validateCanonicalOwner(fqn, news);
|
|
314
|
+
if (output === undefined) yield* checkpointCreate(fqn, instanceId, news);
|
|
315
|
+
let current = yield* find(news);
|
|
316
|
+
if (
|
|
317
|
+
current !== undefined &&
|
|
318
|
+
output === undefined &&
|
|
319
|
+
!(yield* shouldAdopt(fqn))
|
|
320
|
+
)
|
|
321
|
+
return yield* new OwnedBySomeoneElse({
|
|
322
|
+
message: `Custom domain ${news.domain} requires explicit adoption. Re-run with --adopt or adopt(true) to take it over.`,
|
|
323
|
+
resourceType: CustomDomain.Type,
|
|
324
|
+
physicalName: news.domain,
|
|
325
|
+
});
|
|
326
|
+
const url = `https://${news.domain}`;
|
|
327
|
+
const canonical = news.canonical ?? false;
|
|
328
|
+
const attributes = {
|
|
329
|
+
deployment: news.deployment,
|
|
330
|
+
domain: news.domain,
|
|
331
|
+
requestDestination: news.requestDestination,
|
|
332
|
+
canonical: canonical || (output?.canonical ?? false),
|
|
333
|
+
verificationTime: current?.verificationTime ?? null,
|
|
334
|
+
url,
|
|
335
|
+
canonicalUrl: output?.canonicalUrl ?? url,
|
|
336
|
+
};
|
|
337
|
+
if (current === undefined) {
|
|
338
|
+
yield* client.createCustomDomain(news.deployment.name, {
|
|
339
|
+
domain: news.domain,
|
|
340
|
+
requestDestination: news.requestDestination,
|
|
341
|
+
});
|
|
342
|
+
yield* checkpointCreate(fqn, instanceId, news, attributes);
|
|
343
|
+
current = yield* find(news);
|
|
344
|
+
}
|
|
345
|
+
if (current === undefined)
|
|
346
|
+
return yield* CustomDomainNotVisible.make({
|
|
347
|
+
deploymentName: news.deployment.name,
|
|
348
|
+
domain: news.domain,
|
|
349
|
+
});
|
|
350
|
+
yield* checkpointCreate(fqn, instanceId, news, attributes);
|
|
351
|
+
if (output !== undefined && canonical && !output.canonical)
|
|
352
|
+
yield* checkpointUpdate(fqn, instanceId, {
|
|
353
|
+
...output,
|
|
354
|
+
canonical: true,
|
|
355
|
+
});
|
|
356
|
+
const urls = yield* withCanonicalLock(
|
|
357
|
+
news.deployment,
|
|
358
|
+
news.requestDestination,
|
|
359
|
+
Effect.gen(function* () {
|
|
360
|
+
let currentUrls = yield* client.getCanonicalUrls(news.deployment.url);
|
|
361
|
+
if (canonical && current.verificationTime == null) {
|
|
362
|
+
yield* Effect.logInfo(
|
|
363
|
+
`Canonical URL for ${news.domain} is pending verification.`,
|
|
364
|
+
);
|
|
365
|
+
} else if (
|
|
366
|
+
canonical &&
|
|
367
|
+
canonicalUrl(currentUrls, news.requestDestination) !== url
|
|
368
|
+
) {
|
|
369
|
+
yield* client.updateCanonicalUrl(news.deployment.url, {
|
|
370
|
+
requestDestination: news.requestDestination,
|
|
371
|
+
url,
|
|
372
|
+
});
|
|
373
|
+
currentUrls = yield* client.getCanonicalUrls(news.deployment.url);
|
|
374
|
+
} else if (
|
|
375
|
+
!canonical &&
|
|
376
|
+
output?.canonical === true &&
|
|
377
|
+
canonicalUrl(currentUrls, news.requestDestination) === url
|
|
378
|
+
) {
|
|
379
|
+
yield* client.updateCanonicalUrl(news.deployment.url, {
|
|
380
|
+
requestDestination: news.requestDestination,
|
|
381
|
+
});
|
|
382
|
+
currentUrls = yield* client.getCanonicalUrls(news.deployment.url);
|
|
383
|
+
}
|
|
384
|
+
return currentUrls;
|
|
385
|
+
}),
|
|
386
|
+
);
|
|
387
|
+
const result = {
|
|
388
|
+
...attributes,
|
|
389
|
+
canonical,
|
|
390
|
+
verificationTime: current.verificationTime ?? null,
|
|
391
|
+
canonicalUrl: canonicalUrl(urls, news.requestDestination),
|
|
392
|
+
};
|
|
393
|
+
yield* checkpointCreate(fqn, instanceId, news, result);
|
|
394
|
+
return result;
|
|
395
|
+
}),
|
|
396
|
+
delete: Effect.fn("CustomDomain.delete")(function* ({ fqn, output }) {
|
|
397
|
+
const stack = yield* Effect.serviceOption(Stack);
|
|
398
|
+
const state = yield* Effect.serviceOption(State);
|
|
399
|
+
if (Option.isSome(stack) && Option.isSome(state)) {
|
|
400
|
+
const store = yield* state.value;
|
|
401
|
+
for (const resource of Record.values(stack.value.resources)) {
|
|
402
|
+
if (resource.Type !== CustomDomain.Type || resource.FQN === fqn)
|
|
403
|
+
continue;
|
|
404
|
+
const row = yield* store.get({
|
|
405
|
+
stack: stack.value.name,
|
|
406
|
+
stage: stack.value.stage,
|
|
407
|
+
fqn: resource.FQN,
|
|
408
|
+
});
|
|
409
|
+
if (
|
|
410
|
+
row !== undefined &&
|
|
411
|
+
row.kind !== "action" &&
|
|
412
|
+
row.resourceType === CustomDomain.Type &&
|
|
413
|
+
row.attr?.deployment?.name === output.deployment.name &&
|
|
414
|
+
row.attr?.domain === output.domain &&
|
|
415
|
+
row.attr?.requestDestination === output.requestDestination
|
|
416
|
+
) {
|
|
417
|
+
if (output.canonical && row.attr.canonical !== true)
|
|
418
|
+
yield* resetCanonical(output);
|
|
419
|
+
yield* Effect.logInfo(
|
|
420
|
+
`Skipping delete of ${output.domain}; ${resource.FQN} keeps it.`,
|
|
421
|
+
);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
yield* resetCanonical(output);
|
|
427
|
+
yield* client
|
|
428
|
+
.deleteCustomDomain(output.deployment.name, {
|
|
429
|
+
domain: output.domain,
|
|
430
|
+
requestDestination: output.requestDestination,
|
|
431
|
+
})
|
|
432
|
+
.pipe(Effect.catchTag("ConvexNotFound", () => Effect.void));
|
|
433
|
+
}),
|
|
434
|
+
} satisfies Provider.ProviderServiceInput<CustomDomain>;
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
export const layer = Provider.effect(CustomDomain, provider);
|
|
438
|
+
|
|
439
|
+
export class UnsupportedLocalCustomDomain extends Schema.TaggedError<
|
|
440
|
+
UnsupportedLocalCustomDomain,
|
|
441
|
+
{ readonly brand: unique symbol }
|
|
442
|
+
>()("UnsupportedLocalCustomDomain", {}) {
|
|
443
|
+
override get message() {
|
|
444
|
+
return "Declare Convex.CustomDomain only for cloud stages.";
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
export const localProvider = Effect.succeed({
|
|
449
|
+
reconcile: () => Effect.fail(UnsupportedLocalCustomDomain.make({})),
|
|
450
|
+
delete: () => Effect.void,
|
|
451
|
+
} satisfies Provider.ProviderServiceInput<CustomDomain>);
|
|
452
|
+
|
|
453
|
+
export const localLayer = Provider.effect(CustomDomain, localProvider);
|
package/src/Deployment.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
CreateDeploymentType,
|
|
3
|
+
DeploymentClass,
|
|
3
4
|
PlatformDeploymentResponse,
|
|
4
5
|
RegionName,
|
|
5
6
|
} from "@convex-dev/platform/managementApi";
|
|
@@ -25,6 +26,12 @@ export interface DeploymentProps {
|
|
|
25
26
|
readonly type: CreateDeploymentType;
|
|
26
27
|
readonly reference?: string;
|
|
27
28
|
readonly region?: RegionName;
|
|
29
|
+
readonly class?: DeploymentClass;
|
|
30
|
+
/**
|
|
31
|
+
* Safe integer milliseconds since the Unix epoch. Omit to preserve the
|
|
32
|
+
* current cloud expiry; only null clears it.
|
|
33
|
+
*/
|
|
34
|
+
readonly expiresAt?: number | null;
|
|
28
35
|
}
|
|
29
36
|
|
|
30
37
|
export interface DeploymentAttributes {
|
|
@@ -37,6 +44,14 @@ export interface DeploymentAttributes {
|
|
|
37
44
|
* Always set in the cloud; a local deployment echoes the requested region.
|
|
38
45
|
*/
|
|
39
46
|
readonly region?: RegionName;
|
|
47
|
+
/**
|
|
48
|
+
* Always set in the cloud; local deployments do not have a cloud class.
|
|
49
|
+
*/
|
|
50
|
+
readonly class?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Cloud expiry in milliseconds since the Unix epoch, or null when unset.
|
|
53
|
+
*/
|
|
54
|
+
readonly expiresAt?: number | null;
|
|
40
55
|
}
|
|
41
56
|
|
|
42
57
|
export type Deployment = Resource<
|
|
@@ -73,6 +88,26 @@ export class AmbiguousDeployment extends Schema.TaggedError<
|
|
|
73
88
|
reference: Schema.String,
|
|
74
89
|
}) {}
|
|
75
90
|
|
|
91
|
+
export class InvalidDeploymentExpiry extends Schema.TaggedError<
|
|
92
|
+
InvalidDeploymentExpiry,
|
|
93
|
+
{ readonly brand: unique symbol }
|
|
94
|
+
>()("InvalidDeploymentExpiry", {
|
|
95
|
+
requested: Schema.String,
|
|
96
|
+
}) {
|
|
97
|
+
override get message() {
|
|
98
|
+
return "Deployment expiresAt must be a safe integer timestamp in milliseconds, or null to clear the expiry.";
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const validateExpiry = Effect.fn("Deployment.validateExpiry")(function* ({
|
|
103
|
+
expiresAt,
|
|
104
|
+
}: DeploymentProps) {
|
|
105
|
+
if (expiresAt != null && !Number.isSafeInteger(expiresAt))
|
|
106
|
+
return yield* InvalidDeploymentExpiry.make({
|
|
107
|
+
requested: String(expiresAt),
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
76
111
|
export const provider = Effect.gen(function* () {
|
|
77
112
|
const client = yield* ConvexClient;
|
|
78
113
|
const attributes = Effect.fn("Deployment.attributes")(function* (
|
|
@@ -89,6 +124,8 @@ export const provider = Effect.gen(function* () {
|
|
|
89
124
|
type: deployment.deploymentType,
|
|
90
125
|
url: deployment.deploymentUrl,
|
|
91
126
|
region: deployment.region,
|
|
127
|
+
class: deployment.class,
|
|
128
|
+
expiresAt: deployment.expiresAt ?? null,
|
|
92
129
|
} satisfies DeploymentAttributes;
|
|
93
130
|
});
|
|
94
131
|
const find = Effect.fn("Deployment.find")(function* (
|
|
@@ -121,7 +158,10 @@ export const provider = Effect.gen(function* () {
|
|
|
121
158
|
});
|
|
122
159
|
return {
|
|
123
160
|
diff: Effect.fn("Deployment.diff")(function* ({ news, output }) {
|
|
124
|
-
if (!isResolved(news)
|
|
161
|
+
if (!isResolved(news)) return;
|
|
162
|
+
yield* validateExpiry(news);
|
|
163
|
+
if (output === undefined) return;
|
|
164
|
+
const expiresAt = news.expiresAt;
|
|
125
165
|
yield* validate(output, news);
|
|
126
166
|
const deployment = yield* client
|
|
127
167
|
.getDeployment(output.name)
|
|
@@ -129,7 +169,11 @@ export const provider = Effect.gen(function* () {
|
|
|
129
169
|
if (deployment === undefined) return { action: "update" };
|
|
130
170
|
const current = yield* attributes(deployment);
|
|
131
171
|
yield* validate(current, news);
|
|
132
|
-
if (
|
|
172
|
+
if (
|
|
173
|
+
(news.reference ?? output.reference) !== current.reference ||
|
|
174
|
+
(news.class !== undefined && news.class !== current.class) ||
|
|
175
|
+
(expiresAt !== undefined && expiresAt !== (current.expiresAt ?? null))
|
|
176
|
+
)
|
|
133
177
|
return { action: "update" };
|
|
134
178
|
}),
|
|
135
179
|
read: Effect.fn("Deployment.read")(function* ({
|
|
@@ -161,6 +205,7 @@ export const provider = Effect.gen(function* () {
|
|
|
161
205
|
news,
|
|
162
206
|
output,
|
|
163
207
|
}) {
|
|
208
|
+
yield* validateExpiry(news);
|
|
164
209
|
if (output === undefined) yield* checkpointCreate(fqn, instanceId, news);
|
|
165
210
|
if (output !== undefined) yield* validate(output, news);
|
|
166
211
|
let deployment =
|
|
@@ -173,6 +218,7 @@ export const provider = Effect.gen(function* () {
|
|
|
173
218
|
news.reference ??
|
|
174
219
|
output?.reference ??
|
|
175
220
|
(yield* resourceName("deployment", fqn, instanceId));
|
|
221
|
+
const expiresAt = news.expiresAt;
|
|
176
222
|
if (deployment === undefined) {
|
|
177
223
|
const existing = yield* find(news.projectId, reference);
|
|
178
224
|
if (existing !== undefined && !(yield* shouldAdopt(fqn)))
|
|
@@ -191,21 +237,36 @@ export const provider = Effect.gen(function* () {
|
|
|
191
237
|
type: news.type,
|
|
192
238
|
reference,
|
|
193
239
|
...(news.region === undefined ? {} : { region: news.region }),
|
|
240
|
+
...(news.class === undefined ? {} : { class: news.class }),
|
|
241
|
+
...(expiresAt === undefined ? {} : { expiresAt }),
|
|
194
242
|
});
|
|
195
243
|
}
|
|
196
244
|
}
|
|
197
245
|
const current = yield* attributes(deployment);
|
|
198
246
|
yield* validate(current, news);
|
|
199
|
-
if (
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
247
|
+
if (
|
|
248
|
+
current.reference !== reference ||
|
|
249
|
+
(news.class !== undefined && news.class !== current.class) ||
|
|
250
|
+
(expiresAt !== undefined && expiresAt !== (current.expiresAt ?? null))
|
|
251
|
+
) {
|
|
252
|
+
if (current.reference !== reference) {
|
|
253
|
+
const existing = yield* find(news.projectId, reference);
|
|
254
|
+
if (existing !== undefined && existing.name !== current.name)
|
|
255
|
+
return yield* new OwnedBySomeoneElse({
|
|
256
|
+
message: "The requested deployment reference is already in use.",
|
|
257
|
+
resourceType: Deployment.Type,
|
|
258
|
+
physicalName: reference,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
207
261
|
yield* client.updateDeployment(current.name, {
|
|
208
262
|
reference,
|
|
263
|
+
...(news.class === undefined || news.class === current.class
|
|
264
|
+
? {}
|
|
265
|
+
: { class: news.class }),
|
|
266
|
+
...(expiresAt === undefined ||
|
|
267
|
+
expiresAt === (current.expiresAt ?? null)
|
|
268
|
+
? {}
|
|
269
|
+
: { expiresAt }),
|
|
209
270
|
});
|
|
210
271
|
deployment = yield* client.getDeployment(current.name);
|
|
211
272
|
}
|
|
@@ -221,7 +282,7 @@ export const provider = Effect.gen(function* () {
|
|
|
221
282
|
|
|
222
283
|
interface LocalConfig {
|
|
223
284
|
readonly name: string;
|
|
224
|
-
readonly props: DeploymentProps
|
|
285
|
+
readonly props: Omit<DeploymentProps, "class" | "expiresAt">;
|
|
225
286
|
}
|
|
226
287
|
|
|
227
288
|
/**
|
|
@@ -248,9 +309,10 @@ export const localLayer = LocalProvider.make(
|
|
|
248
309
|
instanceId,
|
|
249
310
|
news,
|
|
250
311
|
}) {
|
|
312
|
+
const { class: _class, expiresAt: _expiresAt, ...props } = news;
|
|
251
313
|
return {
|
|
252
314
|
name: yield* resourceName("deployment", fqn, instanceId),
|
|
253
|
-
props
|
|
315
|
+
props,
|
|
254
316
|
} satisfies LocalConfig;
|
|
255
317
|
}),
|
|
256
318
|
start: Effect.fn("Deployment.localStart")(function* ({
|