@gaganref/confect-alchemy 10.6.0-fork.25 → 10.6.0-fork.27
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/Convex.d.ts +1 -0
- package/dist/Convex.d.ts.map +1 -1
- package/dist/Convex.js +3 -1
- package/dist/Convex.js.map +1 -1
- package/dist/ConvexClient.d.ts +27 -0
- package/dist/ConvexClient.d.ts.map +1 -1
- package/dist/ConvexClient.js +27 -0
- 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/Providers.d.ts.map +1 -1
- package/dist/Providers.js +25 -20
- package/dist/Providers.js.map +1 -1
- package/dist/internal/Lifecycle.d.ts +1 -0
- package/dist/internal/Lifecycle.d.ts.map +1 -1
- package/dist/internal/Lifecycle.js +23 -1
- package/dist/internal/Lifecycle.js.map +1 -1
- package/package.json +3 -3
- package/src/Convex.ts +6 -0
- package/src/ConvexClient.ts +73 -0
- package/src/CustomDomain.ts +453 -0
- package/src/Providers.ts +6 -0
- package/src/internal/Lifecycle.ts +20 -0
|
@@ -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/Providers.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type * as Redacted from "effect/Redacted";
|
|
|
4
4
|
import * as Layer from "effect/Layer";
|
|
5
5
|
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
6
6
|
import * as Code from "./Code.js";
|
|
7
|
+
import * as CustomDomain from "./CustomDomain.js";
|
|
7
8
|
import * as ConvexClient from "./ConvexClient.js";
|
|
8
9
|
import * as Deployment from "./Deployment.js";
|
|
9
10
|
import * as DeployKey from "./DeployKey.js";
|
|
@@ -37,6 +38,7 @@ export const providers = (options?: {
|
|
|
37
38
|
DeployKey.DeployKey,
|
|
38
39
|
EnvironmentVariables.EnvironmentVariables,
|
|
39
40
|
Code.Code,
|
|
41
|
+
CustomDomain.CustomDomain,
|
|
40
42
|
LogStream.LogStream,
|
|
41
43
|
UsageLimit.UsageLimit,
|
|
42
44
|
]),
|
|
@@ -59,6 +61,10 @@ export const providers = (options?: {
|
|
|
59
61
|
live: () => EnvironmentVariables.layer,
|
|
60
62
|
local: () => EnvironmentVariables.localLayer,
|
|
61
63
|
}),
|
|
64
|
+
ProviderLayer.dual(CustomDomain.CustomDomain, {
|
|
65
|
+
live: () => CustomDomain.layer,
|
|
66
|
+
local: () => CustomDomain.localLayer,
|
|
67
|
+
}),
|
|
62
68
|
ProviderLayer.dual(UsageLimit.UsageLimit, {
|
|
63
69
|
live: () => UsageLimit.layer,
|
|
64
70
|
local: () => UsageLimit.localLayer,
|
|
@@ -38,6 +38,26 @@ export const checkpointCreate = Effect.fn("Lifecycle.checkpointCreate")(
|
|
|
38
38
|
},
|
|
39
39
|
);
|
|
40
40
|
|
|
41
|
+
export const checkpointUpdate = Effect.fn("Lifecycle.checkpointUpdate")(
|
|
42
|
+
function* (fqn: string, instanceId: string, output: object) {
|
|
43
|
+
const stack = yield* Effect.serviceOption(Stack);
|
|
44
|
+
if (Option.isNone(stack)) return;
|
|
45
|
+
const state = yield* Effect.serviceOption(State);
|
|
46
|
+
if (Option.isNone(state)) return yield* LifecycleStateError.make({ fqn });
|
|
47
|
+
const store = yield* state.value;
|
|
48
|
+
const key = { stack: stack.value.name, stage: stack.value.stage, fqn };
|
|
49
|
+
const row = yield* store.get(key);
|
|
50
|
+
if (
|
|
51
|
+
row === undefined ||
|
|
52
|
+
row.kind === "action" ||
|
|
53
|
+
row.instanceId !== instanceId
|
|
54
|
+
)
|
|
55
|
+
return yield* LifecycleStateError.make({ fqn });
|
|
56
|
+
if (row.status !== "updating") return;
|
|
57
|
+
yield* store.set({ ...key, value: { ...row, attr: output } });
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
|
|
41
61
|
export const shouldAdopt = Effect.fn("Lifecycle.shouldAdopt")(function* (
|
|
42
62
|
fqn: string,
|
|
43
63
|
) {
|