export { DEFAULT_BROADCAST_BUCKETS, KNOWN_BROADCAST_BUCKETS, TELEFUNC_BROADCAST_BUCKET_HEADER, TELEFUNC_SESSION_HEADER, TELEFUNC_SHARD_HEADER, assertLocationFallbackIsScaled, getBucketCoordinatorShardIndices, getDeterministicKeyBucketIndex, getShardIndicesForBucket, resolveCloudflareLocationHint, resolveSessionRoutingTarget, }; export type { CloudflareScale, LocationBucket, SessionRoutingTarget }; import { TELEFUNC_SESSION_HEADER } from '../../../constants.js'; /** * Cloudflare routing primitives for Telefunc's session and broadcast Durable Objects. * * Routing now always resolves to one of Telefunc's canonical Cloudflare location hints. * If Cloudflare doesn't provide a precise mapping, Telefunc uses `locationFallback`. */ declare const DEFAULT_BROADCAST_BUCKETS: readonly ["wnam", "enam", "weur", "eeur", "apac", "oc"]; declare const TELEFUNC_BROADCAST_BUCKET_HEADER = "x-telefunc-broadcast-bucket"; /** Internal: forwarded to the DO so it knows its own instance name. */ declare const TELEFUNC_SHARD_HEADER = "x-telefunc-shard"; declare const KNOWN_BROADCAST_BUCKETS: Set; type LocationBucket = DurableObjectLocationHint; type CloudflareScale = number | Partial>; type SessionRoutingTarget = { sessionInstanceName: string; locationBucket: LocationBucket; shardOrdinal: number; }; /** * Maps one location bucket to its local coordinator-shard ordinals. * Buckets no longer share one global shard index space; each bucket owns ordinals `0..n-1` independently. */ declare function getBucketCoordinatorShardIndices(scale: CloudflareScale | undefined, locationBucket: LocationBucket): number[]; /** * Maps one location bucket to its local session-shard ordinals. * Buckets no longer share one global shard index space; each bucket owns ordinals `0..n-1` independently. */ declare function getShardIndicesForBucket(scale: CloudflareScale | undefined, locationBucket: LocationBucket): number[]; /** * Derives a session shard target from the request's Cloudflare location metadata and the current scale. */ declare function resolveSessionRoutingTarget(baseInstanceName: string, scale: CloudflareScale | undefined, request: Request, locationFallback: DurableObjectLocationHint): SessionRoutingTarget; /** * Deterministically maps one channel key into one bucket index. * Shared by both coordinator-bucket selection and in-bucket shard selection so all keyed broadcast routing uses the same hash. */ declare function getDeterministicKeyBucketIndex(key: string, bucketCount: number): number; /** Resolves the canonical Cloudflare location hint for one request, or the explicit user fallback when no precise hint exists. */ declare function resolveCloudflareLocationHint(request: Request, locationFallback: DurableObjectLocationHint): DurableObjectLocationHint; /** * A per-region `scale` map may omit regions; requests from those regions route to `locationFallback`. * That only works when `locationFallback` itself is scaled — otherwise the fallback lands on a bucket * with no shards and routing throws at request time. Enforce it once, at config time. */ declare function assertLocationFallbackIsScaled(scale: CloudflareScale | undefined, locationFallback: DurableObjectLocationHint): void;