/// import type { Pipeline } from "cloudflare:pipelines"; import type { Secret } from "../secret.ts"; import type { Ai as _Ai } from "./ai.ts"; import type { AiSearchNamespace as _AiSearchNamespace } from "./ai-search-namespace.ts"; import type { AiSearch as _AiSearch } from "./ai-search.ts"; import type { AnalyticsEngineDataset as _AnalyticsEngineDataset } from "./analytics-engine.ts"; import type { Assets } from "./assets.ts"; import type { Binding, Json, Self } from "./bindings.ts"; import type { BrowserRendering } from "./browser-rendering.ts"; import type { R2Bucket as _R2Bucket } from "./bucket.ts"; import type { Container as _Container } from "./container.ts"; import type { D1Database as _D1Database } from "./d1-database.ts"; import type { DurableObjectNamespace as _DurableObjectNamespace } from "./durable-object-namespace.ts"; import type { EmailSender as _EmailSender } from "./email-sender.ts"; import type { HyperdriveRef } from "./hyperdrive-ref.ts"; import type { Hyperdrive as _Hyperdrive } from "./hyperdrive.ts"; import type { Images as _Images } from "./images.ts"; import type { Pipeline as _Pipeline } from "./pipeline.ts"; import type { Queue as _Queue } from "./queue.ts"; import type { RateLimit as _RateLimit } from "./rate-limit.ts"; import type { SecretKey } from "./secret-key.ts"; import type { SecretRef as CloudflareSecretRef } from "./secret-ref.ts"; import type { Secret as CloudflareSecret } from "./secret.ts"; import type { VectorizeIndex as _VectorizeIndex } from "./vectorize-index.ts"; import type { VersionMetadata as _VersionMetadata } from "./version-metadata.ts"; import type { VpcService as _VpcService } from "./vpc-service.ts"; import type { WorkerLoader as _WorkerLoader } from "./worker-loader.ts"; import type { WorkerRef } from "./worker-ref.ts"; import type { WorkerStub } from "./worker-stub.ts"; import type { Worker as _Worker } from "./worker.ts"; import type { Workflow as _Workflow } from "./workflow.ts"; type BoundWorker< RPC extends Rpc.WorkerEntrypointBranded = Rpc.WorkerEntrypointBranded, > = Service & { // cloudflare's Rpc.Provider type loses mapping between properties (jump to definition) // we fix that using Pick to re-connect mappings [property in keyof Pick< RPC, Extract, keyof RPC> >]: Rpc.Provider[property]; }; // NOTE: AiSearch / AiSearchNamespace MUST come FIRST in this conditional // chain, before any structural discriminator like `{ type: "kv_namespace" }`. // `AiSearch.type` is the data-source type (`"r2" | "web-crawler"`), NOT a // binding-type discriminator — so we match by *resource-type import* via the // `_AiSearch` / `_AiSearchNamespace` aliases (underscore-prefixed to avoid // colliding with the identically-named Cloudflare runtime classes on the // right-hand side of the conditional). export type Bound = T extends _AiSearch ? AiSearchInstance : T extends _AiSearchNamespace ? AiSearchNamespace : T extends _DurableObjectNamespace ? DurableObjectNamespace : T extends { type: "kv_namespace" } ? KVNamespace : T extends WorkerStub ? BoundWorker : T extends _Worker | WorkerRef ? BoundWorker : T extends { type: "service" } ? Service : T extends _R2Bucket ? R2Bucket : T extends _Hyperdrive | HyperdriveRef ? Hyperdrive : T extends Secret ? string : T extends CloudflareSecret | CloudflareSecretRef ? SecretsStoreSecret : T extends _EmailSender ? SendEmail : T extends SecretKey ? CryptoKey : T extends Assets ? Service : T extends _Workflow ? Workflow

: T extends _D1Database ? D1Database : T extends DispatchNamespace ? DispatchNamespace : T extends _WorkerLoader ? WorkerLoader : T extends _VectorizeIndex ? VectorizeIndex : T extends _Queue ? Queue : T extends _AnalyticsEngineDataset ? AnalyticsEngineDataset : T extends _Pipeline ? Pipeline : T extends _RateLimit ? RateLimit : T extends string ? T : T extends BrowserRendering ? Fetcher : T extends _Ai ? Ai : T extends _Images ? ImagesBinding : T extends _VersionMetadata ? WorkerVersionMetadata : T extends | _Worker.DevDomain | _Worker.DevUrl ? string : T extends Self ? Service : T extends Json< infer T > ? T : T extends _Container< infer Obj > ? DurableObjectNamespace< Obj & Rpc.DurableObjectBranded > : T extends _VpcService ? Fetcher : T extends undefined ? undefined : Service;