@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 673 lines 22.8 KB
Raw
1 import * as certificatemanager from "@distilled.cloud/gcp/certificatemanager_v1";
2 import { Unowned } from "alchemy/AdoptPolicy";
3 import { isResolved } from "alchemy/Diff";
4 import { createPhysicalName } from "alchemy/PhysicalName";
5 import * as Provider from "alchemy/Provider";
6 import { Resource } from "alchemy/Resource";
7 import { tagRecord } from "alchemy/Tags";
8 import * as Data from "effect/Data";
9 import * as Effect from "effect/Effect";
10 import * as Schedule from "effect/Schedule";
11 import * as Stream from "effect/Stream";
12 import { GcpEnvironment } from "../Environment.ts";
13 import {
14 createInternalLabels,
15 diffLabels,
16 hasAlchemyLabels,
17 stripInternalLabels,
18 toLabels,
19 } from "../Labels.ts";
20 import type { Providers } from "../Providers.ts";
21 import { waitForOperation } from "./operations.ts";
22
23 const DEFAULT_LOCATION = "global";
24 const MAX_NAME_LENGTH = 63;
25
26 export type CertificateMapEntryMatcher = "PRIMARY" | (string & {});
27
28 export type CertificateMapEntryProps = {
29 /**
30 * Parent certificate map. Full name
31 * `projects/{project}/locations/{location}/certificateMaps/{certificateMap}`
32 * or the map id (combined with `location`). Immutable — changing it
33 * replaces the entry.
34 */
35 certificateMap: string;
36 /**
37 * Certificate map entry id (the `{certificateMapEntry}` segment of
38 * `.../certificateMaps/{certificateMap}/certificateMapEntries/{certificateMapEntry}`).
39 * If omitted, a unique name is generated from the stack, stage, and
40 * logical id. Must be 1-63 characters, start with a letter, and match
41 * `[a-zA-Z][a-zA-Z0-9_-]*`. Immutable — changing it replaces the entry.
42 */
43 certificateMapEntryId?: string;
44 /**
45 * Certificate Manager location. Used when `certificateMap` is a bare
46 * id. Certificate maps are global resources; omit or set `"global"`.
47 * Immutable — changing it replaces the entry. `GLOBAL` is accepted and
48 * normalized to `global`.
49 * @default "global"
50 */
51 location?: string;
52 /**
53 * Human-readable description.
54 */
55 description?: string;
56 /**
57 * User labels. Alchemy ownership labels are merged in automatically.
58 */
59 labels?: Record<string, string>;
60 /**
61 * Certificate resource names served for this hostname (or PRIMARY
62 * matcher). Up to four certificates, each
63 * `projects/{project}/locations/{location}/certificates/{certificate}`.
64 * Bare certificate ids are qualified with the entry's project and
65 * location. Mutable.
66 */
67 certificates?: string[];
68 /**
69 * Hostname (FQDN, e.g. `www.example.com`) or wildcard (`*.example.com`)
70 * used as SNI. Mutually exclusive with `matcher`. Immutable — changing
71 * it replaces the entry.
72 */
73 hostname?: string;
74 /**
75 * Predefined matcher when this entry is not selected by SNI. `PRIMARY`
76 * is served when the client omits SNI or the hostname is not in the
77 * map. Mutually exclusive with `hostname`. Immutable — changing it
78 * replaces the entry. If both are set, `hostname` is used.
79 */
80 matcher?: CertificateMapEntryMatcher;
81 };
82
83 export type CertificateMapEntry = Resource<
84 "GCP.CertificateManager.CertificateMapEntry",
85 CertificateMapEntryProps,
86 {
87 /** Full resource name `projects/{project}/locations/{location}/certificateMaps/{certificateMap}/certificateMapEntries/{certificateMapEntry}`. */
88 name: string;
89 /** Certificate map entry id (last path segment). */
90 certificateMapEntryId: string;
91 /** Parent certificate map resource name. */
92 certificateMap: string;
93 /** Parent certificate map id. */
94 certificateMapId: string;
95 /** Project id. */
96 project: string;
97 /** Location id (`global`). */
98 location: string;
99 /** User-provided description. */
100 description: string | undefined;
101 /** User labels (Alchemy ownership labels stripped). */
102 labels: Record<string, string>;
103 /** Certificate resource names attached to this entry. */
104 certificates: string[];
105 /** SNI hostname, if this is a hostname entry. */
106 hostname: string | undefined;
107 /** Predefined matcher (`PRIMARY`), if this is not a hostname entry. */
108 matcher: string | undefined;
109 /** Serving state (`ACTIVE`, `PENDING`). */
110 state: string | undefined;
111 /** RFC3339 creation timestamp. */
112 createTime: string | undefined;
113 /** RFC3339 last-update timestamp. */
114 updateTime: string | undefined;
115 },
116 never,
117 Providers
118 >;
119
120 /**
121 * A Certificate Manager certificate map entry — binds one or more
122 * certificates to an SNI hostname (or the PRIMARY fallback) inside a
123 * certificate map.
124 *
125 * Changing `certificateMapEntryId`, `certificateMap`, `location`,
126 * `hostname`, or `matcher` replaces the resource. Description, labels,
127 * and `certificates` update in place. Hostname and matcher are mutually
128 * exclusive; if both are set, hostname is used.
129 *
130 * ### Creating a Hostname Entry
131 * **Example:** SNI hostname
132 * ```typescript
133 * const cert = yield* GCP.CertificateManager.Certificate("FrontendTls", {
134 * pemCertificate,
135 * pemPrivateKey,
136 * });
137 * const map = yield* GCP.CertificateManager.CertificateMap("FrontendMap", {});
138 * const entry = yield* GCP.CertificateManager.CertificateMapEntry("Www", {
139 * certificateMap: map.name,
140 * certificates: [cert.name],
141 * hostname: "www.example.com",
142 * });
143 * ```
144 *
145 * **Example:** Named entry with labels
146 * ```typescript
147 * const entry = yield* GCP.CertificateManager.CertificateMapEntry("Www", {
148 * certificateMap: map.name,
149 * certificateMapEntryId: "app-www",
150 * description: "prod www",
151 * labels: { env: "prod" },
152 * certificates: [cert.name],
153 * hostname: "www.example.com",
154 * });
155 * ```
156 *
157 * ### Primary Fallback
158 * **Example:** PRIMARY matcher
159 * ```typescript
160 * const fallback = yield* GCP.CertificateManager.CertificateMapEntry("Default", {
161 * certificateMap: map.name,
162 * certificates: [cert.name],
163 * matcher: "PRIMARY",
164 * });
165 * ```
166 *
167 * ### Updating Certificates
168 * **Example:** Attach an extra certificate
169 * ```typescript
170 * const entry = yield* GCP.CertificateManager.CertificateMapEntry("Www", {
171 * certificateMap: map.name,
172 * certificates: [cert.name, extra.name],
173 * hostname: "www.example.com",
174 * });
175 * ```
176 *
177 * @resource
178 * @category CertificateManager
179 */
180 export const CertificateMapEntry = Resource<CertificateMapEntry>(
181 "GCP.CertificateManager.CertificateMapEntry",
182 );
183
184 export class CertificateMapEntryNotResolved extends Data.TaggedError(
185 "GCP.CertificateManager.CertificateMapEntryNotResolved",
186 )<{
187 resourceName: string;
188 }> {}
189
190 export class CertificateMapEntryStillExists extends Data.TaggedError(
191 "GCP.CertificateManager.CertificateMapEntryStillExists",
192 )<{
193 resourceName: string;
194 }> {}
195
196 type Match = { kind: "hostname"; hostname: string } | { kind: "matcher"; matcher: string };
197
198 const lastSegment = (value: string) => {
199 const trimmed = value.replace(/\/+$/, "");
200 const parts = trimmed.split("/");
201 return parts[parts.length - 1] || trimmed;
202 };
203
204 const rfc1035 = (name: string): string => {
205 let next = name
206 .toLowerCase()
207 .replace(/[^a-z0-9-]/g, "-")
208 .replace(/-+/g, "-")
209 .replace(/^-+/, "")
210 .replace(/-+$/, "");
211 if (!/^[a-z]/.test(next)) {
212 next = `c${next}`;
213 }
214 next = next.slice(0, MAX_NAME_LENGTH).replace(/-+$/, "");
215 return next.length > 0 ? next : "certificatemapentry";
216 };
217
218 const normalizeLocation = (location: string | undefined) =>
219 lastSegment(location ?? DEFAULT_LOCATION).toLowerCase();
220
221 const normalizeMatcher = (matcher: string | undefined) => {
222 const value = (matcher ?? "").toUpperCase();
223 if (value === "" || value === "MATCHER_UNSPECIFIED") return undefined;
224 return value;
225 };
226
227 const matchOf = (
228 props: { hostname?: string; matcher?: string },
229 fallback?: Match,
230 ): Match | undefined => {
231 if (props.hostname !== undefined && props.hostname !== "") {
232 return { kind: "hostname", hostname: props.hostname };
233 }
234 const matcher = normalizeMatcher(props.matcher);
235 if (matcher !== undefined) {
236 return { kind: "matcher", matcher };
237 }
238 return fallback;
239 };
240
241 const parseName = (name: string) => {
242 const parts = name.split("/").filter((part) => part.length > 0);
243 const entriesAt = parts.lastIndexOf("certificateMapEntries");
244 const mapsAt = parts.lastIndexOf("certificateMaps");
245 const locationsAt = parts.lastIndexOf("locations");
246 const projectsAt = parts.lastIndexOf("projects");
247 const certificateMap = mapsAt >= 0 ? parts.slice(0, mapsAt + 2).join("/") : "";
248 return {
249 project: projectsAt >= 0 && parts[projectsAt + 1] ? parts[projectsAt + 1]! : "",
250 location:
251 locationsAt >= 0 && parts[locationsAt + 1] ? parts[locationsAt + 1]! : DEFAULT_LOCATION,
252 certificateMap,
253 certificateMapId: mapsAt >= 0 && parts[mapsAt + 1] ? parts[mapsAt + 1]! : "",
254 certificateMapEntryId:
255 entriesAt >= 0 && parts[entriesAt + 1] ? parts[entriesAt + 1]! : lastSegment(name),
256 };
257 };
258
259 const resolveParent = (project: string, certificateMap: string, location: string | undefined) => {
260 if (certificateMap.includes("/")) {
261 const parsed = parseName(
262 certificateMap.includes("/certificateMapEntries/")
263 ? certificateMap
264 : `${certificateMap.replace(/\/+$/, "")}/certificateMapEntries/_`,
265 );
266 return {
267 parent: parsed.certificateMap,
268 location: parsed.location,
269 project: parsed.project || project,
270 certificateMapId: parsed.certificateMapId,
271 };
272 }
273 const loc = normalizeLocation(location);
274 return {
275 parent: `projects/${project}/locations/${loc}/certificateMaps/${certificateMap}`,
276 location: loc,
277 project,
278 certificateMapId: certificateMap,
279 };
280 };
281
282 const parentKey = (certificateMap: string | undefined, location: string | undefined) => {
283 if (certificateMap === undefined || certificateMap === "") return undefined;
284 const parsed = resolveParent("", certificateMap, location);
285 return `${parsed.location}/${parsed.certificateMapId}`;
286 };
287
288 const resourceName = (parent: string, certificateMapEntryId: string) =>
289 `${parent}/certificateMapEntries/${certificateMapEntryId}`;
290
291 const userLabels = (
292 labels: Record<string, string | undefined> | null | undefined,
293 ): Record<string, string> => stripInternalLabels(tagRecord(labels));
294
295 const toId = (id: string, certificateMapEntryId: string | undefined, existing?: string) =>
296 Effect.gen(function* () {
297 if (certificateMapEntryId !== undefined) return certificateMapEntryId;
298 if (existing !== undefined) return existing;
299 return rfc1035(
300 yield* createPhysicalName({
301 id,
302 maxLength: MAX_NAME_LENGTH,
303 lowercase: true,
304 }),
305 );
306 });
307
308 const normalizeCertificateName = (value: string, project: string, location: string) => {
309 if (value.includes("/certificates/")) {
310 const parts = value.split("/").filter((part) => part.length > 0);
311 const certificatesAt = parts.lastIndexOf("certificates");
312 const locationsAt = parts.lastIndexOf("locations");
313 const loc = locationsAt >= 0 && parts[locationsAt + 1] ? parts[locationsAt + 1]! : location;
314 const certificateId =
315 certificatesAt >= 0 && parts[certificatesAt + 1]
316 ? parts[certificatesAt + 1]!
317 : lastSegment(value);
318 return `projects/${project}/locations/${loc}/certificates/${certificateId}`;
319 }
320 return `projects/${project}/locations/${location}/certificates/${lastSegment(value)}`;
321 };
322
323 const normalizeCertificates = (
324 values: readonly string[] | undefined,
325 project: string,
326 location: string,
327 ) => (values ?? []).map((value) => normalizeCertificateName(value, project, location));
328
329 const sameCertificates = (
330 left: readonly string[] | undefined,
331 right: readonly string[] | undefined,
332 project: string,
333 location: string,
334 ) =>
335 [...normalizeCertificates(left, project, location)].sort().join("\0") ===
336 [...normalizeCertificates(right, project, location)].sort().join("\0");
337
338 const toAttrs = (entry: certificatemanager.CertificateMapEntry, project: string) => {
339 const name = entry.name ?? "";
340 const parsed = parseName(name);
341 const matcher = normalizeMatcher(entry.matcher);
342 return {
343 name,
344 certificateMapEntryId: parsed.certificateMapEntryId,
345 certificateMap: parsed.certificateMap,
346 certificateMapId: parsed.certificateMapId,
347 project: parsed.project || project,
348 location: parsed.location,
349 description: entry.description,
350 labels: userLabels(entry.labels),
351 certificates: normalizeCertificates(entry.certificates, project, parsed.location),
352 hostname: entry.hostname !== undefined && entry.hostname !== "" ? entry.hostname : undefined,
353 matcher,
354 state: entry.state,
355 createTime: entry.createTime,
356 updateTime: entry.updateTime,
357 };
358 };
359
360 const isUsableEntryName = (name: string) =>
361 /\/certificateMaps\/[^/]+\/certificateMapEntries\/[^/]+$/.test(name);
362
363 const getByName = (name: string) => {
364 if (!isUsableEntryName(name)) {
365 return Effect.undefined;
366 }
367 return certificatemanager
368 .getProjectsLocationsCertificateMapsCertificateMapEntries({ name })
369 .pipe(Effect.catchTag("NotFound", () => Effect.undefined));
370 };
371
372 const waitUntilExists = (name: string) =>
373 getByName(name).pipe(
374 Effect.flatMap((entry) =>
375 entry
376 ? Effect.succeed(entry)
377 : Effect.fail(new CertificateMapEntryNotResolved({ resourceName: name })),
378 ),
379 Effect.retry({
380 while: (error) => error._tag === "GCP.CertificateManager.CertificateMapEntryNotResolved",
381 times: 8,
382 schedule: Schedule.spaced("1 second"),
383 }),
384 );
385
386 const waitUntilGone = (name: string) =>
387 getByName(name).pipe(
388 Effect.flatMap((entry) =>
389 entry === undefined
390 ? Effect.void
391 : Effect.fail(new CertificateMapEntryStillExists({ resourceName: name })),
392 ),
393 Effect.retry({
394 while: (error) => error._tag === "GCP.CertificateManager.CertificateMapEntryStillExists",
395 times: 10,
396 schedule: Schedule.spaced("1 second"),
397 }),
398 );
399
400 const listEntriesAt = (parent: string, project: string) =>
401 certificatemanager.listProjectsLocationsCertificateMapsCertificateMapEntries
402 .pages({
403 parent,
404 pageSize: 1000,
405 })
406 .pipe(
407 Stream.flatMap((page) => Stream.fromIterable(page.certificateMapEntries ?? [])),
408 Stream.filter((entry) =>
409 Object.keys(entry.labels ?? {}).some((key) => key.startsWith("alchemy-")),
410 ),
411 Stream.map((entry) => toAttrs(entry, project)),
412 Stream.runCollect,
413 Effect.map((chunk) => Array.from(chunk)),
414 Effect.catchTag("NotFound", () => Effect.succeed([])),
415 );
416
417 const listOwnedEntries = (project: string) =>
418 Effect.gen(function* () {
419 const maps = yield* certificatemanager.listProjectsLocationsCertificateMaps
420 .pages({
421 parent: `projects/${project}/locations/-`,
422 pageSize: 1000,
423 })
424 .pipe(
425 Stream.flatMap((page) => Stream.fromIterable(page.certificateMaps ?? [])),
426 Stream.runCollect,
427 Effect.map((chunk) => Array.from(chunk)),
428 Effect.catchTag("NotFound", () =>
429 Effect.succeed([] as certificatemanager.CertificateMap[]),
430 ),
431 );
432
433 const pages = yield* Effect.forEach(
434 maps,
435 (map) =>
436 map.name
437 ? listEntriesAt(map.name, project)
438 : Effect.succeed([] as ReturnType<typeof toAttrs>[]),
439 { concurrency: 4 },
440 );
441 return pages.flat();
442 });
443
444 const toCreateBody = (
445 news: CertificateMapEntryProps,
446 match: Match | undefined,
447 certificates: string[],
448 desiredLabels: Record<string, string>,
449 ): certificatemanager.CertificateMapEntry => {
450 const body: certificatemanager.CertificateMapEntry = {
451 description: news.description,
452 labels: desiredLabels,
453 certificates,
454 };
455 if (match?.kind === "hostname") {
456 body.hostname = match.hostname;
457 } else if (match?.kind === "matcher") {
458 body.matcher = match.matcher;
459 }
460 return body;
461 };
462
463 const matchChanged = (
464 news: CertificateMapEntryProps,
465 olds: Partial<CertificateMapEntryProps> | undefined,
466 output: CertificateMapEntry["Attributes"] | undefined,
467 ) => {
468 const previous = matchOf({
469 hostname: olds?.hostname ?? output?.hostname,
470 matcher: olds?.matcher ?? output?.matcher,
471 });
472 const next = matchOf(news, previous);
473 if (previous === undefined || next === undefined) return false;
474 if (previous.kind !== next.kind) return true;
475 if (
476 previous.kind === "hostname" &&
477 next.kind === "hostname" &&
478 previous.hostname !== next.hostname
479 ) {
480 return true;
481 }
482 if (previous.kind === "matcher" && next.kind === "matcher" && previous.matcher !== next.matcher) {
483 return true;
484 }
485 return false;
486 };
487
488 export const CertificateMapEntryProvider = () =>
489 Provider.succeed(CertificateMapEntry, {
490 stables: [
491 "name",
492 "certificateMapEntryId",
493 "certificateMap",
494 "certificateMapId",
495 "project",
496 "location",
497 "hostname",
498 "matcher",
499 "createTime",
500 ],
501
502 diff: Effect.fn(function* ({ news, olds, output }) {
503 if (!isResolved(news)) return undefined;
504
505 const previousId = olds?.certificateMapEntryId ?? output?.certificateMapEntryId;
506 const nextId = news.certificateMapEntryId ?? previousId;
507 const previousLocation = normalizeLocation(olds?.location ?? output?.location);
508 const nextLocation = normalizeLocation(news.location ?? olds?.location ?? output?.location);
509 const previousParent = parentKey(
510 olds?.certificateMap ?? output?.certificateMap,
511 olds?.location ?? output?.location,
512 );
513 const nextParent =
514 news.certificateMap !== undefined
515 ? parentKey(news.certificateMap, news.location ?? olds?.location ?? output?.location)
516 : previousParent;
517
518 const replace =
519 (previousId !== undefined && nextId !== undefined && nextId !== previousId) ||
520 previousLocation !== nextLocation ||
521 (previousParent !== undefined &&
522 nextParent !== undefined &&
523 previousParent !== nextParent) ||
524 matchChanged(news, olds, output);
525
526 if (!replace) return undefined;
527 return {
528 action: "replace" as const,
529 deleteFirst:
530 previousParent === nextParent &&
531 previousLocation === nextLocation &&
532 previousId !== undefined &&
533 nextId === previousId,
534 };
535 }),
536
537 read: Effect.fn(function* ({ id, olds, output }) {
538 const env = yield* GcpEnvironment.current;
539 const mapRef = olds?.certificateMap ?? output?.certificateMap;
540 let name = output?.name;
541 if (name === undefined || name.length === 0) {
542 // Interrupted creates persist parent Outputs as holes (`{}` / "").
543 // Don't call GET with `.../certificateMaps//certificateMapEntries/...`.
544 if (typeof mapRef !== "string" || mapRef.length === 0) {
545 return undefined;
546 }
547 const certificateMapEntryId = yield* toId(
548 id,
549 olds?.certificateMapEntryId,
550 output?.certificateMapEntryId,
551 );
552 const parent = resolveParent(env.project, mapRef, olds?.location ?? output?.location);
553 name = resourceName(parent.parent, certificateMapEntryId);
554 }
555 const existing = yield* getByName(name);
556 if (existing === undefined) return undefined;
557 const attrs = toAttrs(existing, env.project);
558 return (yield* hasAlchemyLabels(id, tagRecord(existing.labels))) ? attrs : Unowned(attrs);
559 }),
560
561 list: () =>
562 Effect.gen(function* () {
563 const env = yield* GcpEnvironment.current;
564 return yield* listOwnedEntries(env.project);
565 }),
566
567 reconcile: Effect.fn(function* ({ id, news, output }) {
568 const env = yield* GcpEnvironment.current;
569 const certificateMapEntryId = yield* toId(
570 id,
571 news.certificateMapEntryId,
572 output?.certificateMapEntryId,
573 );
574 const parent = resolveParent(
575 env.project,
576 news.certificateMap ?? output?.certificateMap ?? "",
577 news.location ?? output?.location,
578 );
579 const name = resourceName(parent.parent, certificateMapEntryId);
580 const desiredLabels = {
581 ...toLabels(news.labels),
582 ...(yield* createInternalLabels(id)),
583 };
584 const match = matchOf(news, matchOf(output ?? {}));
585 const certificates = normalizeCertificates(
586 news.certificates,
587 parent.project,
588 parent.location,
589 );
590
591 let current = yield* getByName(name);
592
593 if (current === undefined) {
594 const created = yield* certificatemanager
595 .createProjectsLocationsCertificateMapsCertificateMapEntries({
596 parent: parent.parent,
597 certificateMapEntryId,
598 body: toCreateBody(news, match, certificates, desiredLabels),
599 })
600 .pipe(
601 Effect.retry({
602 while: (error) => error._tag === "Conflict" || error._tag === "NotFound",
603 times: 5,
604 schedule: Schedule.spaced("2 seconds"),
605 }),
606 Effect.catchTag("Conflict", () => Effect.undefined),
607 );
608 if (created !== undefined) {
609 yield* waitForOperation(created);
610 }
611 current = yield* waitUntilExists(name);
612 }
613
614 if (current === undefined) {
615 return yield* new CertificateMapEntryNotResolved({ resourceName: name });
616 }
617
618 const observedLabels = tagRecord(current.labels);
619 const { upsert, removed } = diffLabels(observedLabels, desiredLabels);
620 const labelsChanged = upsert.length > 0 || removed.length > 0;
621 const descriptionChanged = (current.description ?? "") !== (news.description ?? "");
622 const certificatesChanged =
623 news.certificates !== undefined &&
624 !sameCertificates(current.certificates, certificates, parent.project, parent.location);
625
626 if (labelsChanged || descriptionChanged || certificatesChanged) {
627 const updateMask = [
628 labelsChanged ? "labels" : undefined,
629 descriptionChanged ? "description" : undefined,
630 certificatesChanged ? "certificates" : undefined,
631 ].filter((field): field is string => field !== undefined);
632
633 const operation =
634 yield* certificatemanager.patchProjectsLocationsCertificateMapsCertificateMapEntries({
635 name,
636 updateMask: updateMask.join(","),
637 body: {
638 name,
639 labels: desiredLabels,
640 description: news.description,
641 certificates,
642 },
643 });
644 yield* waitForOperation(operation);
645 current = yield* waitUntilExists(name);
646 }
647
648 return toAttrs(current, env.project);
649 }),
650
651 delete: Effect.fn(function* ({ output }) {
652 const name = output.name;
653 if (name === undefined || name.length === 0 || !isUsableEntryName(name)) {
654 return;
655 }
656 const operation = yield* certificatemanager
657 .deleteProjectsLocationsCertificateMapsCertificateMapEntries({
658 name,
659 })
660 .pipe(
661 Effect.retry({
662 while: (error) => error._tag === "Conflict",
663 times: 8,
664 schedule: Schedule.spaced("2 seconds"),
665 }),
666 Effect.catchTag("NotFound", () => Effect.undefined),
667 );
668 if (operation !== undefined) {
669 yield* waitForOperation(operation, { notFoundOk: true });
670 }
671 yield* waitUntilGone(name);
672 }),
673 });