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

main
ts 710 lines 22.4 KB
Raw
1 import * as networkservices from "@distilled.cloud/gcp/networkservices_v1";
2 import { Unowned } from "alchemy/AdoptPolicy";
3 import { isResolved } from "alchemy/Diff";
4 import * as Provider from "alchemy/Provider";
5 import { Resource } from "alchemy/Resource";
6 import { tagRecord } from "alchemy/Tags";
7 import * as Effect from "effect/Effect";
8 import * as Schedule from "effect/Schedule";
9 import { GcpEnvironment } from "../Environment.ts";
10 import { createInternalLabels, diffLabels, hasAlchemyLabels, toLabels } from "../Labels.ts";
11 import type { Providers } from "../Providers.ts";
12 import type {
13 GrpcRouteFaultInjectionPolicy,
14 GrpcRouteStatefulSessionAffinityPolicy,
15 } from "./GrpcRoute.ts";
16 import {
17 DEFAULT_GLOBAL,
18 changedFields,
19 collectPages,
20 hasAlchemyLabelKeys,
21 normalizeLocation,
22 parentOf,
23 parseName,
24 resourceName,
25 rfc1035,
26 sameJson,
27 sameStringList,
28 toPhysicalId,
29 userLabels,
30 waitForOperation,
31 waitUntilGone,
32 waitUntilPresent,
33 } from "./internal.ts";
34
35 const COLLECTION = "httpRoutes";
36
37 export type HttpRouteHeaderMatchIntegerRange = {
38 /** Inclusive start of the range. */
39 start?: number;
40 /** Exclusive end of the range. */
41 end?: number;
42 };
43
44 export type HttpRouteHeaderMatch = {
45 /** Exact header value. */
46 exactMatch?: string;
47 /** RE2 regular expression. */
48 regexMatch?: string;
49 /** Prefix of the header value. */
50 prefixMatch?: string;
51 /** Suffix of the header value. */
52 suffixMatch?: string;
53 /** Header is present regardless of value. */
54 presentMatch?: boolean;
55 /** Integer range match. */
56 rangeMatch?: HttpRouteHeaderMatchIntegerRange;
57 /** HTTP header name. */
58 header?: string;
59 /** Invert the match result. */
60 invertMatch?: boolean;
61 };
62
63 export type HttpRouteQueryParameterMatch = {
64 /** Exact query parameter value. */
65 exactMatch?: string;
66 /** RE2 regular expression. */
67 regexMatch?: string;
68 /** Parameter is present regardless of value. */
69 presentMatch?: boolean;
70 /** Query parameter name. */
71 queryParameter?: string;
72 };
73
74 export type HttpRouteRouteMatch = {
75 /** Exact request path. Mutually exclusive with prefix/regex. */
76 fullPathMatch?: string;
77 /** Path prefix. Must start with `/`. */
78 prefixMatch?: string;
79 /** RE2 regular expression against the path. */
80 regexMatch?: string;
81 /** Case-insensitive prefix/full path matching. */
82 ignoreCase?: boolean;
83 /** Header matchers. All must match. */
84 headers?: HttpRouteHeaderMatch[];
85 /** Query parameter matchers. All must match. */
86 queryParameters?: HttpRouteQueryParameterMatch[];
87 };
88
89 export type HttpRouteHeaderModifier = {
90 /** Replace headers by name. */
91 set?: Record<string, string>;
92 /** Append headers by name. */
93 add?: Record<string, string>;
94 /** Header names to remove. */
95 remove?: string[];
96 };
97
98 export type HttpRouteDestination = {
99 /** BackendService URL. */
100 serviceName?: string;
101 /** Traffic weight relative to other destinations. */
102 weight?: number;
103 /** Request header modifiers applied before forwarding. */
104 requestHeaderModifier?: HttpRouteHeaderModifier;
105 /** Response header modifiers applied before returning. */
106 responseHeaderModifier?: HttpRouteHeaderModifier;
107 };
108
109 export type HttpRouteRedirect = {
110 /** Host used in the redirect. */
111 hostRedirect?: string;
112 /** Path used in the redirect. Mutually exclusive with `prefixRewrite`. */
113 pathRedirect?: string;
114 /** Replace the matched prefix with this value. */
115 prefixRewrite?: string;
116 /** HTTP status (`MOVED_PERMANENTLY_DEFAULT`, `FOUND`, …). */
117 responseCode?: string;
118 /** Redirect to HTTPS. */
119 httpsRedirect?: boolean;
120 /** Strip the original query string. */
121 stripQuery?: boolean;
122 /** Port used in the redirect. */
123 portRedirect?: number;
124 };
125
126 export type HttpRouteURLRewrite = {
127 /** Replace the matching path prefix. */
128 pathPrefixRewrite?: string;
129 /** Replace the Host header. */
130 hostRewrite?: string;
131 };
132
133 export type HttpRouteRetryPolicy = {
134 /**
135 * Conditions that trigger a retry (`5xx`, `gateway-error`, `reset`,
136 * `connect-failure`, `retriable-4xx`, `refused-stream`).
137 */
138 retryConditions?: string[];
139 /** Allowed retry count. Defaults to 1. */
140 numRetries?: number;
141 /** Timeout per retry attempt. */
142 perTryTimeout?: string;
143 };
144
145 export type HttpRouteRequestMirrorPolicy = {
146 /** Shadow destination. Weight is ignored. */
147 destination?: HttpRouteDestination;
148 /** Percentage of requests mirrored. */
149 mirrorPercent?: number;
150 };
151
152 export type HttpRouteCorsPolicy = {
153 /** Allowed origins. */
154 allowOrigins?: string[];
155 /** Allowed origin RE2 patterns. */
156 allowOriginRegexes?: string[];
157 /** `Access-Control-Allow-Methods`. */
158 allowMethods?: string[];
159 /** `Access-Control-Allow-Headers`. */
160 allowHeaders?: string[];
161 /** `Access-Control-Expose-Headers`. */
162 exposeHeaders?: string[];
163 /** `Access-Control-Max-Age` in seconds. */
164 maxAge?: string;
165 /** `Access-Control-Allow-Credentials`. */
166 allowCredentials?: boolean;
167 /** Disable the CORS policy. */
168 disabled?: boolean;
169 };
170
171 export type HttpRouteHttpDirectResponse = {
172 /** Response body as a string. Max 1024 characters. */
173 stringBody?: string;
174 /** Response body as bytes. Max 4096B. */
175 bytesBody?: string;
176 /** HTTP status. */
177 status?: number;
178 };
179
180 export type HttpRouteRouteAction = {
181 /** Destinations that receive matched traffic. */
182 destinations?: HttpRouteDestination[];
183 /** Redirect instead of forwarding. */
184 redirect?: HttpRouteRedirect;
185 /** Fault injection. */
186 faultInjectionPolicy?: GrpcRouteFaultInjectionPolicy;
187 /** Request header modifiers. */
188 requestHeaderModifier?: HttpRouteHeaderModifier;
189 /** Response header modifiers. */
190 responseHeaderModifier?: HttpRouteHeaderModifier;
191 /** URL rewrite before forwarding. */
192 urlRewrite?: HttpRouteURLRewrite;
193 /** End-to-end timeout including retries. */
194 timeout?: string;
195 /** Retry policy. */
196 retryPolicy?: HttpRouteRetryPolicy;
197 /** Request mirroring. */
198 requestMirrorPolicy?: HttpRouteRequestMirrorPolicy;
199 /** CORS policy. */
200 corsPolicy?: HttpRouteCorsPolicy;
201 /** Cookie-based session affinity. */
202 statefulSessionAffinity?: GrpcRouteStatefulSessionAffinityPolicy;
203 /** Static HTTP response. */
204 directResponse?: HttpRouteHttpDirectResponse;
205 /** Idle timeout. `0s` disables it. */
206 idleTimeout?: string;
207 };
208
209 export type HttpRouteRouteRule = {
210 /**
211 * Matchers. The rule matches if any matcher matches. Omitted matches
212 * every request.
213 */
214 matches?: HttpRouteRouteMatch[];
215 /** How to route matched traffic. */
216 action?: HttpRouteRouteAction;
217 };
218
219 export type HttpRouteProps = {
220 /**
221 * HttpRoute id (the `{httpRoute}` segment of
222 * `projects/{project}/locations/{location}/httpRoutes/{httpRoute}`).
223 * If omitted, a unique name is generated from the stack, stage, and
224 * logical id. Must be 1-63 characters and not start with a number.
225 * Immutable — changing it replaces the route.
226 */
227 httpRouteId?: string;
228 /**
229 * Location (`global`, `us-central1`, …). Immutable — changing it
230 * replaces the route. `US-CENTRAL1` is accepted and normalized to
231 * `us-central1`.
232 * @default "global"
233 */
234 location?: string;
235 /**
236 * Hostnames this route matches against the HTTP Host header, e.g.
237 * `foo.example.com` or `*.example.com`.
238 */
239 hostnames: string[];
240 /**
241 * Routing rules matched in order. At least one rule is required.
242 */
243 rules: HttpRouteRouteRule[];
244 /**
245 * Mesh resource names this route attaches to. Attached meshes must be
246 * sidecar meshes.
247 */
248 meshes?: string[];
249 /**
250 * Gateway resource names this route attaches to.
251 */
252 gateways?: string[];
253 /**
254 * Human-readable description. Max length 1024 characters.
255 */
256 description?: string;
257 /**
258 * User labels. Alchemy ownership labels are merged in automatically.
259 */
260 labels?: Record<string, string>;
261 };
262
263 export type HttpRoute = Resource<
264 "GCP.NetworkServices.HttpRoute",
265 HttpRouteProps,
266 {
267 /** Full resource name `projects/{project}/locations/{location}/httpRoutes/{httpRoute}`. */
268 name: string;
269 /** HttpRoute id (last path segment). */
270 httpRouteId: string;
271 /** Project id. */
272 project: string;
273 /** Location id (`global`, `us-central1`, …). */
274 location: string;
275 /** Server-defined resource URL. */
276 selfLink: string | undefined;
277 /** Hostnames this route matches. */
278 hostnames: string[];
279 /** Routing rules. */
280 rules: HttpRouteRouteRule[];
281 /** Attached Mesh resource names. */
282 meshes: string[];
283 /** Attached Gateway resource names. */
284 gateways: string[];
285 /** User-provided description. */
286 description: string | undefined;
287 /** User labels (Alchemy ownership labels stripped). */
288 labels: Record<string, string>;
289 /** RFC3339 creation timestamp. */
290 createTime: string | undefined;
291 /** RFC3339 last-update timestamp. */
292 updateTime: string | undefined;
293 },
294 never,
295 Providers
296 >;
297
298 /**
299 * A Network Services HttpRoute — how a Mesh or Gateway routes HTTP
300 * traffic for a set of hostnames.
301 *
302 * Changing `httpRouteId` or `location` replaces the route. Hostnames,
303 * rules, mesh/gateway attachments, description, and labels update in
304 * place.
305 *
306 * ### Creating an HttpRoute
307 * **Example:** Redirect
308 * ```typescript
309 * const route = yield* GCP.NetworkServices.HttpRoute("Web", {
310 * hostnames: ["www.example.com"],
311 * rules: [
312 * {
313 * matches: [{ prefixMatch: "/" }],
314 * action: {
315 * redirect: { hostRedirect: "example.com", httpsRedirect: true },
316 * },
317 * },
318 * ],
319 * });
320 * ```
321 *
322 * **Example:** Direct response
323 * ```typescript
324 * const route = yield* GCP.NetworkServices.HttpRoute("Health", {
325 * httpRouteId: "app-http",
326 * hostnames: ["health.example.com"],
327 * labels: { env: "prod" },
328 * rules: [
329 * {
330 * matches: [{ fullPathMatch: "/healthz" }],
331 * action: { directResponse: { status: 200, stringBody: "ok" } },
332 * },
333 * ],
334 * });
335 * ```
336 *
337 * @resource
338 * @category NetworkServices
339 */
340 export const HttpRoute = Resource<HttpRoute>("GCP.NetworkServices.HttpRoute");
341
342 const toStringMap = (
343 value: Record<string, string | undefined> | undefined,
344 ): Record<string, string> | undefined => {
345 if (value === undefined) return undefined;
346 return Object.fromEntries(
347 Object.entries(value).filter((entry): entry is [string, string] => entry[1] !== undefined),
348 );
349 };
350
351 const toHeaderModifier = (
352 value: HttpRouteHeaderModifier | networkservices.HttpRouteHeaderModifier | undefined,
353 ): HttpRouteHeaderModifier | undefined => {
354 if (value === undefined) return undefined;
355 return {
356 set: toStringMap(value.set),
357 add: toStringMap(value.add),
358 remove: value.remove ?? [],
359 };
360 };
361
362 const toHeaderMatch = (
363 value: HttpRouteHeaderMatch | networkservices.HttpRouteHeaderMatch,
364 ): HttpRouteHeaderMatch => ({
365 exactMatch: value.exactMatch,
366 regexMatch: value.regexMatch,
367 prefixMatch: value.prefixMatch,
368 suffixMatch: value.suffixMatch,
369 presentMatch: value.presentMatch,
370 rangeMatch: value.rangeMatch
371 ? { start: value.rangeMatch.start, end: value.rangeMatch.end }
372 : undefined,
373 header: value.header,
374 invertMatch: value.invertMatch,
375 });
376
377 const toQueryMatch = (
378 value: HttpRouteQueryParameterMatch | networkservices.HttpRouteQueryParameterMatch,
379 ): HttpRouteQueryParameterMatch => ({
380 exactMatch: value.exactMatch,
381 regexMatch: value.regexMatch,
382 presentMatch: value.presentMatch,
383 queryParameter: value.queryParameter,
384 });
385
386 const toMatch = (
387 value: HttpRouteRouteMatch | networkservices.HttpRouteRouteMatch,
388 ): HttpRouteRouteMatch => ({
389 fullPathMatch: value.fullPathMatch,
390 prefixMatch: value.prefixMatch,
391 regexMatch: value.regexMatch,
392 ignoreCase: value.ignoreCase,
393 headers: (value.headers ?? []).map(toHeaderMatch),
394 queryParameters: (value.queryParameters ?? []).map(toQueryMatch),
395 });
396
397 const toDestination = (
398 value: HttpRouteDestination | networkservices.HttpRouteDestination,
399 ): HttpRouteDestination => ({
400 serviceName: value.serviceName,
401 weight: value.weight,
402 requestHeaderModifier: toHeaderModifier(value.requestHeaderModifier),
403 responseHeaderModifier: toHeaderModifier(value.responseHeaderModifier),
404 });
405
406 const toRedirect = (
407 value: HttpRouteRedirect | networkservices.HttpRouteRedirect | undefined,
408 ): HttpRouteRedirect | undefined => {
409 if (value === undefined) return undefined;
410 return {
411 hostRedirect: value.hostRedirect,
412 pathRedirect: value.pathRedirect,
413 prefixRewrite: value.prefixRewrite,
414 responseCode: value.responseCode,
415 httpsRedirect: value.httpsRedirect,
416 stripQuery: value.stripQuery,
417 portRedirect: value.portRedirect,
418 };
419 };
420
421 const toFault = (
422 value: GrpcRouteFaultInjectionPolicy | networkservices.GrpcRouteFaultInjectionPolicy | undefined,
423 ): GrpcRouteFaultInjectionPolicy | undefined => {
424 if (value === undefined) return undefined;
425 return {
426 delay: value.delay
427 ? {
428 fixedDelay: value.delay.fixedDelay,
429 percentage: value.delay.percentage,
430 }
431 : undefined,
432 abort: value.abort
433 ? {
434 httpStatus: value.abort.httpStatus,
435 percentage: value.abort.percentage,
436 }
437 : undefined,
438 };
439 };
440
441 const toRetry = (
442 value: HttpRouteRetryPolicy | networkservices.HttpRouteRetryPolicy | undefined,
443 ): HttpRouteRetryPolicy | undefined => {
444 if (value === undefined) return undefined;
445 return {
446 retryConditions: value.retryConditions ?? [],
447 numRetries: value.numRetries,
448 perTryTimeout: value.perTryTimeout,
449 };
450 };
451
452 const toMirror = (
453 value: HttpRouteRequestMirrorPolicy | networkservices.HttpRouteRequestMirrorPolicy | undefined,
454 ): HttpRouteRequestMirrorPolicy | undefined => {
455 if (value === undefined) return undefined;
456 return {
457 destination: value.destination ? toDestination(value.destination) : undefined,
458 mirrorPercent: value.mirrorPercent,
459 };
460 };
461
462 const toCors = (
463 value: HttpRouteCorsPolicy | networkservices.HttpRouteCorsPolicy | undefined,
464 ): HttpRouteCorsPolicy | undefined => {
465 if (value === undefined) return undefined;
466 return {
467 allowOrigins: value.allowOrigins ?? [],
468 allowOriginRegexes: value.allowOriginRegexes ?? [],
469 allowMethods: value.allowMethods ?? [],
470 allowHeaders: value.allowHeaders ?? [],
471 exposeHeaders: value.exposeHeaders ?? [],
472 maxAge: value.maxAge,
473 allowCredentials: value.allowCredentials,
474 disabled: value.disabled,
475 };
476 };
477
478 const toDirect = (
479 value: HttpRouteHttpDirectResponse | networkservices.HttpRouteHttpDirectResponse | undefined,
480 ): HttpRouteHttpDirectResponse | undefined => {
481 if (value === undefined) return undefined;
482 return {
483 stringBody: value.stringBody,
484 bytesBody: value.bytesBody,
485 status: value.status,
486 };
487 };
488
489 const toAction = (
490 value: HttpRouteRouteAction | networkservices.HttpRouteRouteAction | undefined,
491 ): HttpRouteRouteAction | undefined => {
492 if (value === undefined) return undefined;
493 return {
494 destinations: (value.destinations ?? []).map(toDestination),
495 redirect: toRedirect(value.redirect),
496 faultInjectionPolicy: toFault(value.faultInjectionPolicy),
497 requestHeaderModifier: toHeaderModifier(value.requestHeaderModifier),
498 responseHeaderModifier: toHeaderModifier(value.responseHeaderModifier),
499 urlRewrite: value.urlRewrite
500 ? {
501 pathPrefixRewrite: value.urlRewrite.pathPrefixRewrite,
502 hostRewrite: value.urlRewrite.hostRewrite,
503 }
504 : undefined,
505 timeout: value.timeout,
506 retryPolicy: toRetry(value.retryPolicy),
507 requestMirrorPolicy: toMirror(value.requestMirrorPolicy),
508 corsPolicy: toCors(value.corsPolicy),
509 statefulSessionAffinity: value.statefulSessionAffinity
510 ? { cookieTtl: value.statefulSessionAffinity.cookieTtl }
511 : undefined,
512 directResponse: toDirect(value.directResponse),
513 idleTimeout: value.idleTimeout,
514 };
515 };
516
517 const toRule = (
518 value: HttpRouteRouteRule | networkservices.HttpRouteRouteRule,
519 ): HttpRouteRouteRule => ({
520 matches: (value.matches ?? []).map(toMatch),
521 action: toAction(value.action),
522 });
523
524 const toAttrs = (route: networkservices.HttpRoute, project: string) => {
525 const name = route.name ?? "";
526 const parsed = parseName(name, COLLECTION, DEFAULT_GLOBAL);
527 return {
528 name,
529 httpRouteId: parsed.id,
530 project: parsed.project || project,
531 location: parsed.location || DEFAULT_GLOBAL,
532 selfLink: route.selfLink,
533 hostnames: route.hostnames ?? [],
534 rules: (route.rules ?? []).map(toRule),
535 meshes: route.meshes ?? [],
536 gateways: route.gateways ?? [],
537 description: route.description,
538 labels: userLabels(route.labels),
539 createTime: route.createTime,
540 updateTime: route.updateTime,
541 };
542 };
543
544 const getByName = (name: string) =>
545 networkservices
546 .getProjectsLocationsHttpRoutes({ name })
547 .pipe(Effect.catchTag("NotFound", () => Effect.undefined));
548
549 export const HttpRouteProvider = () =>
550 Provider.succeed(HttpRoute, {
551 stables: ["name", "httpRouteId", "project", "location", "selfLink", "createTime"],
552
553 diff: Effect.fn(function* ({ news, olds, output }) {
554 if (!isResolved(news)) return undefined;
555 const previousId = olds?.httpRouteId ?? output?.httpRouteId;
556 const nextId = news.httpRouteId ? rfc1035(news.httpRouteId, "http-route") : previousId;
557 const previousLocation = normalizeLocation(
558 olds?.location ?? output?.location,
559 DEFAULT_GLOBAL,
560 );
561 const nextLocation = normalizeLocation(
562 news.location ?? olds?.location ?? output?.location,
563 DEFAULT_GLOBAL,
564 );
565 if (
566 (previousId !== undefined && nextId !== undefined && nextId !== previousId) ||
567 previousLocation !== nextLocation
568 ) {
569 return { action: "replace" as const };
570 }
571 return undefined;
572 }),
573
574 read: Effect.fn(function* ({ id, olds, output }) {
575 const env = yield* GcpEnvironment.current;
576 const httpRouteId = yield* toPhysicalId(
577 id,
578 olds?.httpRouteId,
579 output?.httpRouteId,
580 "http-route",
581 );
582 const location = normalizeLocation(olds?.location ?? output?.location, DEFAULT_GLOBAL);
583 const name = output?.name ?? resourceName(env.project, location, COLLECTION, httpRouteId);
584 const existing = yield* getByName(name);
585 if (existing === undefined) return undefined;
586 const attrs = toAttrs(existing, env.project);
587 return (yield* hasAlchemyLabels(id, tagRecord(existing.labels))) ? attrs : Unowned(attrs);
588 }),
589
590 list: () =>
591 Effect.gen(function* () {
592 const env = yield* GcpEnvironment.current;
593 const items = yield* collectPages(
594 networkservices.listProjectsLocationsHttpRoutes.pages({
595 parent: parentOf(env.project, "-"),
596 pageSize: 1000,
597 returnPartialSuccess: true,
598 }),
599 (page) => page.httpRoutes,
600 );
601 return items
602 .filter((item) => hasAlchemyLabelKeys(item.labels))
603 .map((item) => toAttrs(item, env.project));
604 }),
605
606 reconcile: Effect.fn(function* ({ id, news, output }) {
607 const env = yield* GcpEnvironment.current;
608 const httpRouteId = yield* toPhysicalId(
609 id,
610 news.httpRouteId,
611 output?.httpRouteId,
612 "http-route",
613 );
614 const location = normalizeLocation(news.location ?? output?.location, DEFAULT_GLOBAL);
615 const name = resourceName(env.project, location, COLLECTION, httpRouteId);
616 const desiredLabels = {
617 ...toLabels(news.labels),
618 ...(yield* createInternalLabels(id)),
619 };
620 const desiredRules = news.rules.map(toRule);
621 const desiredHostnames = news.hostnames;
622 const desiredMeshes = news.meshes ?? [];
623 const desiredGateways = news.gateways ?? [];
624
625 let current = yield* getByName(name);
626
627 if (current === undefined) {
628 const created = yield* networkservices
629 .createProjectsLocationsHttpRoutes({
630 parent: parentOf(env.project, location),
631 httpRouteId,
632 body: {
633 labels: desiredLabels,
634 description: news.description,
635 hostnames: desiredHostnames,
636 rules: desiredRules,
637 meshes: desiredMeshes,
638 gateways: desiredGateways,
639 },
640 })
641 .pipe(
642 Effect.retry({
643 while: (error) => error._tag === "Conflict",
644 times: 5,
645 schedule: Schedule.spaced("2 seconds"),
646 }),
647 Effect.catchTag("Conflict", () => Effect.undefined),
648 );
649 if (created !== undefined) {
650 yield* waitForOperation(created);
651 }
652 current = yield* waitUntilPresent(getByName(name), name);
653 }
654
655 const observedLabels = tagRecord(current.labels);
656 const { upsert, removed } = diffLabels(observedLabels, desiredLabels);
657 const labelsChanged = upsert.length > 0 || removed.length > 0;
658 const descriptionChanged = (current.description ?? "") !== (news.description ?? "");
659 const hostnamesChanged = !sameStringList(current.hostnames, desiredHostnames);
660 const rulesChanged = !sameJson((current.rules ?? []).map(toRule), desiredRules);
661 const meshesChanged = !sameStringList(current.meshes, desiredMeshes);
662 const gatewaysChanged = !sameStringList(current.gateways, desiredGateways);
663
664 const updateMask = changedFields([
665 ["labels", labelsChanged],
666 ["description", descriptionChanged],
667 ["hostnames", hostnamesChanged],
668 ["rules", rulesChanged],
669 ["meshes", meshesChanged],
670 ["gateways", gatewaysChanged],
671 ]);
672
673 if (updateMask.length > 0) {
674 const operation = yield* networkservices.patchProjectsLocationsHttpRoutes({
675 name: current.name ?? name,
676 updateMask: updateMask.join(","),
677 body: {
678 name: current.name ?? name,
679 labels: desiredLabels,
680 description: news.description,
681 hostnames: desiredHostnames,
682 rules: desiredRules,
683 meshes: desiredMeshes,
684 gateways: desiredGateways,
685 },
686 });
687 yield* waitForOperation(operation);
688 current = yield* waitUntilPresent(getByName(current.name ?? name), current.name ?? name);
689 }
690
691 return toAttrs(current, env.project);
692 }),
693
694 delete: Effect.fn(function* ({ output }) {
695 const operation = yield* networkservices
696 .deleteProjectsLocationsHttpRoutes({ name: output.name })
697 .pipe(
698 Effect.retry({
699 while: (error) => error._tag === "Conflict",
700 times: 8,
701 schedule: Schedule.spaced("2 seconds"),
702 }),
703 Effect.catchTag("NotFound", () => Effect.undefined),
704 );
705 if (operation !== undefined) {
706 yield* waitForOperation(operation, { notFoundOk: true });
707 }
708 yield* waitUntilGone(getByName(output.name), output.name);
709 }),
710 });