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

main
ts 49 lines 2.04 KB
Raw
1 import * as Output from "alchemy/Output";
2
3 /** The Function attributes the helpers below read. */
4 export interface QualifiedFunctionRef {
5 readonly functionArn: Output.Output<string>;
6 readonly functionName: Output.Output<string>;
7 readonly qualifiedArn: Output.Output<string>;
8 }
9
10 /** The alias ARN, when the Function routes through one. */
11 const aliasArnOf = (qualifiedArn: string | undefined, functionArn: string) =>
12 // State written before `qualifiedArn` existed has no value for it.
13 qualifiedArn !== undefined && qualifiedArn !== functionArn ? qualifiedArn : undefined;
14
15 /**
16 * The ARN consumers should invoke `fn` through: its alias ARN when the
17 * Function sets `alias`, otherwise the unqualified function ARN. Integration
18 * URIs, notification targets and rule targets wire this instead of
19 * `functionArn` so they follow the alias.
20 */
21 export const qualifiedArnOf = (fn: QualifiedFunctionRef): Output.Output<string> =>
22 Output.map(
23 Output.all(fn.qualifiedArn, fn.functionArn),
24 ([qualifiedArn, functionArn]: [string | undefined, string]) =>
25 aliasArnOf(qualifiedArn, functionArn) ?? functionArn,
26 );
27
28 /**
29 * The `FunctionName` consumers should pass to Lambda APIs (event-source
30 * mappings, `AddPermission`): the alias ARN when the Function sets `alias`,
31 * otherwise the plain function name.
32 */
33 export const qualifiedNameOf = (fn: QualifiedFunctionRef): Output.Output<string> =>
34 Output.map(
35 Output.all(fn.qualifiedArn, fn.functionArn, fn.functionName),
36 ([qualifiedArn, functionArn, functionName]: [string | undefined, string, string]) =>
37 aliasArnOf(qualifiedArn, functionArn) ?? functionName,
38 );
39
40 /**
41 * The `Qualifier` to start `fn`'s durable executions on: the alias name when
42 * the Function sets `alias`, otherwise `$LATEST`.
43 */
44 export const qualifierOf = (fn: QualifiedFunctionRef): Output.Output<string> =>
45 Output.map(
46 Output.all(fn.qualifiedArn, fn.functionArn),
47 ([qualifiedArn, functionArn]: [string | undefined, string]) =>
48 aliasArnOf(qualifiedArn, functionArn)?.slice(functionArn.length + 1) ?? "$LATEST",
49 );