1/**
2 * The pack hasher as an AWS Lambda (DESIGN §22.11): an Effect-native
3 * Function that answers {@link HashEvent}s — the same scan the Worker runs
4 * inline, on a core several times faster and, above all, on as many cores
5 * as there are chunks in flight. Declare it in the same stack as the Git
6 * Worker (the stack needs both provider sets) and hand it to
7 * {@link HasherLambda}.
8 *
9 * **Example:** A Git host that hashes pushes on Lambda
10 * ```typescript
11 * import * as Git from "alchemy/Git";
12 * import * as GitHasher from "alchemy/Git/Hasher";
13 *
14 * const GitLive = Git.ApiLive.pipe(
15 * Layer.provide(Git.ApiHandlersLive),
16 * Layer.provide(Authentication.layer),
17 * Layer.provide(Git.ReposDurableObject),
18 * Layer.provide(Git.RegistryDurableObject),
19 * Layer.provide(GitHasher.HasherLambda(GitHasher.HasherFunction)),
20 * Layer.provide(AWS.Lambda.InvokeFunctionHttp),
21 * Layer.provide(Git.BlobStoreR2(GitObjects)),
22 * );
23 * ```
24 */
25import * as Duration from "effect/Duration";
26import * as Effect from "effect/Effect";
27import * as Lambda from "../../AWS/Lambda/Function.ts";
28import { handleHashEvent, isHashEvent } from "./LambdaEvent.ts";
29
30export default class HasherFunction extends Lambda.Function<HasherFunction>()(
31 "GitHasher",
32 {
33 main: import.meta.url,
34 // CPU scales with memory on Lambda; 3 GB is the fastest single-thread
35 // tier and a chunk needs well under that.
36 memorySize: 3008,
37 timeout: Duration.seconds(60),
38 },
39 Effect.gen(function* () {
40 const fn = yield* Lambda.Function;
41 yield* fn.listen((event: unknown) =>
42 isHashEvent(event) ? handleHashEvent(event) : undefined,
43 );
44 return {};
45 }),
46) {}