| 1 | import type * as Binding from "./Binding.ts"; |
| 2 | import { makeBindingLayer } from "./BindingLayer.ts"; |
| 3 | import { |
| 4 | SecretKey, |
| 5 | type SecretKeyAccessor, |
| 6 | type SecretKeyPayload, |
| 7 | } from "./SecretKey.ts"; |
| 8 | |
| 9 | /** The binding value produced by calling {@link SecretKey} (declared on `env` or `yield*`-ed). */ |
| 10 | export type SecretKeyBinding = Binding.Binding< |
| 11 | SecretKey["key"], |
| 12 | SecretKeyAccessor, |
| 13 | SecretKey |
| 14 | > & |
| 15 | Readonly<SecretKeyPayload>; |
| 16 | |
| 17 | /** |
| 18 | * The layer that provides the Effect-native interface for the Cloudflare |
| 19 | * Workers Secret Key binding. |
| 20 | * |
| 21 | * Provide it on the Worker effect (`Effect.provide(Cloudflare.Workers.SecretKeyBinding)`) |
| 22 | * so that yielding a {@link SecretKey} binding attaches the native |
| 23 | * `secret_key` binding to the surrounding Worker at deploy time and, at |
| 24 | * runtime, resolves to a deferred {@link SecretKeyAccessor} (yield it to |
| 25 | * obtain the native `CryptoKey`). |
| 26 | */ |
| 27 | export const SecretKeyBinding = makeBindingLayer< |
| 28 | SecretKey, |
| 29 | // The ambient global type, matching SecretKeyAccessor and InferEnv's |
| 30 | // SecretKeyBinding mapping. |
| 31 | CryptoKey, |
| 32 | SecretKeyAccessor |
| 33 | >(SecretKey, (raw) => raw); |