import * as Context from "effect/Context"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import * as Redacted from "effect/Redacted"; import type { HttpEffect } from "./Http.ts"; import type { Output } from "./Output.ts"; export interface BaseRuntimeContext { Type: string; id: string; env: Record; /** * Read a value by its (already-canonical) key. The key is used verbatim; * callers must {@link sanitizeKey} first. See {@link sanitizeKey}. */ get(key: string): Effect.Effect; /** * Store an output under the given (already-canonical) key, returning the key. * The key is used verbatim; callers must {@link sanitizeKey} first. */ set(id: string, output: Output): Effect.Effect; exports?: Effect.Effect>; serve?(handler: HttpEffect, options?: { shape?: Record; }): Effect.Effect; shape?: () => Record; /** additional services to provide to the plan */ planServices?: Layer.Layer; /** * Telemetry exporter Layer registered during init via * `Telemetry.layer(...)` / `Telemetry.layerOtlp(...)` (see Telemetry.ts). * The runtime bridges build it into every event's request scope, * overriding the env-driven default. */ telemetry?: Layer.Layer; } /** * Canonicalize a logical key into a key that is safe to use as the name of an * environment variable / binding (`[a-zA-Z][a-zA-Z0-9_]*`). * * `RuntimeContext.set`/`get` are dumb key/value stores: they read and write the * key **verbatim**. It is the *caller's* responsibility to hand them a * canonical key, since the caller is the one that knows the logical key may * contain `.`/`-` (e.g. a dotted config name from `Platform`, or an * `Output.toString()` like `"QueueSinkQueue.queueUrl"`). Callers run the key * through this before calling `set`/`get` so both sides agree. */ export declare const sanitizeKey: (key: string) => string; /** * The wire format `RuntimeContext.set`/`get` use to carry a `Redacted` value * through an environment variable. `JSON.stringify(Redacted)` emits the * literal string `""` and loses the value, so secrets are * serialized as this marker and the runtime `get` path rebuilds the wrapper. */ export interface RedactedMarker { readonly _tag: "Redacted"; readonly value: unknown; } /** * Detect the (already JSON-parsed) {@link RedactedMarker} shape. After * `JSON.parse` the marker is a plain object — `Redacted.isRedacted` is * always `false` on it — so detection is structural. */ export declare const isRedactedMarker: (value: unknown) => value is RedactedMarker; /** * Serialize a binding value for an env var: `Redacted` values are packed as * a {@link RedactedMarker}, non-string values as JSON. * * A plain string is stored **verbatim** whenever `JSON.parse` would reject * it — which is almost every real-world string (names, URLs, ids). Packing * those too would put `"my-queue"` (quote characters included) on the wire, * where anything that consumes the raw binding without going through * {@link unpackEnvValue} — the Cloudflare dashboard, a hand-written env * read, a queue-name comparison against `MessageBatch.queue` — sees the * quoted form and mismatches (#1243). Only ambiguous strings (`"123"`, * `"null"`, JSON documents) keep the pack so the read side can't * reinterpret them. */ export declare const packEnvValue: (value: unknown) => string; /** * Like {@link packEnvValue}, but a `Redacted` input keeps its `Redacted` * wrapper on the *outside* of the packed string, so deploy-time code can * route secrets through a dedicated channel (Cloudflare `secret_text`, * Secrets Store) instead of leaking them as plain env vars. The inner * payload still carries the marker for the runtime `get` accessor. */ export declare const packEnvValueKeepRedacted: (value: unknown) => string | Redacted.Redacted; /** * Parse an env-var string produced by {@link packEnvValue} back into its * value: rebuild `Redacted` from the marker, return other JSON values * as-is, and fall back to the raw string for non-JSON input (a verbatim * string from `packEnvValue`, or an env var the user set directly). * `undefined` passes through. * * Runtime `get` accessors MUST feed this from the raw environment * (`process.env[key]` / the platform env object) — never through * `Config.string`: the ambient runtime `ConfigProvider` reifies bound * values (unwrapping the marker before it could be detected here), and * during init the ambient provider is the interceptor installed in * `Platform.ts`, whose runtime branch calls back into `ctx.get(key)` — * resolving through `Config` would re-enter it for the same key and * recurse forever. */ export declare const unpackEnvValue: (raw: string | undefined) => T | undefined; declare const RuntimeContext_base: Context.ServiceClass; /** * Context of the runtime environment. * * E.g. the context of a running Worker, Task, Process, Function */ export declare class RuntimeContext extends RuntimeContext_base { static phantom: Layer.Layer; } export declare const CurrentRuntimeContext: Effect.Effect; export {}; //# sourceMappingURL=RuntimeContext.d.ts.map